Refactor some code from Notebook into a standalone function that finds all descendant widgets of a given container that are Containers or Terminals and returns lists of them, and use this when closing a tab. This function will form the basis of layout enumeration
This commit is contained in:
parent
0817d2651d
commit
789092bb07
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue