From 489bc2cbb66297877c7756864ecea2219c6a3206 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sun, 24 Jan 2010 12:55:03 +0000 Subject: [PATCH] Slight refactoring of each derived Container's add() to handle all the Terminal signals the same way. --- terminatorlib/notebook.py | 15 +++++++-------- terminatorlib/paned.py | 24 +++++++++++++----------- terminatorlib/window.py | 22 ++++++++++++++-------- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/terminatorlib/notebook.py b/terminatorlib/notebook.py index 2745dff9..9dcd4d13 100755 --- a/terminatorlib/notebook.py +++ b/terminatorlib/notebook.py @@ -102,10 +102,10 @@ class Notebook(Container, gtk.Notebook): def newtab(self, widget=None): """Add a new tab, optionally supplying a child widget""" + maker = Factory() top_window = get_top_window(self) if not widget: - maker = Factory() widget = maker.make('Terminal') widget.spawn_child() @@ -113,17 +113,16 @@ class Notebook(Container, gtk.Notebook): 'split-horiz': self.split_horiz, 'split-vert': self.split_vert, 'title-change': self.propagate_title_change, - 'unzoom': self.unzoom} + 'unzoom': self.unzoom, + 'tab-change': top_window.tab_change, + 'group-all': top_window.group_all, + 'ungroup-all': top_window.ungroup_all, + 'group-tab': top_window.group_tab, + 'ungroup-tab': top_window.ungroup_tab} - maker = Factory() if maker.isinstance(widget, 'Terminal'): for signal in signals: self.connect_child(widget, signal, signals[signal]) - self.connect_child(widget, 'tab-change', top_window.tab_change) - self.connect_child(widget, 'group-all', top_window.group_all) - self.connect_child(widget, 'ungroup-all', top_window.ungroup_all) - self.connect_child(widget, 'group-tab', top_window.group_tab) - self.connect_child(widget, 'ungroup-tab', top_window.ungroup_tab) self.set_tab_reorderable(widget, True) label = TabLabel(self.window.get_title(), self) diff --git a/terminatorlib/paned.py b/terminatorlib/paned.py index 42670ad5..1275c3f5 100755 --- a/terminatorlib/paned.py +++ b/terminatorlib/paned.py @@ -84,19 +84,21 @@ class Paned(Container): 'split-vert': self.split_vert, 'title-change': self.propagate_title_change, 'resize-term': self.resizeterm, - 'zoom': top_window.zoom} + 'zoom': top_window.zoom, + 'tab-change': top_window.tab_change, + 'group-all': top_window.group_all, + 'ungroup-all': top_window.ungroup_all, + 'group-tab': top_window.group_tab, + 'ungroup-tab': top_window.ungroup_tab, + 'maximise': [top_window.zoom, False]} for signal in signals: - self.connect_child(widget, signal, signals[signal]) - - # FIXME: We shouldn't be doing this exact same thing in each - # Container - self.connect_child(widget, 'maximise', top_window.zoom, False) - self.connect_child(widget, 'tab-change', top_window.tab_change) - self.connect_child(widget, 'group-all', top_window.group_all) - self.connect_child(widget, 'ungroup-all', top_window.ungroup_all) - self.connect_child(widget, 'group-tab', top_window.group_tab) - self.connect_child(widget, 'ungroup-tab', top_window.ungroup_tab) + args = [] + handler = signals[signal] + if isinstance(handler, list): + args = handler[1:] + handler = handler[0] + self.connect_child(widget, signal, handler, *args) widget.grab_focus() diff --git a/terminatorlib/window.py b/terminatorlib/window.py index 68db91ea..4a01df9d 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -152,10 +152,15 @@ class Window(Container, gtk.Window): return(False) return(True) + def is_child_notebook(self): + """Returns True if this Window's child is a Notebook""" + maker = Factory() + return(maker.isinstance(self.get_child(), 'Notebook')) + def tab_new(self): """Make a new tab""" maker = Factory() - if not maker.isinstance(self.get_child(), 'Notebook'): + if not self.is_child_notebook(): notebook = maker.make('Notebook', window=self) self.get_child().newtab() @@ -217,10 +222,12 @@ class Window(Container, gtk.Window): def set_hidden(self, value): """Set the visibility of the window from the supplied value""" + # FIXME: Implement or drop this pass def set_iconified(self, value): """Set the minimised state of the window from the value""" + # FIXME: Implement or drop this pass def set_real_transparency(self, value=True): @@ -245,17 +252,16 @@ class Window(Container, gtk.Window): 'title-change': self.title.set_title, 'split-horiz': self.split_horiz, 'split-vert': self.split_vert, - 'unzoom': self.unzoom} + 'unzoom': self.unzoom, + 'tab-change': self.tab_change, + 'group-all': self.group_all, + 'ungroup-all': self.ungroup_all, + 'group-tab': self.group_tab, + 'ungroup-tab': self.ungroup_tab} for signal in signals: self.connect_child(widget, signal, signals[signal]) - self.connect_child(widget, 'tab-change', self.tab_change) - self.connect_child(widget, 'group-all', self.group_all) - self.connect_child(widget, 'ungroup-all', self.ungroup_all) - self.connect_child(widget, 'group-tab', self.group_tab) - self.connect_child(widget, 'ungroup-tab', self.ungroup_tab) - widget.grab_focus() def remove(self, widget):