diff --git a/terminatorlib/container.py b/terminatorlib/container.py index f9367b38..ce9cf1ce 100755 --- a/terminatorlib/container.py +++ b/terminatorlib/container.py @@ -60,7 +60,7 @@ class Container(object): self.cnxids.remove_widget(widget) def get_offspring(self): - """Return a list of child widgets, if any""" + """Return a list of direct child widgets, if any""" return(self.children) def split_horiz(self, widget): diff --git a/terminatorlib/notebook.py b/terminatorlib/notebook.py index 439dbbf1..f1999ecd 100755 --- a/terminatorlib/notebook.py +++ b/terminatorlib/notebook.py @@ -12,7 +12,7 @@ from factory import Factory from container import Container from editablelabel import EditableLabel from translation import _ -from util import err, dbg, get_top_window +from util import err, dbg, get_top_window, enumerate_descendants class Notebook(Container, gtk.Notebook): """Class implementing a gtk.Notebook container""" @@ -179,21 +179,9 @@ class Notebook(Container, gtk.Notebook): dialog.destroy() if result == gtk.RESPONSE_ACCEPT: - containers = [] - objects = [] - for descendant in child.get_children(): - if maker.isinstance(descendant, 'Container'): - containers.append(descendant) - elif maker.isinstance(descendant, 'Terminal'): - objects.append(descendant) - - while len(containers) > 0: - child = containers.pop() - for descendant in child.get_children(): - if maker.isinstance(descendant, 'Container'): - containers.append(descendant) - elif maker.isinstance(descendant, 'Terminal'): - objects.append(descendant) + containers = None + objects = None + containers, objects = enumerate_descendants(child) while len(objects) > 0: descendant = objects.pop() diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index 20f8297b..471f5859 100755 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -61,6 +61,7 @@ class Terminator(Borg): self.windows.remove(window) if len(self.windows) == 0: # We have no windows left, we should exit + dbg('no windows remain, quitting') gtk.main_quit() def register_terminal(self, terminal): @@ -79,6 +80,7 @@ class Terminator(Borg): self.terminals.remove(terminal) if len(self.terminals) == 0: + dbg('no terminals remain, destroying all windows') for window in self.windows: window.destroy() else: diff --git a/terminatorlib/util.py b/terminatorlib/util.py index 26c79250..4e781591 100755 --- a/terminatorlib/util.py +++ b/terminatorlib/util.py @@ -229,3 +229,38 @@ def get_nav_tiebreak(direction, cursor_x, cursor_y, rect): else: raise ValueError('Unknown direction: %s' % direction) +def enumerate_descendants(parent): + """Walk all our children and build up a list of containers and + terminals""" + # FIXME: Does having to import this here mean we should move this function + # back to Container? + from factory import Factory + + containerstmp = [] + containers = [] + terminals = [] + maker = Factory() + + if parent is None: + err('no parent widget specified') + return + + for descendant in parent.get_children(): + if maker.isinstance(descendant, 'Container'): + containerstmp.append(descendant) + elif maker.isinstance(descendant, 'Terminal'): + terminals.append(descendant) + + while len(containerstmp) > 0: + child = containerstmp.pop() + for descendant in child.get_children(): + if maker.isinstance(descendant, 'Container'): + containerstmp.append(descendant) + elif maker.isinstance(descendant, 'Terminal'): + terminals.append(descendant) + containers.append(child) + + dbg('%d containers and %d terminals fall beneath %s' % (len(containers), + len(terminals), parent)) + return(containers, terminals) +