[gnome-games/sudoku-tube] Append underscore to private methods



commit 1bcf56af24c9bd36ba7a884a25779358f248af86
Author: Zhang Sen <zh jesse gmail com>
Date:   Mon Jun 8 22:58:39 2009 +0800

    Append underscore to private methods
---
 gnome-sudoku/src/lib/gsudoku.py |   79 ++++++++++++++++++++-------------------
 1 files changed, 40 insertions(+), 39 deletions(-)

diff --git a/gnome-sudoku/src/lib/gsudoku.py b/gnome-sudoku/src/lib/gsudoku.py
index e3defd7..a05bb2e 100644
--- a/gnome-sudoku/src/lib/gsudoku.py
+++ b/gnome-sudoku/src/lib/gsudoku.py
@@ -162,22 +162,22 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
         self.__trackers_tracking__ = {}
         gobject.GObject.__init__(self)
         SudokuNumberGrid.__init__(self, group_size = group_size)
-        self.setup_grid(grid, group_size)
+        self._setup_grid(grid, group_size)
         for e in self.__entries__.values():
             e.show()
-            e.connect('undo-change', self.entry_callback)
-            e.connect('changed', self.entry_callback)
-            e.connect('focus-in-event', self.focus_callback)
-            e.connect('key-press-event', self.key_press_cb)
-        self.connect('focus-changed', self.highlight_cells)
+            e.connect('undo-change', self._entry_callback)
+            e.connect('changed', self._entry_callback)
+            e.connect('focus-in-event', self._focus_callback)
+            e.connect('key-press-event', self._key_press_cb)
+        self.connect('focus-changed', self._highlight_cells)
 
-    def key_press_cb (self, widget, event):
+    def _key_press_cb(self, widget, event):
         key = gtk.gdk.keyval_name(event.keyval)
-        dest = self.go_around(widget.x, widget.y, key)
+        dest = self._go_around(widget.x, widget.y, key)
         if dest:
             self.table.set_focus_child(self.__entries__[dest])
 
-    def go_around (self, x, y, direction):
+    def _go_around(self, x, y, direction):
         '''return the coordinate if we should go to the other side of the grid.
         Or else return None.'''
         (limit_min, limit_max) = (0, self.group_size -1)
@@ -194,11 +194,11 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
         return dest
 
     @simple_debug
-    def focus_callback (self, e, event):
+    def _focus_callback(self, e, event):
         self.focused = e
         self.emit('focus-changed')
 
-    def get_highlight_colors (self):
+    def _get_highlight_colors(self):
         entry = self.__entries__.values()[0]
         default_color = gtkcolor_to_rgb(entry.style.bg[gtk.STATE_SELECTED])
         hsv = colors.rgb_to_hsv(*default_color)
@@ -220,20 +220,20 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
 
     def toggle_highlight (self, val):
         self.do_highlight_cells = val
-        self.unhighlight_cells()
+        self._unhighlight_cells()
         if self.focused:
-            self.highlight_cells()
+            self._highlight_cells()
 
-    def unhighlight_cells (self, *args):
+    def _unhighlight_cells(self, *args):
         for e in self.__entries__.values():
             e.set_background_color(None)
 
-    def highlight_cells (self, *args):
+    def _highlight_cells(self, *args):
         if not self.do_highlight_cells:
             return
-        self.unhighlight_cells()
+        self._unhighlight_cells()
         if not hasattr(self, 'box_color'):
-            self.get_highlight_colors()
+            self._get_highlight_colors()
         my_x, my_y = self.focused.x, self.focused.y
 
         # col_coords can sometimes be null.
@@ -264,9 +264,9 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
             if entry.read_only or entry.get_text():
                 pass
             else:
-                self.show_hint_for_entry(entry, interactive = True)
+                self._show_hint_for_entry(entry, interactive = True)
 
-    def show_hint_for_entry (self, entry, interactive = False):
+    def _show_hint_for_entry(self, entry, interactive = False):
         if interactive:
             set_method = entry.set_note_text_interactive
         else:
@@ -299,7 +299,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
                 if not self.grid.virgin._get_(x, y):
                     val = self.__entries__[(x, y)].get_value() # get the value from the user-visible grid,
                     if val:
-                        removed.append((x, y, val, self.trackers_for_point(x, y, val)))
+                        removed.append((x, y, val, self._trackers_for_point(x, y, val)))
                         self.remove(x, y, do_removal = True)
         return removed
 
@@ -320,7 +320,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
         self.clear_notes(clear_args = {'bottom_text':''})
 
     @simple_debug
-    def blank_grid (self):
+    def _blank_grid(self):
         for x in range(self.group_size):
             for y in range(self.group_size):
                 e = self.__entries__[(x, y)]
@@ -337,8 +337,8 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
         self.impossible_hints = 0
         self.trackers = {}
         self.__trackers_tracking__ = {}
