[gnome-games/applygsoc2009: 16/76] Unified way to open game
- From: Pablo Castellano <pablog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/applygsoc2009: 16/76] Unified way to open game
- Date: Mon, 6 Sep 2010 02:48:34 +0000 (UTC)
commit ef636e54409ccccabe25ab708bef0525fcac8557
Author: Pablo Castellano <pablog src gnome org>
Date: Thu Aug 26 04:51:35 2010 +0200
Unified way to open game
gnome-sudoku/src/lib/main.py | 32 +++++++++++++++++++++-----------
1 files changed, 21 insertions(+), 11 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index 53bfc4d..42bbc22 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -149,7 +149,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"""
@@ -158,8 +159,17 @@ class UI (gconf_wrapper.GConfWrapper):
if new_puzzle:
# get_puzzles returns a list of (<puzzle>, <difficulty>)
self._game = self.sudoku_maker.get_puzzles(1, ['easy'])[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
@@ -178,18 +188,16 @@ class UI (gconf_wrapper.GConfWrapper):
# Generate puzzles in background...
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()
@@ -414,7 +422,9 @@ 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])
@simple_debug
def _close_current_game (self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]