[gnome-games/sudoku-tube] Make auto_fill_for_xy work



commit db1ae0a1004a4a3032fba98a5898dec6a63f0092
Author: Zhang Sen <zh jesse gmail com>
Date:   Tue Jul 14 08:39:35 2009 +0800

    Make auto_fill_for_xy work
    
    SudokuSolver.auto_fill_for_xy() should only return the possible value, and not
    change the grid.

 gnome-sudoku/src/lib/gsudoku.py |   10 +++-------
 gnome-sudoku/src/lib/main.py    |    3 ++-
 gnome-sudoku/src/lib/sudoku.py  |    2 --
 3 files changed, 5 insertions(+), 10 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/gsudoku.py b/gnome-sudoku/src/lib/gsudoku.py
index be8b412..584fb64 100644
--- a/gnome-sudoku/src/lib/gsudoku.py
+++ b/gnome-sudoku/src/lib/gsudoku.py
@@ -570,14 +570,10 @@ class SudokuModel:
             self.set_value(coords[0], coords[1], val)
         return changed
 
-    def auto_fill_current_entry (self):
-        e = self.get_focus()
-        if not e:
-            return
-        filled = self.grid.auto_fill_for_xy(e.x, e.y)
+    def auto_fill_current(self, x, y):
+        filled = self.grid.auto_fill_for_xy(x, y)
         if filled and filled != -1:
-            e.set_text_interactive('')
-            e.set_text_interactive(str(filled[1]))
+            self.set_value(x, y, filled[1])
 
     def _mark_impossible_implications(self, x, y):
         if not self.grid:
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index cadadd7..168460b 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -492,7 +492,8 @@ class UI (gconf_wrapper.GConfWrapper):
         self._main_model.auto_fill()
 
     def auto_fill_current_square_cb (self, *args):
-        self.gsd.auto_fill_current_entry()
+        current = self._main_grid_vew.get_focus()
+        self._main_model.auto_fill_current(current.x, current.y)
 
     def tracker_toggle_cb (self, widg):
         if widg.get_active():
diff --git a/gnome-sudoku/src/lib/sudoku.py b/gnome-sudoku/src/lib/sudoku.py
index f8d6fcf..d42e105 100644
--- a/gnome-sudoku/src/lib/sudoku.py
+++ b/gnome-sudoku/src/lib/sudoku.py
@@ -275,7 +275,6 @@ class SudokuSolver (SudokuGrid):
         possible = self.gen_set - self.rows[y] - self.cols[x] - self.boxes[self.box_by_coords[(x, y)]]
         if len(possible) == 1:
             val = possible.pop()
-            self.add(x, y, val)
             return ((x, y), val)
         if len(possible) == 0:
             return -1
@@ -294,7 +293,6 @@ class SudokuSolver (SudokuGrid):
             if needed_set and len(needed_set) == 1:
                 val = needed_set.pop()
                 if val in possible:
-                    self.add(x, y, val)
                     return ((x, y), val)
                 else:
                     return -1



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