-        self.blank_grid()
-        self.setup_grid(grid, group_size)
+        self._blank_grid()
+        self._setup_grid(grid, group_size)
 
     @simple_debug
     def load_game (self, game):
@@ -347,7 +347,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
         A game is simply a two lined string where the first line represents our
         virgin self and line two represents our game-in-progress.
         """
-        self.blank_grid()
+        self._blank_grid()
         if '\n' in game:
             virgin, in_prog = game.split('\n')
         else:
@@ -364,7 +364,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
                         self.add_value(col, row, values[index])
 
     @simple_debug
-    def setup_grid (self, grid, group_size):
+    def _setup_grid(self, grid, group_size):
         self.doing_initial_setup = True
         self.__error_pairs__ = ParallelDict()
         if isinstance(grid, sudoku.SudokuGrid):
@@ -379,15 +379,15 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
         self.doing_initial_setup = False
 
     @simple_debug
-    def entry_callback (self, widget, *args):
+    def _entry_callback(self, widget, *args):
         if not widget.get_text():
             if self.grid and self.grid._get_(widget.x, widget.y):
                 self.grid.remove(widget.x, widget.y)
             self.remove(widget.x, widget.y)
         else:
-            self.entry_validate(widget)
+            self._entry_validate(widget)
         if self.show_impossible_implications:
-            self.mark_impossible_implications(widget.x, widget.y)
+            self._mark_impossible_implications(widget.x, widget.y)
         if self.always_show_hints:
             self.update_all_hints()
 
@@ -400,16 +400,16 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
                 elif e.get_text():
                     e.set_note_text(bottom_text = '')
                 else:
-                    self.show_hint_for_entry(e)
+                    self._show_hint_for_entry(e)
 
     @simple_debug
-    def entry_validate (self, widget, *args):
+    def _entry_validate(self, widget, *args):
         val = widget.get_value()
         self.add_value(widget.x, widget.y, val)
         if self.grid.check_for_completeness():
             self.emit('puzzle-finished')
 
-    def complain_conflicts (self, x, y, value):
+    def _complain_conflicts(self, x, y, value):
         '''set error highlights on [x, y] and all related box.
 
         We think the error is caused by `value`. But the box at [x, y] could
@@ -456,7 +456,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
         try:
             self.grid.add(x, y, val, True)
         except sudoku.ConflictError, err:
-            self.complain_conflicts(err.x, err.y, err.value)
+            self._complain_conflicts(err.x, err.y, err.value)
         # Draw our entry
         self.__entries__[(x, y)].queue_draw()
 
@@ -469,9 +469,9 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
         e = self.__entries__[(x, y)]
         if do_removal and self.grid and self.grid._get_(x, y):
             self.grid.remove(x, y)
-        self.remove_error_highlight(x, y)
+        self._remove_error_highlight(x, y)
         # remove trackers
-        for t in self.trackers_for_point(x, y):
+        for t in self._trackers_for_point(x, y):
             remove = []
             for crumb in self.trackers[t]:
                 if crumb[0] == x and crumb[1] == y:
@@ -482,7 +482,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
             e.set_value(0)
         e.unset_color()
 
-    def remove_error_highlight (self, x, y):
+    def _remove_error_highlight(self, x, y):
         '''remove error highlight from [x, y] and also all errors caused by it'''
         if self.__error_pairs__.has_key((x, y)):
             entry = self.__entries__[(x, y)]
@@ -510,6 +510,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
             self.emit('puzzle-finished')
         return retval
 
+
     @simple_debug
     def auto_fill_current_entry (self):
         e = self.focused
@@ -521,7 +522,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
             e.set_text_interactive(str(filled[1]))
 
     @simple_debug
-    def mark_impossible_implications (self, x, y):
+    def _mark_impossible_implications(self, x, y):
         if not self.grid:
             return
         implications = self.grid.find_impossible_implications(x, y)
@@ -544,7 +545,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
         self.trackers[identifier] = []
         return identifier
 
-    def trackers_for_point (self, x, y, val = None):
+    def _trackers_for_point(self, x, y, val = None):
         if val:
             # if we have a value we can do this a simpler way...
             track_for_point = filter(
@@ -581,7 +582,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
         ret = []
         while self.trackers[identifier]:
             x, y, v = self.trackers[identifier][0]
-            ret.append((x, y, v, self.trackers_for_point(x, y, v)))
+            ret.append((x, y, v, self._trackers_for_point(x, y, v)))
             self.remove(x, y)
             if self.grid and self.grid._get_(x, y):
                 self.grid.remove(x, y)
@@ -597,7 +598,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
                     and (x, y, val) not in tracks
                     and not self.grid.virgin._get_(x, y)
                     ):
-                    removed.append((x, y, val, self.trackers_for_point(x, y, val)))
+                    removed.append((x, y, val, self._trackers_for_point(x, y, val)))
                     self.remove(x, y)
                     if self.grid and self.grid._get_(x, y):
                         self.grid.remove(x, y)



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