(self, terminal, direction)
Navigate around terminals
Navigate around terminals
Navigate around terminals
def navigate_terminal(self, terminal, direction):
        """Navigate around terminals"""
        if self.is_zoomed():
            self.unzoom()
            while Gtk.events_pending():
                Gtk.main_iteration_do(False)

        _containers, terminals = util.enumerate_descendants(self)
        visibles = self.get_visible_terminals()
        current = terminals.index(terminal)
        length = len(terminals)
        next = None

        if length <= 1 or len(visibles) <= 1:
            return

        if direction in ['next', 'prev']:
            tmpterms = copy.copy(terminals)
            tmpterms = tmpterms[current+1:]
            tmpterms.extend(terminals[0:current])

            if direction == 'next':
                tmpterms.reverse()

            next = 0
            while len(tmpterms) > 0:
                tmpitem = tmpterms.pop()
                if tmpitem in visibles:
                    next = terminals.index(tmpitem)
                    break
        elif direction in ['left', 'right', 'up', 'down']:
            layout = self.get_visible_terminals()
            allocation = terminal.get_allocation()
            possibles = []

            # Get the co-ordinate of the appropriate edge for this direction
            edge, p1, p2 = util.get_edge(allocation, direction)
            # Find all visible terminals which are, in their entirity, in the
            # direction we want to move, and are at least partially spanning
            # p1 to p2
            for term in layout:
                rect = layout[term]
                if util.get_nav_possible(edge, rect, direction, p1, p2):
                    possibles.append(term)

            if len(possibles) == 0:
                return

            # Find out how far away each of the possible terminals is, then
            # find the smallest distance. The winning terminals are all of
            # those who are that distance away.
            offsets = {}
            for term in possibles:
                rect = layout[term]
                offsets[term] = util.get_nav_offset(edge, rect, direction)
            keys = list(offsets.values())
            keys.sort()
            winners = [k for k, v in offsets.items() if v == keys[0]]
            next = terminals.index(winners[0])

            if len(winners) > 1:
                # Break an n-way tie using the cursor position
                cursor_x = allocation.x + allocation.width / 2
                cursor_y = allocation.y + allocation.height / 2

                for term in winners:
                    rect = layout[term]
                    if util.get_nav_tiebreak(direction, cursor_x, cursor_y,
                            rect):
                        next = terminals.index(term)
                        break;
        else:
            err('Unknown navigation direction: %s' % direction)

        if next is not None:
            terminals[next].grab_focus()
def navigate_terminal ( self , terminal , direction ) : if self . is_zoomed ( ) : self . unzoom ( ) while Gtk . events_pending ( ) : Gtk . main_iteration_do ( False ) _containers , terminals = util . enumerate_descendants ( self ) visibles = self . get_visible_terminals ( ) current = terminals . index ( terminal ) length = len ( terminals ) next = None if length <= 1 or len ( visibles ) <= 1 : return if direction in [ 'next' , 'prev' ] : tmpterms = copy . copy ( terminals ) tmpterms = tmpterms [ current + 1 : ] tmpterms . extend ( terminals [ 0 : current ] ) if direction == 'next' : tmpterms . reverse ( ) next = 0 while len ( tmpterms ) > 0 : tmpitem = tmpterms . pop ( ) if tmpitem in visibles : next = terminals . index ( tmpitem ) break elif direction in [ 'left' , 'right' , 'up' , 'down' ] : layout = self . get_visible_terminals ( ) allocation = terminal . get_allocation ( ) possibles = [ ] # Get the co-ordinate of the appropriate edge for this direction edge , p1 , p2 = util . get_edge ( allocation , direction ) # Find all visible terminals which are, in their entirity, in the # direction we want to move, and are at least partially spanning # p1 to p2 for term in layout : rect = layout [ term ] if util . get_nav_possible ( edge , rect , direction , p1 , p2 ) : possibles . append ( term ) if len ( possibles ) == 0 : return # Find out how far away each of the possible terminals is, then # find the smallest distance. The winning terminals are all of # those who are that distance away. offsets = { } for term in possibles : rect = layout [ term ] offsets [ term ] = util . get_nav_offset ( edge , rect , direction ) keys = list ( offsets . values ( ) ) keys . sort ( ) winners = [ k for k , v in offsets . items ( ) if v == keys [ 0 ] ] next = terminals . index ( winners [ 0 ] ) if len ( winners ) > 1 : # Break an n-way tie using the cursor position cursor_x = allocation . x + allocation . width / 2 cursor_y = allocation . y + allocation . height / 2 for term in winners : rect = layout [ term ] if util . get_nav_tiebreak ( direction , cursor_x , cursor_y , rect ) : next = terminals . index ( term ) break else : err ( 'Unknown navigation direction: %s' % direction ) if next is not None : terminals [ next ] . grab_focus ( )