[gnome-games/sudoku-tube] Unified way to open game



commit 5fccfad8fc2a35d09f767fe3921895474fd360a4
Author: Zhang Sen <zh jesse gmail com>
Date:   Sat May 30 19:08:46 2009 +0800

    Unified way to open game
---
 gnome-sudoku/src/lib/main.py |   39 ++++++++++++++++++++++++---------------
 1 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index fb45972..2498ea7 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -167,7 +167,8 @@ class UI (gconf_wrapper.GConfWrapper):
         saved_games = self.sudoku_tracker.list_saved_games()
         if saved_games:
             self._game = saved_games[0]
-            saver.open_game(self, self._game)
+            self._open_game(game_selector.NewOrSavedGameSelector.SAVED_GAME,
+                    self._game)
 
     def _auto_load_new(self):
         """Automatically open a new game"""
@@ -176,7 +177,16 @@ class UI (gconf_wrapper.GConfWrapper):
         if new_puzzle:
             # new_puzzle is a list, with the form of (<puzzle>, <difficulty>)
             self._game = new_puzzle[0][0]
-            self.gsd.change_grid(self._game, 9)
+            self._open_game(game_selector.NewOrSavedGameSelector.NEW_GAME,
+                    self._game)
+
+    def _open_game(self, type, puzzle):
+        """Finally enter the puzzle"""
+        if type == game_selector.NewOrSavedGameSelector.NEW_GAME:
+            self.gsd.change_grid(puzzle, 9)
+        elif type == game_selector.NewOrSavedGameSelector.SAVED_GAME:
+            saver.open_game(self, puzzle)
+        self._post_open_setup()
 
     def _post_open_setup(self):
         """Properly do the setup after entering game
@@ -193,18 +203,16 @@ class UI (gconf_wrapper.GConfWrapper):
             gobject.timeout_add_seconds(1,
                     lambda *args: self.start_worker_thread() and True)
 
-    def select_game (self):
+    def _select_game(self):
+        """Run the game-selector
+
+        Return (chosen-game-type, chosen-puzzle),
+        Return None if user cancels."""
         self.update_statusbar() # make the statusbar empty
         selector = game_selector.NewOrSavedGameSelector()
         choice = selector.run_dialog()
         selector.dialog.destroy()
-        if not choice:
-            return True
-        if choice[0] == game_selector.NewOrSavedGameSelector.NEW_GAME:
-            self.gsd.change_grid(choice[1], 9)
-        if choice[0] == game_selector.NewOrSavedGameSelector.SAVED_GAME:
-            saver.open_game(self, choice[1])
-        self._post_open_setup()
+        return choice
 
     def show (self):
         self.gsd.show()
@@ -240,7 +248,7 @@ class UI (gconf_wrapper.GConfWrapper):
             ('New', gtk.STOCK_NEW, None,
              '<Control>n', _('New game'), self.new_cb),
             ('NewWithContact', gtk.STOCK_NEW, _('New with contact'),
-                None, _('New with contact'), self.new_with_contact),
+                None, _('New with contact'), self._new_with_contact),
             ('Print', gtk.STOCK_PRINT, None,
              None, _('Print current game'), self.print_game),
             ('PrintMany', gtk.STOCK_PRINT, _('Print _Multiple Sudokus'),
@@ -451,11 +459,12 @@ class UI (gconf_wrapper.GConfWrapper):
     @simple_debug
     def new_cb (self, *args):
         if self._close_current_game():
-            self.select_game()
+            choice = self._select_game()
+            if choice:
+                self._open_game(choice[0], choice[1])
 
-    def new_with_contact (self, *args):
-        if self._close_current_game():
-            self.select_game()
+    def _new_with_contact(self, *args):
+        pass
 
     @simple_debug
     def _close_current_game (self):



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