gnome-games r7303 - in trunk/gnome-sudoku: . src/lib



Author: thinkle
Date: Sat Feb  2 17:42:24 2008
New Revision: 7303
URL: http://svn.gnome.org/viewvc/gnome-games?rev=7303&view=rev

Log:
2008-02-02  Thomas Hinkle  <tmhinkle gmail com>

	* src/lib/defaults.py.in (PUZZLE_DIR): Add PUZZLE_DIR parameter to
	point to where default starter puzzles are stored.
	* src/lib/sudoku_maker.py (SudokuMaker.load): Use PUZZLE_DIR from
	defaults to load puzzles (fixes in-place running of gnome-sudoku).
	(SudokuMaker.get_puzzles): Add parameter 'exclude' which is a list
	of puzzles not to include in results. This allows caller to exclude
	saved games (which SudokuMaker doesn't know about)
	* src/lib/game_selector.py (NewOrSavedGameSelector.make_new_game_model):
	Exclude saved games from list of new games.


Modified:
   trunk/gnome-sudoku/ChangeLog
   trunk/gnome-sudoku/src/lib/defaults.py.in
   trunk/gnome-sudoku/src/lib/gsudoku.py
   trunk/gnome-sudoku/src/lib/main.py

Modified: trunk/gnome-sudoku/src/lib/defaults.py.in
==============================================================================
--- trunk/gnome-sudoku/src/lib/defaults.py.in	(original)
+++ trunk/gnome-sudoku/src/lib/defaults.py.in	Sat Feb  2 17:42:24 2008
@@ -2,7 +2,12 @@
 import errno
 import gettext
 
-if sys.modules["gnome_sudoku"].installed_mode:
+if (sys.modules.has_key('gnome_sudoku') and
+    hasattr(sys.modules["gnome_sudoku"],'installed_mode') and
+    sys.modules["gnome_sudoku"].installed_mode):
+    # If the installed_mode attribute is not set, then we are
+    # importing from something other than the gnome-sudoku script; we
+    # assume anyone importing in this way is doing testing etc.
     APP_DATA_DIR = os.path.join('@prefix@', 'share') 
     IMAGE_DIR = os.path.join(APP_DATA_DIR, 'pixmaps', 'gnome-sudoku')
     LOCALEDIR = os.path.join(APP_DATA_DIR, 'locale')
@@ -15,7 +20,7 @@
     LOCALEDIR = os.path.join(APP_DATA_DIR, 'locale')
     GLADE_DIR = os.path.join('@abs_top_builddir@', 'gnome-sudoku', 'glade')
     BASE_DIR = os.path.join('@abs_top_builddir@', 'gnome-sudoku', 'data')
-    PUZZLE_DIR = BASE_DIR    
+    PUZZLE_DIR = BASE_DIR
 
 DOMAIN = 'gnome-games'
 gettext.bindtextdomain(DOMAIN, LOCALEDIR)

Modified: trunk/gnome-sudoku/src/lib/gsudoku.py
==============================================================================
--- trunk/gnome-sudoku/src/lib/gsudoku.py	(original)
+++ trunk/gnome-sudoku/src/lib/gsudoku.py	Sat Feb  2 17:42:24 2008
@@ -1272,6 +1272,120 @@
         if not val: val = self.grid._get_(x,y)
         self.trackers[tracker].remove((x,y,val))
 
+class GridDancer:
+
+    DANCE_COLORS = [colors.color_hex_to_float(hx) for hx in 
+                    [
+
+        '#cc0000', # red
+        '#ef2929',
+        '#f57900', # orange
+        '#fcaf3e',
+        #'#edd400', # yellow
+        '#fce94f',
+        '#8ae234', # green
+        '#73d216',
+        '#729fcf', # blue
+        '#3465a4',
+        '#ad7fa8', # violet
+        '#75507b', ]
+                    ]
+
+    STEPS_PER_ANIMATION = 18
+    
+    def __init__ (self, grid):
+        self.animations = [self.value_dance,
+                           self.box_dance,
+                           self.col_dance,
+                           self.row_dance,]
+        self.current_animation = self.value_dance
+        self.step = 0
+        self.grid = grid
+        self.dancing = False
+        for box in self.grid.__entries__.values():
+            box.read_only = False
+            box.queue_draw()
+
+    def start_dancing (self):
+        self.dancing = True
+        gobject.timeout_add(500,self.dance_grid)
+
+    def stop_dancing (self):
+        self.dancing = False
+        print 'unhighlight_cells'
+        self.grid.unhighlight_cells()
+
+    def do_dance_step (self):
+        self.grid.__entries__[(random.randint(0,8),
+                               random.randint(0,8))
+                              ].set_background_color(
+            random.choice(self.DANCE_COLORS)
+            )
+    
+    def rotate_animation (self):
+        ci = self.animations.index(self.current_animation)
+        if (ci+1) == len(self.animations):
+            ni = 0
+        else:
+            ni = ci + 1
+        self.current_animation = self.animations[ni]
+        self.step = 0
+
+    def dance_grid (self):
+        if not self.dancing: return
+        if self.step > self.STEPS_PER_ANIMATION:
+            self.rotate_animation()
+        if hasattr(self,'adjustment'):
+            self.adjustment += 1
+        else:
+            self.adjustment = 0
+        if self.adjustment >= 9: self.adjustment = 0
+        try:
+            self.current_animation()
+        except AttributeError:
+            return True
+        self.step += 1
+        if self.dancing:
+            return True
+
+    def col_dance (self):
+        for x in range(9):
+            n = (x + self.adjustment) % len(self.DANCE_COLORS)
+            color = self.DANCE_COLORS[n]
+            for y in range(9):
+                self.grid.__entries__[(x,y)].set_background_color(color)
+                
+    def row_dance (self):
+        for y in range(9):
+            n = (y + self.adjustment) % len(self.DANCE_COLORS)
+            color = self.DANCE_COLORS[n]
+            for x in range(9):
+                self.grid.__entries__[(x,y)].set_background_color(color)
+
+    def box_dance (self):
+        for box in range(9):
+            n = (box + self.adjustment) % len(self.DANCE_COLORS)
+            color = self.DANCE_COLORS[n]
+            for x,y in self.grid.grid.box_coords[box]:
+                self.grid.__entries__[(x,y)].set_background_color(color)
+        
+    def value_dance (self):
+        for value in range(10):
+            n = (value + self.adjustment) % len(self.DANCE_COLORS)
+            color = self.DANCE_COLORS[n]
+            for x in range(9):
+                for y in range(9):
+                    if self.grid.grid._get_(x,y)==value:
+                        self.grid.__entries__[(x,y)].set_background_color(color)
+
+def test_dance_grid (grid):
+    dancer = GridDancer(grid)
+    dancer.start_dancing()
+    def stop (*args): dancer.stop_dancing()
+    gobject.timeout_add(2000,stop)
+
+
+
 if __name__ == '__main__':
     def test_sng ():
         w = gtk.Window()
@@ -1303,6 +1417,7 @@
         w.connect('delete-event', gtk.main_quit)
         w.add(sgd)
         w.show_all()
+        test_dance_grid(sgd)
         gtk.main()
         
     def test_number_selector ():

Modified: trunk/gnome-sudoku/src/lib/main.py
==============================================================================
--- trunk/gnome-sudoku/src/lib/main.py	(original)
+++ trunk/gnome-sudoku/src/lib/main.py	Sat Feb  2 17:42:24 2008
@@ -470,6 +470,9 @@
             sublabel += ngettext("You used the auto-fill %(n)s time",
                                  "You used the auto-fill %(n)s times",
                                  self.gsd.auto_fills)%{'n':self.gsd.auto_fills}
+        from gsudoku import GridDancer
+        self.dancer = GridDancer(self.gsd)
+        self.dancer.start_dancing()            
         dialog_extras.show_message(_("You win!"),label=_("You win!"),
                                    #icon=os.path.join(IMAGE_DIR,'winner2.png'),
                                    sublabel=sublabel
@@ -483,7 +486,7 @@
         #hs.run_dialog()
         #self.main_actions.get_action('HighScores').set_sensitive(True)
         #self.gsd.blank_grid()
-        self.new_cb()
+        #self.new_cb()
 
     @simple_debug
     def initialize_prefs (self):
@@ -527,6 +530,9 @@
             self.do_stop()
             
     def do_stop (self):
+        if hasattr(self,'dancer'):
+            self.dancer.stop_dancing()
+            delattr(self,'dancer')
         self.gsd.grid = None
         self.tracker_ui.reset()
         self.timer.reset_timer()



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