Logo Search packages:      
Sourcecode: lfm version File versions  Download package

def lfm::actions::Tree::run (   self  ) 

manage keys

Definition at line 1851 of file actions.py.

01851                  :
        """manage keys"""
        
        while 1:
            self.show()
            chext = 0
            ch = self.win_tree.getch()

            # to avoid extra chars input
            if ch == 0x1B:
                chext = 1
                ch = self.win_tree.getch()
                ch = self.win_tree.getch()

            # cursor up
            if ch in [ord('p'), ord('P'), curses.KEY_UP]:
                if self.pos == 0:
                    continue
                if self.tree[self.pos][1] != self.tree[self.pos-1][1]:
                    continue
                newpos = self.pos - 1
            # cursor down
            elif ch in [ord('n'), ord('N'), curses.KEY_DOWN]:
                if self.pos == len(self.tree) - 1:
                    continue
                if self.tree[self.pos][1] != self.tree[self.pos+1][1]:
                    continue
                newpos = self.pos + 1
            # page previous
            elif ch in [curses.KEY_PPAGE, curses.KEY_BACKSPACE,
                        0x08, 0x10]:                         # BackSpace, Ctrl-P
                depth = self.tree[self.pos][1] 
                if self.pos - (curses.LINES-4) >= 0:
                    if depth  == self.tree[self.pos - (curses.LINES-4)][1]:
                        newpos = self.pos - (curses.LINES-4)
                    else:
                        newpos = self.pos
                        while 1:
                            if newpos - 1 < 0:
                                break
                            if self.tree[newpos-1][1] != depth:
                                break
                            newpos -= 1
                else:
                    newpos = self.pos
                    while 1:
                        if newpos - 1 < 0:
                            break
                        if self.tree[newpos-1][1] != depth:
                            break
                        newpos -= 1
            # page next
            elif ch in [curses.KEY_NPAGE, ord(' '), 0x0E]:   # Ctrl-N
                depth = self.tree[self.pos][1] 
                if self.pos + (curses.LINES-4) <= len(self.tree) - 1:
                    if depth  == self.tree[self.pos + (curses.LINES-4)][1]:
                        newpos = self.pos + (curses.LINES-4)
                    else:
                        newpos = self.pos
                        while 1:
                            if newpos + 1 == len(self.tree):
                                break
                            if self.tree[newpos+1][1] != depth:
                                break
                            newpos += 1
                else:
                    newpos = self.pos
                    while 1:
                        if newpos + 1 == len(self.tree):
                            break
                        if self.tree[newpos+1][1] != depth:
                            break
                        newpos += 1
            # home
            elif (ch in [curses.KEY_HOME, 0x001,0x16A ]) or \
                 (chext == 1) and (ch == 72):  # home
                newpos = 1
            # end
            elif (ch in [curses.KEY_END, 0x005, 0x181]) or \
                 (chext == 1) and (ch == 70):   # end
                newpos = len(self.tree) - 1
            # cursor left
            elif ch in [curses.KEY_LEFT]:
                if self.pos == 0:
                    continue
                newdepth = self.tree[self.pos][1] - 1
                for i in range(self.pos-1, -1, -1):
                    if self.tree[i][1] == newdepth:
                        break
                newpos = i
            # cursor right
            elif ch in [curses.KEY_RIGHT]:
                child_dirs = self.__get_dirs(self.path)
                if len(child_dirs) > 0:
                    self.path = os.path.join(self.path, child_dirs[0])
                    self.tree = self.get_tree()
                    self.pos = self.__get_curpos()
                continue                   
            # enter
            elif ch in [10, 13]:
                return self.path
            # quit
            elif ch in [ord('q'), ord('Q'), curses.KEY_F10, 0x03]:  # Ctrl-C
                return -1

            # else
            else:
                continue
            
            # update
            self.regenerate_tree(newpos)
            self.regenerate_tree(newpos)


Generated by  Doxygen 1.6.0   Back to index