[gnome-games/applygsoc2009: 7/76] Remove the ugly dialog-swallower



commit 40bc18dae653c7436b76eb882288e1bd44b8027b
Author: Pablo Castellano <pablog src gnome org>
Date:   Thu Aug 26 04:38:14 2010 +0200

    Remove the ugly dialog-swallower
    
    Also changes how the game is launched: a new or saved puzzle is directly opened
    on game launching. Pressing 'New' will open a dialog to select games.

 gnome-sudoku/src/lib/dialog_swallower.py |   77 ------------------------------
 gnome-sudoku/src/lib/game_selector.py    |    8 +---
 gnome-sudoku/src/lib/gsudoku.py          |   36 --------------
 gnome-sudoku/src/lib/main.py             |   77 ++++++++++++++---------------
 gnome-sudoku/src/lib/sudoku_thumber.py   |    2 +-
 5 files changed, 39 insertions(+), 161 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/game_selector.py b/gnome-sudoku/src/lib/game_selector.py
index 82120a1..0e1e1b6 100644
--- a/gnome-sudoku/src/lib/game_selector.py
+++ b/gnome-sudoku/src/lib/game_selector.py
@@ -211,7 +211,7 @@ class NewOrSavedGameSelector:
         self.dialog.emit('response', gtk.RESPONSE_OK)
 
     @simple_debug
-    def close (self):
+    def close (self, *args):
         self.dialog.emit('response', gtk.RESPONSE_CLOSE)
 
     @simple_debug
@@ -221,12 +221,6 @@ class NewOrSavedGameSelector:
         else:
             return None
 
-    def run_swallowed_dialog (self, swallower):
-        self.setup_dialog()
-        return self.handle_response(
-            swallower.run_dialog(self.dialog)
-            )
-
     def run_dialog (self):
         self.setup_dialog()
         return self.handle_response(self.dialog.run())
diff --git a/gnome-sudoku/src/lib/gsudoku.py b/gnome-sudoku/src/lib/gsudoku.py
index 2202352..d82c643 100644
--- a/gnome-sudoku/src/lib/gsudoku.py
+++ b/gnome-sudoku/src/lib/gsudoku.py
@@ -755,42 +755,6 @@ if __name__ == '__main__':
         t.__entries__[(3, 1)].set_value(3)
         t.__entries__[(3, 1)].set_note_text('234', '12')
 
