gnome-games r8946 - trunk/gnome-sudoku/src/lib
- From: thomashpa svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r8946 - trunk/gnome-sudoku/src/lib
- Date: Sun, 29 Mar 2009 20:03:13 +0000 (UTC)
Author: thomashpa
Date: Sun Mar 29 20:03:13 2009
New Revision: 8946
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8946&view=rev
Log:
Move code for printing multiple sudokus to printing.py
Modified:
trunk/gnome-sudoku/src/lib/game_selector.py
trunk/gnome-sudoku/src/lib/main.py
trunk/gnome-sudoku/src/lib/printing.py
Modified: trunk/gnome-sudoku/src/lib/game_selector.py
==============================================================================
--- trunk/gnome-sudoku/src/lib/game_selector.py (original)
+++ trunk/gnome-sudoku/src/lib/game_selector.py Sun Mar 29 20:03:13 2009
@@ -225,91 +225,4 @@
else:
return None
-class GamePrinter (gconf_wrapper.GConfWrapper):
-
- glade_file = os.path.join(GLADE_DIR,'print_games.glade')
-
- initial_prefs = {'sudokus_per_page':2,
- 'print_multiple_sudokus_to_print':4,
- 'print_minimum_difficulty':0,
- 'print_maximum_difficulty':0.9,
- 'print_easy':True,
- 'print_medium':True,
- 'print_hard':True,
- 'print_very_hard':True,
- }
-
- def __init__ (self, sudoku_maker, gconf):
- gconf_wrapper.GConfWrapper.__init__(self,gconf)
- self.sudoku_maker = sudoku_maker
- self.glade = gtk.glade.XML(self.glade_file)
- # Set up toggles...
- for key,wname in [('mark_printed_as_played','markAsPlayedToggle'),
- ('print_already_played_games','includeOldGamesToggle'),
- ('print_easy','easyCheckButton'),
- ('print_medium','mediumCheckButton'),
- ('print_hard','hardCheckButton'),
- ('print_very_hard','very_hardCheckButton'),
- ]:
- setattr(self,wname,self.glade.get_widget(wname))
- try: assert(getattr(self,wname))
- except: raise AssertionError('Widget %s does not exist'%wname)
- self.gconf_wrap_toggle(key,getattr(self,wname))
- self.sudokusToPrintSpinButton = self.glade.get_widget('sudokusToPrintSpinButton')
- self.sudokusPerPageSpinButton = self.glade.get_widget('sudokusPerPageSpinButton')
- for key,widg in [('print_multiple_sudokus_to_print',self.sudokusToPrintSpinButton.get_adjustment()),
- ('sudokus_per_page',self.sudokusPerPageSpinButton.get_adjustment())
- ]:
- self.gconf_wrap_adjustment(key,widg)
- self.dialog = self.glade.get_widget('dialog')
- self.dialog.set_default_response(gtk.RESPONSE_OK)
- self.dialog.connect('response',self.response_cb)
-
- def response_cb (self, dialog, response):
- if response not in (gtk.RESPONSE_ACCEPT, gtk.RESPONSE_OK):
- self.dialog.hide()
- return
- # Otherwise, we're printing!
- levels = []
- for cat in DR.categories:
- if getattr(self,
- cat.replace(' ','_')+'CheckButton'
- ).get_active():
- levels.append(cat)
- if not levels:
- levels = DR.categories.keys()
- nsudokus = self.sudokusToPrintSpinButton.get_adjustment().get_value()
- sudokus = self.sudoku_maker.get_puzzles(
- nsudokus,
- levels,
- new=not self.includeOldGamesToggle.get_active()
- )
- # Convert floating point difficulty into a label string
- sudokus.sort(cmp=lambda a,b: cmp(a[1],b[1]))
- sudokus = [(sudoku.sudoku_grid_from_string(puzzle),
- "%s (%.2f)"%(sudoku.get_difficulty_category_name(d),d)
- ) for puzzle,d in sudokus]
- from printing import SudokuPrinter
- sp = SudokuPrinter(sudokus,
- self.dialog,
- sudokus_per_page=self.sudokusPerPageSpinButton.get_adjustment().get_value())
-
- self.sudokus_printed = sudokus
- response = sp.print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, sp.main_window)
-
- if response == gtk.PRINT_OPERATION_RESULT_ERROR:
- pass
- elif response == gtk.PRINT_OPERATION_RESULT_APPLY:
- if self.markAsPlayedToggle.get_active():
- for sud,lab in self.sudokus_printed:
- jar = {}
- jar['game']=sud.to_string()
- jar['printed']=True
- jar['printed_at']=time.time()
- tracker = saver.SudokuTracker()
- tracker.finish_jar(jar)
- self.dialog.hide()
-
- def run_dialog (self):
- self.dialog.show()
Modified: trunk/gnome-sudoku/src/lib/main.py
==============================================================================
--- trunk/gnome-sudoku/src/lib/main.py (original)
+++ trunk/gnome-sudoku/src/lib/main.py Sun Mar 29 20:03:13 2009
@@ -803,7 +803,7 @@
@simple_debug
def print_multiple_games (self, *args):
- gp=game_selector.GamePrinter(self.sudoku_maker, self.gconf)
+ gp=printing.GamePrinter(self.sudoku_maker, self.gconf)
gp.run_dialog()
@simple_debug
Modified: trunk/gnome-sudoku/src/lib/printing.py
==============================================================================
--- trunk/gnome-sudoku/src/lib/printing.py (original)
+++ trunk/gnome-sudoku/src/lib/printing.py Sun Mar 29 20:03:13 2009
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
import gtk, cairo
import sudoku, gsudoku
+from defaults import *
+from sudoku import DifficultyRating as DR
+from gtk_goodies import gconf_wrapper
from gettext import gettext as _
from gettext import ngettext
@@ -112,3 +115,92 @@
error_dialog.connect("response", lambda w,id: w.destroy())
error_dialog.show()
+class GamePrinter (gconf_wrapper.GConfWrapper):
+
+ glade_file = os.path.join(GLADE_DIR,'print_games.glade')
+
+ initial_prefs = {'sudokus_per_page':2,
+ 'print_multiple_sudokus_to_print':4,
+ 'print_minimum_difficulty':0,
+ 'print_maximum_difficulty':0.9,
+ 'print_easy':True,
+ 'print_medium':True,
+ 'print_hard':True,
+ 'print_very_hard':True,
+ }
+
+ def __init__ (self, sudoku_maker, gconf):
+ gconf_wrapper.GConfWrapper.__init__(self,gconf)
+ self.sudoku_maker = sudoku_maker
+ self.glade = gtk.glade.XML(self.glade_file)
+ # Set up toggles...
+ for key,wname in [('mark_printed_as_played','markAsPlayedToggle'),
+ ('print_already_played_games','includeOldGamesToggle'),
+ ('print_easy','easyCheckButton'),
+ ('print_medium','mediumCheckButton'),
+ ('print_hard','hardCheckButton'),
+ ('print_very_hard','very_hardCheckButton'),
+ ]:
+ setattr(self,wname,self.glade.get_widget(wname))
+ try: assert(getattr(self,wname))
+ except: raise AssertionError('Widget %s does not exist'%wname)
+ self.gconf_wrap_toggle(key,getattr(self,wname))
+ self.sudokusToPrintSpinButton = self.glade.get_widget('sudokusToPrintSpinButton')
+ self.sudokusPerPageSpinButton = self.glade.get_widget('sudokusPerPageSpinButton')
+ for key,widg in [('print_multiple_sudokus_to_print',self.sudokusToPrintSpinButton.get_adjustment()),
+ ('sudokus_per_page',self.sudokusPerPageSpinButton.get_adjustment())
+ ]:
+ self.gconf_wrap_adjustment(key,widg)
+ self.dialog = self.glade.get_widget('dialog')
+ self.dialog.set_default_response(gtk.RESPONSE_OK)
+ self.dialog.connect('response',self.response_cb)
+
+ def response_cb (self, dialog, response):
+ if response not in (gtk.RESPONSE_ACCEPT, gtk.RESPONSE_OK):
+ self.dialog.hide()
+ return
+ # Otherwise, we're printing!
+ levels = []
+ for cat in DR.categories:
+ if getattr(self,
+ cat.replace(' ','_')+'CheckButton'
+ ).get_active():
+ levels.append(cat)
+ if not levels:
+ levels = DR.categories.keys()
+ nsudokus = self.sudokusToPrintSpinButton.get_adjustment().get_value()
+ sudokus = self.sudoku_maker.get_puzzles(
+ nsudokus,
+ levels,
+ new=not self.includeOldGamesToggle.get_active()
+ )
+ # Convert floating point difficulty into a label string
+ sudokus.sort(cmp=lambda a,b: cmp(a[1],b[1]))
+ sudokus = [(sudoku.sudoku_grid_from_string(puzzle),
+ "%s (%.2f)"%(sudoku.get_difficulty_category_name(d),d)
+ ) for puzzle,d in sudokus]
+ from printing import SudokuPrinter
+ sp = SudokuPrinter(sudokus,
+ self.dialog,
+ sudokus_per_page=self.sudokusPerPageSpinButton.get_adjustment().get_value())
+
+ self.sudokus_printed = sudokus
+ response = sp.print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, sp.main_window)
+
+ if response == gtk.PRINT_OPERATION_RESULT_ERROR:
+ pass
+ elif response == gtk.PRINT_OPERATION_RESULT_APPLY:
+ if self.markAsPlayedToggle.get_active():
+ for sud,lab in self.sudokus_printed:
+ jar = {}
+ jar['game']=sud.to_string()
+ jar['printed']=True
+ jar['printed_at']=time.time()
+ tracker = saver.SudokuTracker()
+ tracker.finish_jar(jar)
+ self.dialog.hide()
+
+ def run_dialog (self):
+ self.dialog.show()
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]