[gnome-games/sudoku-tube] Extract method of (de-)activate actions



commit a0728b5d85011e26a32109b4a17b6dffaeab990f
Author: Zhang Sen <zh jesse gmail com>
Date:   Wed May 27 17:01:25 2009 +0800

    Extract method of (de-)activate actions
---
 gnome-sudoku/src/lib/main.py |   28 ++++++++++++----------------
 1 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index f0cfabc..0169738 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -45,6 +45,16 @@ 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 = [
@@ -63,23 +73,9 @@ def inactivate_new_game_etc (fun):
             '/MenuBar/Tools/Tracker',
             '/MenuBar/Game/PuzzleInfo',
             ]
-        for p in paths:
-            action = ui.uimanager.get_action(p)
-            if not action:
-                action = ui.uimanager.get_widget(p)
-            if not action:
-                print 'No action at path', p
-            else:
-                action.set_sensitive(False)
+        activate_actions(ui.uimanager, paths, False)
         ret = fun(ui, *args, **kwargs)
-        for p in paths:
-            action = ui.uimanager.get_action(p)
-            if not action:
-                action = ui.uimanager.get_widget(p)
-            if not action:
-                print 'No action at path', p
-            else:
-                action.set_sensitive(True)
+        activate_actions(ui.uimanager, paths, True)
         return ret
     return inactivate_new_game_etc_
 



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