From c8e83793085b76e5d6eb90a452657ff6b19a164d Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Thu, 19 Apr 2012 16:29:10 -0400 Subject: [PATCH] Implemented reordering tabs and Ctrl+tab to cycle between them --- pygo.py | 40 ++++++++++++++++++++++++++++++++++++++++ ui/default.glade | 1 + 2 files changed, 41 insertions(+) diff --git a/pygo.py b/pygo.py index 23dd3d5..9010821 100755 --- a/pygo.py +++ b/pygo.py @@ -37,13 +37,30 @@ class Pygo(): # gobject.timeout_add(1000, self.update) + # fixme - ctrl+shift+tab just does a shift+tab, even with the return True... + def on_key_pressed(self, widget, event): + key = gtk.gdk.keyval_name(event.keyval) + + if key == 'Tab' and event.state & gtk.gdk.CONTROL_MASK: + if event.state & gtk.gdk.SHIFT_MASK: + self.do_prev_page() + else: + self.do_next_page() + + return True + + def on_game_close(self, widget): + if self.games.get_current_page() == -1: + return + self.games.remove_page(self.games.get_current_page()) def on_local_new(self, widget): game = gogame.GoGame(goban.Goban()) self.games.append_page(game, gtk.Label('Local Game')) + self.games.set_tab_reorderable(game, True) game.show_all() @@ -55,6 +72,29 @@ class Pygo(): sys.exit(0) + def do_prev_page(self): + '''Goes to the previous tab page, but looping if this is the first''' + if self.games.get_current_page() == -1: + return + + new_page = self.games.get_current_page() - 1 + if new_page < 0: + new_page = self.games.get_n_pages() - 1 + + self.games.set_current_page(new_page) + + + def do_next_page(self): + '''Goes to the next tab page, but looping if this is the last''' + if self.games.get_current_page() == -1: + return + + new_page = self.games.get_current_page() + 1 + if new_page >= self.games.get_n_pages(): + new_page = 0 + + self.games.set_current_page(new_page) + def main(): # Read config file diff --git a/ui/default.glade b/ui/default.glade index 1a3d4a7..a2a056b 100644 --- a/ui/default.glade +++ b/ui/default.glade @@ -18,6 +18,7 @@ GDK_GRAVITY_NORTH_WEST True False +