Refactor get_first_parent_paned into a generic, non-recursive function for finding the first parent widget of a given type
This commit is contained in:
parent
14f6525195
commit
18d4df6af8
|
@ -1250,15 +1250,16 @@ class Terminator:
|
||||||
page = self.get_first_notebook_page(page[0])
|
page = self.get_first_notebook_page(page[0])
|
||||||
|
|
||||||
def resizeterm (self, widget, keyname):
|
def resizeterm (self, widget, keyname):
|
||||||
vertical = False
|
|
||||||
if keyname in ('Up', 'Down'):
|
if keyname in ('Up', 'Down'):
|
||||||
vertical = True
|
type = gtk.VPaned
|
||||||
elif keyname in ('Left', 'Right'):
|
elif keyname in ('Left', 'Right'):
|
||||||
vertical = False
|
type = gtk.HPaned
|
||||||
else:
|
else:
|
||||||
|
err ("Invalid keytype: %s" % type)
|
||||||
return
|
return
|
||||||
parent = self.get_first_parent_paned(widget,vertical)
|
|
||||||
if parent == None:
|
parent = self.get_first_parent_widget(widget, type)
|
||||||
|
if parent is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
#We have a corresponding parent pane
|
#We have a corresponding parent pane
|
||||||
|
@ -1338,21 +1339,15 @@ class Terminator:
|
||||||
return parent
|
return parent
|
||||||
return self.get_first_parent_notebook(parent)
|
return self.get_first_parent_notebook(parent)
|
||||||
|
|
||||||
def get_first_parent_paned (self, widget, vertical = None):
|
def get_first_parent_widget (self, widget, type):
|
||||||
"""This method returns the first parent pane of a widget.
|
"""This method searches up through the gtk widget heirarchy
|
||||||
if vertical is True returns the first VPaned
|
of 'widget' until it finds a parent widget of type 'type'"""
|
||||||
if vertical is False return the first Hpaned
|
while not isinstance(widget.get_parent(), type):
|
||||||
if is None return the First Paned"""
|
widget = widget.get_parent()
|
||||||
if isinstance (widget, gtk.Window):
|
if widget is None:
|
||||||
return None
|
return widget
|
||||||
parent = widget.get_parent()
|
|
||||||
if isinstance (parent, gtk.Paned) and vertical is None:
|
return widget.get_parent()
|
||||||
return parent
|
|
||||||
if isinstance (parent, gtk.VPaned) and vertical:
|
|
||||||
return parent
|
|
||||||
elif isinstance (parent, gtk.HPaned) and not vertical:
|
|
||||||
return parent
|
|
||||||
return self.get_first_parent_paned(parent, vertical)
|
|
||||||
|
|
||||||
def get_first_notebook_page(self, widget):
|
def get_first_notebook_page(self, widget):
|
||||||
if isinstance (widget, gtk.Window) or widget is None:
|
if isinstance (widget, gtk.Window) or widget is None:
|
||||||
|
|
Loading…
Reference in New Issue