From ac95dddfbefe9e3fd686f54507cb3177d021cf0e Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 19 Jan 2010 13:06:09 +0000 Subject: [PATCH] start working on a set of methods to walk the widget tree to find the visible ones, and collect their gtk allocation (i.e. where they are and how big they are). This is expected to form the basis of directional navigation and layout display/saving --- terminatorlib/container.py | 16 ++++++++++++++++ terminatorlib/terminator.py | 6 +++++- terminatorlib/window.py | 24 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/terminatorlib/container.py b/terminatorlib/container.py index a0914bfd..175da7c3 100755 --- a/terminatorlib/container.py +++ b/terminatorlib/container.py @@ -173,4 +173,20 @@ the %s will also close all terminals within it.') % (reqtype, reqtype)) if maker.isinstance(parent, 'Container'): parent.propagate_title_change(widget, title) + def get_visible_terminals(self): + """Walk the widget tree to find all of the visible terminals. That is, + any terminals which are not hidden in another Notebook pane""" + maker = Factory() + terminals = {} + + for child in self.get_offspring(): + if maker.isinstance(child, 'Terminal'): + terminals[child] = child.get_allocation() + elif maker.isinstance(child, 'Container'): + terminals.update(child.get_visible_terminals()) + else: + err('Unknown child type %s' % type(child)) + + return(terminals) + # vim: set expandtab ts=4 sw=4: diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index 6c2955d6..9a2614ef 100755 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -123,8 +123,12 @@ class Terminator(Borg): if next < 0: next = length - 1 else: + window = get_top_window(terminal) + layout = window.get_visible_terminals() + # FIXME: Do the directional navigation, don't just print the layout + import pprint + pprint.pprint(layout) raise NotImplementedError - # FIXME: Do the directional navigation if next is not None: self.terminals[next].grab_focus() diff --git a/terminatorlib/window.py b/terminatorlib/window.py index e99a6801..413f0840 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -318,6 +318,30 @@ class Window(Container, gtk.Window): self.zoom_data = None self.set_property('term_zoomed', False) + def get_visible_terminals(self): + """Walk down the widget tree to find all of the visible terminals. + Mostly using Container::get_visible_terminals()""" + maker = Factory() + child = self.get_child() + terminals = {} + + # If our child is a Notebook, reset to work from its visible child + if maker.isinstance(child, 'Notebook'): + pagenum = child.get_current_page() + child = child.get_nth_page(pagenum) + + if maker.isinstance(child, 'Container'): + terminals.update(child.get_visible_terminals()) + elif maker.isnstance(child, 'Terminal'): + # This branch is only possible if we started out as a Notebook. We + # wouldn't have been called if there was really only one Terminal + # child. + terminals[child] = child.get_allocation() + else: + err('Unknown child type %s' % type(child)) + + return(terminals) + class WindowTitle(object): """Class to handle the setting of the window title"""