[gnome-games/sudoku-tube] Make function-decorator into a method



commit ff3f14c4695fd686d3c7fcdad415140263d2f577
Author: Zhang Sen <zh jesse gmail com>
Date:   Wed May 27 17:46:31 2009 +0800

    Make function-decorator into a method
---
 gnome-sudoku/src/lib/main.py |   64 +++++++++++++++++++-----------------------
 1 files changed, 29 insertions(+), 35 deletions(-)

diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index d56b5bd..e32bc56 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -45,39 +45,6 @@ gtk.stock_add([('tracks',
                 _('Track moves'),
                 0, 0, ""), ])
 
-def activate_actions (uimanager, action_paths, sensitive):
-    for path in action_paths:
-        action = uimanager.get_action(path)
-        if not action:
-            action = uimanager.get_widget(path)
-        if not action:
-            print 'No action at path', path
-        else:
-            action.set_sensitive(sensitive)
-
-def inactivate_new_game_etc (fun):
-    def inactivate_new_game_etc_ (ui, *args, **kwargs):
-        paths = [
-            '/MenuBar/Game/New',
-            '/MenuBar/Game/NewWithContact',
-            '/MenuBar/Game/Print',
-            # undo/redo is handled elsewhere as it can't simply be turned on/off.
-            '/MenuBar/Edit/Clear',
-            '/MenuBar/Edit/ClearNotes',
-            '/MenuBar/View/ToggleToolbar',
-            '/MenuBar/Tools/ShowPossible',
-            '/MenuBar/Tools/AutofillCurrentSquare',
-            '/MenuBar/Tools/Autofill',
-            '/MenuBar/Tools/AlwaysShowPossible',
-            '/MenuBar/Tools/ShowImpossibleImplications',
-            '/MenuBar/Tools/Tracker',
-            '/MenuBar/Game/PuzzleInfo',
-            ]
-        activate_actions(ui.uimanager, paths, False)
-        ret = fun(ui, *args, **kwargs)
-        activate_actions(ui.uimanager, paths, True)
-        return ret
-    return inactivate_new_game_etc_
 
 class UI (gconf_wrapper.GConfWrapper):
     ui = '''<ui>
@@ -188,9 +155,8 @@ class UI (gconf_wrapper.GConfWrapper):
                 if self.gconf['generate_puzzles_in_background']:
                     gobject.timeout_add_seconds(1, lambda *args: self.start_worker_thread() and True)
 
-
-    @inactivate_new_game_etc
     def select_game (self):
+        self._activate_in_game_actions(False)
         self.tb.hide()
         self.update_statusbar()
         choice = game_selector.NewOrSavedGameSelector().run_swallowed_dialog(self.swallower)
@@ -209,7 +175,35 @@ class UI (gconf_wrapper.GConfWrapper):
             self.gsd.update_all_hints()
         if self.gconf['highlight']:
             self.gsd.toggle_highlight(True)
+        self._activate_in_game_actions(True)
 
+    def _activate_in_game_actions (self, sensitive):
+        """Inactivate some actions if we are in game-selector
+
+        Some actions should only be active during a game, and be disabled when
+        we are choosing game. We call them 'in-game actions'."""
+        in_game_actions = [
+            '/MenuBar/Game/New',
+            '/MenuBar/Game/NewWithContact',
+            '/MenuBar/Game/Print',
+            '/MenuBar/Edit/Clear',
+            '/MenuBar/Edit/ClearNotes',
+            '/MenuBar/View/ToggleToolbar',
+            '/MenuBar/Tools/ShowPossible',
+            '/MenuBar/Tools/AutofillCurrentSquare',
+            '/MenuBar/Tools/Autofill',
+            '/MenuBar/Tools/AlwaysShowPossible',
+            '/MenuBar/Tools/ShowImpossibleImplications',
+            '/MenuBar/Tools/Tracker',
+            '/MenuBar/Game/PuzzleInfo']
+        for path in in_game_actions:
+            action = self.uimanager.get_action(path)
+            if not action:
+                action = self.uimanager.get_widget(path)
+            if action:
+                action.set_sensitive(sensitive)
+            else:
+                print 'No action at path', path
 
     def show (self):
         self.gsd.show()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]