[gnome-games/sudoku-tube] Extract method to get focused box
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/sudoku-tube] Extract method to get focused box
- Date: Wed, 8 Jul 2009 14:57:51 +0000 (UTC)
commit 935d661fda185ddb431963ef9dec033a360a512d
Author: Zhang Sen <zh jesse gmail com>
Date: Wed Jul 8 22:48:51 2009 +0800
Extract method to get focused box
gnome-sudoku/src/lib/gsudoku.py | 30 +++++++++++++++++-------------
1 files changed, 17 insertions(+), 13 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/gsudoku.py b/gnome-sudoku/src/lib/gsudoku.py
index 3201c49..d90e975 100644
--- a/gnome-sudoku/src/lib/gsudoku.py
+++ b/gnome-sudoku/src/lib/gsudoku.py
@@ -108,6 +108,10 @@ class SudokuNumberGrid (gtk.AspectFrame):
def set_focus(self, x, y):
self.table.set_focus_child(self.__entries__[x, y])
+ def get_focus(self):
+ return self.table.get_focus_child()
+
+
class ParallelDict (dict):
"""A handy new sort of dictionary for tracking conflicts.
@@ -164,7 +168,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.always_show_hints = False
self.auto_fills = 0
@@ -205,8 +208,8 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
return None, None
def _focus_callback(self, e, event):
- self.focused = e
- self._highlight_cells()
+ if self.do_highlight_cells:
+ self._highlight_cells()
def _get_highlight_colors(self):
entry = self.__entries__.values()[0]
@@ -230,21 +233,23 @@ 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):
- if not self.do_highlight_cells:
+ focused = self.get_focus()
+ if not focused: # no need to do anything if no box has focus
return
- self.unhighlight_cells()
+ self.unhighlight_cells() # first clear all the cells
if not hasattr(self, 'box_color'):
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'):
@@ -267,8 +272,8 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
e.set_background_color(self.box_color)
def show_hint (self):
- if self.focused:
- entry = self.focused
+ entry = self.get_focus()
+ if entry:
if entry.read_only or entry.get_text():
pass
else:
@@ -508,9 +513,8 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
self.emit('puzzle-finished')
return retval
-
def auto_fill_current_entry (self):
- e = self.focused
+ e = self.get_focus()
if not e:
return
filled = self.grid.auto_fill_for_xy(e.x, e.y)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]