[gnome-games/sudoku-tube] Let the model emit the puzzle-finished signal
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games/sudoku-tube] Let the model emit the puzzle-finished signal
- Date: Mon, 3 Aug 2009 09:00:36 +0000 (UTC)
commit f4cd1aad664aa7f24d42fc00009caf33928c28f2
Author: Zhang Sen <zh jesse gmail com>
Date: Mon Aug 3 16:53:31 2009 +0800
Let the model emit the puzzle-finished signal
gnome-sudoku/src/lib/main.py | 27 +++++++++++++++------------
gnome-sudoku/src/lib/model.py | 20 +++++++++++---------
gnome-sudoku/src/lib/view.py | 13 +------------
3 files changed, 27 insertions(+), 33 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index 7d0388b..a86393b 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -14,6 +14,7 @@ import gtk
from gettext import gettext as _
from gettext import ngettext
+import dancer
import game_selector
import model
import view
@@ -175,6 +176,7 @@ class UI (gconf_wrapper.GConfWrapper):
"""Properly do the setup after entering game
Like show highlight, update hints, start timer, etc."""
+ self._main_model.connect('puzzle-finished', self.you_win_callback)
self._calc_difficulty()
self.setup_toggles()
self.update_statusbar()
@@ -244,7 +246,6 @@ class UI (gconf_wrapper.GConfWrapper):
tracker_ui_container = self.builder.get_object("tracker_ui_container")
self._main_grid_vew = view.SudokuView(9, self._history_manager)
- self._main_grid_vew.connect('puzzle-finished', self.you_win_callback)
main_grid_container.pack_start(self._main_grid_vew, padding=6)
self._tracker_ui = tracker_box.TrackerBox(self._main_grid_vew)
@@ -358,14 +359,7 @@ class UI (gconf_wrapper.GConfWrapper):
self.dancer.stop_dancing()
delattr(self, 'dancer')
- def you_win_callback (self, grid):
- if hasattr(self, 'dancer'):
- return
- self.won = True
- # increase difficulty for next time.
- self.gconf['difficulty'] = self.gconf['difficulty'] + 0.1
- self.timer.finish_timing()
- self.sudoku_tracker.finish_game(self._jar_game())
+ def _build_report_label(self):
sublabel = _("You completed the puzzle in %(totalTime)s (%(activeTime)s active)") % {'totalTime': self.timer.total_time_string(),
'activeTime': self.timer.active_time_string()
}
@@ -387,12 +381,21 @@ class UI (gconf_wrapper.GConfWrapper):
"You used the auto-fill %(n)s times",
autofill_count) % {
'n': autofill_count}
- import dancer
+
+ return sublabel
+
+ def you_win_callback(self, model):
+ if hasattr(self, 'dancer'):
+ return
+ self.won = True
+ # increase difficulty for next time.
+ self.gconf['difficulty'] = self.gconf['difficulty'] + 0.1
+ self.timer.finish_timing()
+ self.sudoku_tracker.finish_game(self._jar_game())
self.dancer = dancer.GridDancer(self._main_grid_vew, self._main_model)
self.dancer.start_dancing()
dialog_extras.show_message(_("You win!"), label = _("You win!"),
- sublabel = sublabel
- )
+ sublabel=self._build_report_label())
def new_cb (self, *args):
if self._close_current_game():
diff --git a/gnome-sudoku/src/lib/model.py b/gnome-sudoku/src/lib/model.py
index 515b684..7058e2b 100644
--- a/gnome-sudoku/src/lib/model.py
+++ b/gnome-sudoku/src/lib/model.py
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
+
+import gobject
+
import sudoku
@@ -121,9 +124,6 @@ class NotesModel:
self.update_all_hints()
- def puzzle_finished_cb(self):
- self._clear_hints()
-
def update_all_hints(self):
for x in range(self._group_size):
for y in range(self._group_size):
@@ -174,9 +174,15 @@ class NotesModel:
self._clear_top_note()
self._clear_bottom_note()
-class SudokuModel:
+class SudokuModel(gobject.GObject):
+
+ __gsignals__ = {
+ # atm. only used by dancer
+ "puzzle-finished": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
+ }
def __init__ (self, virgin_grid, group_size, initial_grid=None):
+ gobject.GObject.__init__(self)
self.autofill_count = 0
self.show_impossible_implications = False
self.impossibilities = set()
@@ -199,10 +205,6 @@ class SudokuModel:
observer.update(values)
self._check_for_completeness()
- def _signal_completeness(self):
- for observer in self._observers:
- observer.puzzle_finished_cb()
-
def reset_grid (self):
"""Reset grid to its original setup.
"""
@@ -289,7 +291,7 @@ class SudokuModel:
def _check_for_completeness(self):
if self.grid.check_for_completeness():
- self._signal_completeness()
+ self.emit("puzzle-finished")
def set_autofill_count(self, count):
self.autofill_count = count
diff --git a/gnome-sudoku/src/lib/view.py b/gnome-sudoku/src/lib/view.py
index a081fa3..5cd183a 100644
--- a/gnome-sudoku/src/lib/view.py
+++ b/gnome-sudoku/src/lib/view.py
@@ -4,7 +4,6 @@ import math
import random
import gtk
-import gobject
import colors
import number_box
@@ -208,17 +207,10 @@ class SudokuNumberGrid (gtk.AspectFrame):
def reset(self):
pass
-class SudokuView(SudokuNumberGrid, gobject.GObject):
-
- # some signals to give notice about change of the View
- __gsignals__ = {
- # atm. only used by dancer
- "puzzle-finished": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
- }
+class SudokuView(SudokuNumberGrid):
def __init__(self, group_size, controller=None):
SudokuNumberGrid.__init__(self, group_size)
- gobject.GObject.__init__(self)
self._model = None
self._do_highlight_cells = False
@@ -303,9 +295,6 @@ class SudokuView(SudokuNumberGrid, gobject.GObject):
# default black color
return None
- def puzzle_finished_cb(self):
- self.emit("puzzle-finished")
-
def update_notes(self, notes_list):
for notes in notes_list:
x, y, top_note, bottom_note = notes
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]