-    def reproduce_foobared_rendering ():
-        from dialog_swallower import SwappableArea
-        sgd = SudokuGameDisplay()
-        sgd.set_bg_color('black')
-        vb = gtk.VBox()
-        hb = gtk.HBox()
-        swallower = SwappableArea(hb)
-        tb = gtk.Toolbar()
-        b = gtk.ToolButton(stock_id = gtk.STOCK_QUIT)
-        b.connect('clicked', lambda x: window.hide() or gtk.main_quit())
-        tb.add(b)
-        def run_swallowed_dialog (*args):
-            md = MessageDialog(title = "Bar", label = "Bar", sublabel = "Baz "*12)
-            swallower.run_dialog(md)
-        b2 = gtk.ToolButton(label = 'Dialog')
-        b2.connect('clicked', run_swallowed_dialog)
-        tb.add(b2)
-        vb.pack_start(tb, fill = False, expand = False)
-        vb.pack_start(swallower, padding = 12)
-        window.add(vb)
-        window.show_all()
-        from gtk_goodies.dialog_extras import MessageDialog
-        md = MessageDialog(title = "Foo", label = "Foo", sublabel = "Bar "*12)
-        swallower.run_dialog(md)
-        hb.pack_start(sgd, padding = 6)
-        game = '''1 8 4 2 0 0 0 0 0
-                  0 6 0 0 0 9 1 2 0
-                  0 2 0 0 8 0 0 0 0
-                  0 1 8 0 5 0 0 0 0
-                  9 0 0 0 0 0 0 0 3
-                  0 0 0 0 1 0 6 5 0
-                  0 0 0 0 9 0 0 8 0
-                  0 5 7 1 0 0 0 9 0
-                  0 0 0 0 0 3 5 4 7'''
-        sgd.change_grid(game, 9)
-
     def test_sudoku_game ():
         game = '''1 8 4 2 0 0 0 0 0
                   0 6 0 0 0 9 1 2 0
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index 42b59ac..ec74e5e 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -14,7 +14,6 @@ import pango
 from gettext import gettext as _
 from gettext import ngettext
 
-import dialog_swallower
 import game_selector
 import gsudoku
 import printing
@@ -128,16 +127,34 @@ class UI (gconf_wrapper.GConfWrapper):
         # setup sudoku maker...
         self.sudoku_maker = sudoku_maker.SudokuMaker()
         self.sudoku_tracker = saver.SudokuTracker()
-        # generate puzzles while our use is working...
+
+		self._game = None
+		self._auto_load_saved()
+		if not self._game: # no game loaded
+		    self._auto_load_new()
+
         self.show()
-		self.quit = False
-        if run_selector:
-            if self.select_game():
-                # If this return True, the user closed...
-                self.quit = True
-            else:
-                self.quit = False
-				self._run_background_generator()
+		# generate puzzles while our use is working...
+		self._run_background_generator()
+
+	def _auto_load_saved(self):
+		"""Automatically open a saved game
+	
+        To keep things simple and keep aligned with other game, we should only
+        save *one* game in the future. And auto load this one game on launch"""
+        saved_games = self.sudoku_tracker.list_saved_games()
+        if saved_games:
+            self._game = saved_games[0]
+            saver.open_game(self, self._game)
+            self.update_statusbar()
+
+    def _auto_load_new(self):
+        """Automatically open a new game"""
+        # should use preconfigured level
+        # get_puzzles returns a list of (<puzzle>, <difficulty>)
+        self._game = self.sudoku_maker.get_puzzles(1, ['easy'])[0][0]
+        # process self._game==None
+        self.gsd.change_grid(self._game, 9)
 	
     def _run_background_generator (self):
         """Generate puzzles in background"""
@@ -149,9 +166,10 @@ class UI (gconf_wrapper.GConfWrapper):
         gobject.timeout_add_seconds(1, lambda *args: self.start_worker_thread() and True)
 
     def select_game (self):
-		self._activate_in_game_actions(False)
-        self.tb.hide()
-        choice = game_selector.NewOrSavedGameSelector().run_swallowed_dialog(self.swallower)
+		self.update_statusbar() # make the statusbar empty
+        selector = game_selector.NewOrSavedGameSelector()
+        choice = selector.run_dialog()
+        selector.dialog.destroy()
         if not choice:
             return True
         self.timer.start_timing()
@@ -159,13 +177,8 @@ class UI (gconf_wrapper.GConfWrapper):
             self.gsd.change_grid(choice[1], 9)
         if choice[0] == game_selector.NewOrSavedGameSelector.SAVED_GAME:
             saver.open_game(self, choice[1])
-        if self.gconf['show_toolbar']:
-            self.tb.show()
         if self.gconf['always_show_hints']:
             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
@@ -323,9 +336,7 @@ class UI (gconf_wrapper.GConfWrapper):
         self.tb = self.uimanager.get_widget('/Toolbar')
         self.vb.pack_start(self.tb, fill = False, expand = False)
         self.main_area = gtk.HBox()
-        self.swallower = dialog_swallower.SwappableArea(self.main_area)
-        self.swallower.show()
-        self.vb.pack_start(self.swallower, True, padding = 12)
+        self.vb.pack_start(self.main_area, True, padding = 12)
         self.main_area.pack_start(self.gsd, padding = 6)
         self.main_actions.set_visible(True)
         self.game_box = gtk.VBox()
@@ -463,19 +474,6 @@ class UI (gconf_wrapper.GConfWrapper):
             and self.gsd.grid.is_changed()
             and (not self.won)):
             self.save_game(self)
-        if gtk.main_level() > 1:
-            # If we are in an embedded mainloop, that means that one
-            # of our "swallowed" dialogs is active, in which case we
-            # have to quit that mainloop before we can quit
-            # properly.
-            if self.swallower.running:
-                d = self.swallower.running
-                d.response(gtk.RESPONSE_DELETE_EVENT)
-            gtk.main_quit() # Quit the embedded mainloop
-            gobject.idle_add(self.quit_cb, 100) # Call ourselves again
-                                               # to quit the main
-                                               # mainloop
-            return
         # make sure we really go away before doing our saving --
         # otherwise we appear sluggish.
         while gtk.events_pending():
@@ -993,12 +991,11 @@ def start_game ():
         return
 
     u = UI()
-    if not u.quit:
-        try:
-            gtk.main()
-        except KeyboardInterrupt:
-            # properly quit on a keyboard interrupt...
-            u.quit_cb()
+	try:
+    	gtk.main()
+    except KeyboardInterrupt:
+        # properly quit on a keyboard interrupt...
+        u.quit_cb()
 
 def profile_me ():
     print 'Profiling GNOME Sudoku'
diff --git a/gnome-sudoku/src/lib/sudoku_thumber.py b/gnome-sudoku/src/lib/sudoku_thumber.py
index b8cb242..c1a9a0e 100644
--- a/gnome-sudoku/src/lib/sudoku_thumber.py
+++ b/gnome-sudoku/src/lib/sudoku_thumber.py
@@ -128,7 +128,7 @@ def draw_sudoku (cr, sudoku, played, size, offset_x = 0, offset_y = 0, border_co
                 cr.show_text(letter)
 
 def make_pixbuf (sudoku, played, border_color, line_color = (0.4, 0.4, 0.4)):
-    size = 126
+    size = 60
     surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, size, size)
     cr = cairo.Context(surface)
     draw_sudoku(cr, sudoku, played,  size, 0, 0, border_color, line_color)



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