From 9c72b6287d73bb94db6b4e219f9fac3fe43e9ee8 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 21 Jan 2010 12:33:42 +0000 Subject: [PATCH] Implement tab changing keyboard shortcuts --- terminatorlib/notebook.py | 5 ++++- terminatorlib/paned.py | 1 + terminatorlib/terminal.py | 30 +++++++++++++++--------------- terminatorlib/window.py | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/terminatorlib/notebook.py b/terminatorlib/notebook.py index fb6f17ca..9205dd28 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 +from util import err, dbg, get_top_window class Notebook(Container, gtk.Notebook): """Class implementing a gtk.Notebook container""" @@ -97,6 +97,8 @@ class Notebook(Container, gtk.Notebook): def newtab(self, widget=None): """Add a new tab, optionally supplying a child widget""" + top_window = get_top_window(self) + if not widget: maker = Factory() widget = maker.make('Terminal') @@ -112,6 +114,7 @@ class Notebook(Container, gtk.Notebook): 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.set_tab_reorderable(widget, True) label = TabLabel(self.window.get_title(), self) diff --git a/terminatorlib/paned.py b/terminatorlib/paned.py index 914acec2..ed48190b 100755 --- a/terminatorlib/paned.py +++ b/terminatorlib/paned.py @@ -91,6 +91,7 @@ class Paned(Container): self.connect_child(widget, signal, signals[signal]) self.connect_child(widget, 'maximise', top_window.zoom, False) + self.connect_child(widget, 'tab-change', top_window.tab_change) widget.grab_focus() diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index ab5b243e..a4daf428 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -56,6 +56,8 @@ class Terminal(gtk.VBox): (gobject.TYPE_STRING,)), 'navigate': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)), + 'tab-change': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, + (gobject.TYPE_INT,)), } TARGET_TYPE_VTE = 8 @@ -1197,43 +1199,40 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) self.zoom() def key_next_tab(self): - # FIXME: Implement this - self.terminator.next_tab (self) + self.emit('tab-change', -1) def key_prev_tab(self): - # FIXME: Implement this - self.terminator.previous_tab (self) + self.emit('tab-change', -2) def key_switch_to_tab_1(self): - # FIXME: Implement these - self.terminator.switch_to_tab (self, 0) + self.emit('tab-change', 0) def key_switch_to_tab_2(self): - self.terminator.switch_to_tab (self, 1) + self.emit('tab-change', 1) def key_switch_to_tab_3(self): - self.terminator.switch_to_tab (self, 2) + self.emit('tab-change', 2) def key_switch_to_tab_4(self): - self.terminator.switch_to_tab (self, 3) + self.emit('tab-change', 3) def key_switch_to_tab_5(self): - self.terminator.switch_to_tab (self, 4) + self.emit('tab-change', 4) def key_switch_to_tab_6(self): - self.terminator.switch_to_tab (self, 5) + self.emit('tab-change', 5) def key_switch_to_tab_7(self): - self.terminator.switch_to_tab (self, 6) + self.emit('tab-change', 6) def key_switch_to_tab_8(self): - self.terminator.switch_to_tab (self, 7) + self.emit('tab-change', 7) def key_switch_to_tab_9(self): - self.terminator.switch_to_tab (self, 8) + self.emit('tab-change', 8) def key_switch_to_tab_10(self): - self.terminator.switch_to_tab (self, 9) + self.emit('tab-change', 9) def key_reset(self): self.vte.reset (True, False) @@ -1254,6 +1253,7 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) self.group_tab(self) def key_ungroup_tab(self): + # FIXME: IMplement this self.ungroup_tab(self) def key_new_window(self): diff --git a/terminatorlib/window.py b/terminatorlib/window.py index aa296e1c..230ab430 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -248,6 +248,7 @@ class Window(Container, gtk.Window): for signal in signals: self.connect_child(widget, signal, signals[signal]) + self.connect_child(widget, 'tab-change', self.tab_change) widget.grab_focus() def remove(self, widget): @@ -372,6 +373,38 @@ class Window(Container, gtk.Window): self.set_geometry_hints(self, -1, -1, -1, -1, extra_width, extra_height, font_width, font_height, -1.0, -1.0) + def tab_change(self, widget, num=None): + """Change to a specific tab""" + if num is None: + err('must specify a tab to change to') + + maker = Factory() + child = self.get_child() + + if not maker.isinstance(child, 'Notebook'): + dbg('child is not a notebook, nothing to change to') + return + + if num == -1: + # Go to the next tab + cur = child.get_current_page() + pages = child.get_n_pages() + if cur == pages - 1: + num = 0 + elif num == -2: + # Go to the previous tab + cur = child.get_current_page() + if cur > 0: + num = cur - 1 + else: + num = child.get_n_pages() - 1 + + child.set_current_page(num) + # Work around strange bug in gtk-2.12.11 and pygtk-2.12.1 + # Without it, the selection changes, but the displayed page doesn't + # change + child.set_current_page(child.get_current_page()) + class WindowTitle(object): """Class to handle the setting of the window title"""