[gnome-games/sudoku-tube] Change method to function



commit 033d7e332c124313da456503aaf245315d863988
Author: Zhang Sen <zh jesse gmail com>
Date:   Thu Jul 23 09:26:23 2009 +0800

    Change method to function

 gnome-sudoku/src/lib/tracker_box.py |  103 ++++++++++++++++++-----------------
 1 files changed, 53 insertions(+), 50 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/tracker_box.py b/gnome-sudoku/src/lib/tracker_box.py
index 434a29c..8f512ff 100644
--- a/gnome-sudoku/src/lib/tracker_box.py
+++ b/gnome-sudoku/src/lib/tracker_box.py
@@ -9,24 +9,59 @@ from gettext import gettext as _
 
 import defaults
 
-ICON_FACTORY = gtk.IconFactory()
 STOCK_PIXBUFS = {}
-for filename, stock_id in [('footprints.png', 'tracks'), ]:
-    try:
-        pb = gtk.gdk.pixbuf_new_from_file(os.path.join(defaults.IMAGE_DIR,
-            filename))
-    except gobject.GError, e:
-        print 'Failed to load pixbuf: %s' % e
-        continue
-    STOCK_PIXBUFS[stock_id] = pb
-    iconset = gtk.IconSet(pb)
-    ICON_FACTORY.add(stock_id, iconset)
-    ICON_FACTORY.add_default()
-
-gtk.stock_add([('tracks',
-                _('Track moves'),
-                0, 0, ""), ])
 
+def _add_tracker_stock_icon():
+    icon_factory = gtk.IconFactory()
+    for filename, stock_id in [('footprints.png', 'tracks'), ]:
+        try:
+            pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(defaults.IMAGE_DIR,
+                filename))
+        except gobject.GError, err:
+            print 'Failed to load pixbuf: %s' % err
+            continue
+        STOCK_PIXBUFS[stock_id] = pixbuf
+        iconset = gtk.IconSet(pixbuf)
+        icon_factory.add(stock_id, iconset)
+        icon_factory.add_default()
+
+    gtk.stock_add([('tracks',
+                    _('Track moves'),
+                    0, 0, ""), ])
+
+_add_tracker_stock_icon()
+
+TRACKER_COLORS = [
+    # Use tango colors recommended here:
+    # http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines
+    tuple([c / 255.0 for c in cols]) for cols in
+    [(32, 74, 135), # Sky Blue 3
+     (78, 154, 6), # Chameleon 3
+     (206, 92, 0), # Orange 3
+     (143, 89, 2), # Chocolate 3
+     (92, 53, 102), # Plum 3
+     (85, 87, 83), # Aluminium 5
+     (196, 160, 0), # Butter 3
+     ]
+    ]
+
+def _get_tracker_color(identifier):
+    try:
+        return TRACKER_COLORS[identifier]
+    except IndexError:
+        new_color = _generate_new_color()
+        TRACKER_COLORS.append(new_color)
+        return _get_tracker_color(identifier)
+
+def _generate_new_color():
+    random_color = TRACKER_COLORS[0]
+    while random_color in TRACKER_COLORS:
+        # If we have generated all possible colors, this will
+        # enter an infinite loop
+        random_color = (random.randint(0, 100)/100.0,
+                        random.randint(0, 100)/100.0,
+                        random.randint(0, 100)/100.0)
+    return random_color
 
 def _pixbuf_transform_color(pixbuf, color):
     """Return new pixbuf with color changed to color"""
@@ -110,7 +145,7 @@ class _TrackerBox (gtk.VBox):
         tracker_id = self._view_controller.create_tracker()
         pixbuf = _pixbuf_transform_color(
             STOCK_PIXBUFS['tracks'],
-            self._view_controller.get_tracker_color(tracker_id))
+            _get_tracker_color(tracker_id))
         # select our new tracker
         self.tracker_tree.get_selection().select_iter(
             self.tracker_model.append([tracker_id,
@@ -157,20 +192,6 @@ class Tracker:
     """The controller that really perform the changes on the SudokuView, e.g.
     set the color"""
 
-    TRACKER_COLORS = [
-        # Use tango colors recommended here:
-        # http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines
-        tuple([x / 255.0 for x in cols]) for cols in
-        [(32, 74, 135), # Sky Blue 3
-         (78, 154, 6), # Chameleon 3
-         (206, 92, 0), # Orange 3
-         (143, 89, 2), # Chocolate 3
-         (92, 53, 102), # Plum 3
-         (85, 87, 83), # Aluminium 5
-         (196, 160, 0), # Butter 3
-         ]
-        ]
-
     def __init__(self, sudoku_view):
         self._sudoku_view = sudoku_view
         self._trackers = {}
@@ -187,7 +208,7 @@ class Tracker:
                 self._add_to_tracker(tracker_id, x, y)
 
     def _add_to_tracker(self, tracker_id, x, y):
-        color = self.get_tracker_color(tracker_id)
+        color = _get_tracker_color(tracker_id)
         self._sudoku_view.set_color(x, y, color)
         self._trackers[tracker_id].append((x, y))
 
@@ -202,24 +223,6 @@ class Tracker:
         self._trackers[identifier] = []
         return identifier
 
-    def get_tracker_color(self, identifier):
-        try:
-            return self.TRACKER_COLORS[identifier]
-        except IndexError:
-            new_color = self._generate_new_color()
-            self.TRACKER_COLORS.append(new_color)
-            return self.get_tracker_color(identifier)
-
-    def _generate_new_color(self):
-        random_color = self.TRACKER_COLORS[0]
-        while random_color in self.TRACKER_COLORS:
-            # If we have generated all possible colors, this will
-            # enter an infinite loop
-            random_color = (random.randint(0, 100)/100.0,
-                            random.randint(0, 100)/100.0,
-                            random.randint(0, 100)/100.0)
-        return random_color
-
     def toggle_tracker(self, identifier, value):
         """Toggle tracking for tracker identified by identifier."""
         self.__trackers_tracking__[identifier] = value



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