[gnome-games/applygsoc2009: 30/76] XXX: Extract method to get focused box



commit a207c151d5c33688393deb2a62a726fb790113ee
Author: Pablo Castellano <pablog src gnome org>
Date:   Thu Aug 26 13:03:03 2010 +0200

    XXX: Extract method to get focused box

 gnome-sudoku/src/lib/gsudoku.py |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/gsudoku.py b/gnome-sudoku/src/lib/gsudoku.py
index 06bf5ca..cbe9529 100644
--- a/gnome-sudoku/src/lib/gsudoku.py
+++ b/gnome-sudoku/src/lib/gsudoku.py
@@ -67,6 +67,10 @@ class SudokuNumberGrid (gtk.AspectFrame):
         for e in self.__entries__.values():
             e.modify_bg(gtk.STATE_NORMAL, color)
 
+    def get_focus(self):
+	    return self.table.get_focus_child()
+
+
 class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
 
     __gsignals__ = {
@@ -79,7 +83,6 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
     def __init__ (self, grid = None, group_size = 9,
                   show_impossible_implications = False):
         group_size = int(group_size)
-		self.focused = None
         self.hints = 0
         self.hint_square = None
         self.always_show_hints = False
@@ -122,7 +125,6 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
         return dest
 
     def focus_callback (self, e, event):
-        self.focused = e
         self.emit('focus-changed')
 
     def _get_highlight_colors (self):
@@ -147,21 +149,25 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
 
     def toggle_highlight (self, val):
         self.do_highlight_cells = val
-        self._unhighlight_cells()
-        if self.focused:
+        if val:
+            self._unhighlight_cells()
+        else:
             self._highlight_cells()
 
-    def _unhighlight_cells (self, *args):
+    def _unhighlight_cells (self):
         for e in self.__entries__.values():
             e.set_background_color(None)
 
-    def _highlight_cells (self, *args):
+    def _highlight_cells (self):
+        focused = self.get_focus()
+		if not focused: # no need to do anything if no box has focus
+		    return
         if not self.do_highlight_cells:
             return
-        self._unhighlight_cells()
-        if self.focused:
+        self._unhighlight_cells() # first clear all the cells
+        if focused:
             self._get_highlight_colors()
-        my_x, my_y = self.focused.x, self.focused.y
+        my_x, my_y = focused.x, focused.y
 
         # col_coords can sometimes be null.
         if not hasattr(self.grid, 'col_coords'):
@@ -567,13 +573,13 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
         return retval
 
     def auto_fill_current_entry (self):
-        e = self.focused
-        if not e:
+	    focused = self.get_focus()
+        if not focused:
             return
-        filled = self.grid.auto_fill_for_xy(e.x, e.y)
+        filled = self.grid.auto_fill_for_xy(focused.x, focused.y)
         if filled and filled != -1:
-            e.set_text_interactive('')
-            e.set_text_interactive(str(filled[1]))
+            focused.set_text_interactive('')
+            focused.set_text_interactive(str(filled[1]))
 
     def __set_impossible (self, coords, setting):
         '''Call set_impossible() on a grid entry



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