Пример #1
0
 def show_info_cb (self, *args):
     if not self.gsd.grid:
         dialog_extras.show_message(parent = self.w,
                                    title = _("Puzzle Information"),
                                    label = _("There is no current puzzle.")
                                    )
         return
     puzzle = self.gsd.grid.virgin.to_string()
     diff = self.sudoku_maker.get_difficulty(puzzle)
     information = _("Calculated difficulty: ")
     information += diff.value_string()
     information += " (%1.2f)" % diff.value
     information += "\n"
     information += _("Number of moves instantly fillable by elimination: ")
     information += str(int(diff.instant_elimination_fillable))
     information += "\n"
     information += _("Number of moves instantly fillable by filling: ")
     information += str(int(diff.instant_fill_fillable))
     information += "\n"
     information += _("Amount of trial-and-error required to solve: ")
     information += str(len(diff.guesses))
     dialog_extras.show_message(parent = self.w,
                                title = _("Puzzle Statistics"),
                                label = _("Puzzle Statistics"),
                                sublabel = information)
Пример #2
0
 def show_info_cb (self, *args):
     if not self.gsd.grid:
         dialog_extras.show_message(parent = self.w,
                                    title = _("Puzzle Information"),
                                    label = _("There is no current puzzle.")
                                    )
         return
     puzzle = self.gsd.grid.virgin.to_string()
     diff = self.sudoku_maker.get_difficulty(puzzle)
     information = _("Calculated difficulty: ")
     information += diff.value_string()
     information += " (%1.2f)" % diff.value
     information += "\n"
     information += _("Number of moves instantly fillable by elimination: ")
     information += str(int(diff.instant_elimination_fillable))
     information += "\n"
     information += _("Number of moves instantly fillable by filling: ")
     information += str(int(diff.instant_fill_fillable))
     information += "\n"
     information += _("Amount of trial-and-error required to solve: ")
     information += str(len(diff.guesses))
     dialog_extras.show_message(parent = self.w,
                                title = _("Puzzle Statistics"),
                                label = _("Puzzle Statistics"),
                                sublabel = information)
Пример #3
0
 def you_win_callback (self, grid):
     if hasattr(self, 'dancer'):
         return
     self.won = True
     # increase difficulty for next time.
     self.mateconf['difficulty'] = self.mateconf['difficulty'] + 0.1
     self.timer.finish_timing()
     self.sudoku_tracker.finish_game(self)
     sublabel = _("You completed the puzzle in %(totalTime)s (%(activeTime)s active)") % {'totalTime': self.timer.total_time_string(),
     'activeTime': self.timer.active_time_string()
             }
     sublabel += "\n"
     sublabel += ngettext("You got %(n)s hint", "You got %(n)s hints", self.gsd.hints) % {'n':self.gsd.hints}
     sublabel += "\n"
     if self.gsd.impossible_hints:
         sublabel += ngettext("You had %(n)s impossibility pointed out.",
                              "You had %(n)s impossibilities pointed out.",
                              self.gsd.impossible_hints) % {'n':self.gsd.impossible_hints}
         sublabel += "\n"
     if self.gsd.auto_fills:
         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}
     import dancer
     self.dancer = dancer.GridDancer(self.gsd)
     self.dancer.start_dancing()
     dialog_extras.show_message(_("You win!"), label = _("You win!"),
                                sublabel = sublabel
                                )
Пример #4
0
 def you_win_callback (self, grid):
     if hasattr(self, 'dancer'):
         return
     self.won = True
     # increase difficulty for next time.
     self.gconf['difficulty'] = self.gconf['difficulty'] + 0.1
     self.timer.finish_timing()
     self.sudoku_tracker.finish_game(self)
     sublabel = _("You completed the puzzle in %(totalTime)s (%(activeTime)s active)") % {'totalTime': self.timer.total_time_string(),
     'activeTime': self.timer.active_time_string()
             }
     sublabel += "\n"
     sublabel += ngettext("You got %(n)s hint", "You got %(n)s hints", self.gsd.hints) % {'n':self.gsd.hints}
     sublabel += "\n"
     if self.gsd.impossible_hints:
         sublabel += ngettext("You had %(n)s impossibility pointed out.",
                              "You had %(n)s impossibilities pointed out.",
                              self.gsd.impossible_hints) % {'n':self.gsd.impossible_hints}
         sublabel += "\n"
     if self.gsd.auto_fills:
         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}
     import dancer
     self.dancer = dancer.GridDancer(self.gsd)
     self.dancer.start_dancing()
     dialog_extras.show_message(_("You win!"), label = _("You win!"),
                                sublabel = sublabel
                                )
Пример #5
0
 def save_game(self, ui):
     jar = jar_game(ui)
     filename = os.path.join(self.save_path, self.get_filename(jar['game']))
     try:
         outfi = file(filename, 'w')
         pickle.dump(jar, outfi)
         outfi.close()
     except (OSError, IOError), e:
         show_message(
             title=_('Sudoku unable to save game.'),
             label=_('Sudoku unable to save game.'),
             message_type=gtk.MESSAGE_ERROR,
             sublabel=(_('Unable to save file %(filename)s.') % locals() +
                       '\n' + _('Error %(errno)s: %(error)s') % {
                           'errno': e.errno,
                           'error': e.strerror
                       }))
Пример #6
0
 def finish_jar(self, jar):
     self.remove_from_saved_games(jar)
     try:
         filename = os.path.join(self.finished_path,
                                 self.get_filename(jar['game']))
         outfi = file(filename, 'w')
         pickle.dump(jar, outfi)
         outfi.close()
     except (OSError, IOError), e:
         show_message(
             title=_('Sudoku unable to mark game as finished.'),
             label=_('Sudoku unable to mark game as finished.'),
             message_type=gtk.MESSAGE_ERROR,
             sublabel=(_('Unable to save file %(filename)s.') % locals() +
                       '\n' + _('Error %(errno)s: %(error)s') % {
                           'errno': e.errno,
                           'error': e.strerror
                       }))
Пример #7
0
 def finish_jar (self, jar):
     self.remove_from_saved_games(jar)
     try:
         filename = os.path.join(self.finished_path,
                                 self.get_filename(jar['game']))
         outfi = file(filename, 'w')
         pickle.dump(jar, outfi)
         outfi.close()
     except (OSError, IOError), e:
         show_message(
             title = _('Sudoku unable to mark game as finished.'),
             label = _('Sudoku unable to mark game as finished.'),
             message_type = gtk.MESSAGE_ERROR,
             sublabel = (_('Unable to save file %(filename)s.') % locals() + '\n' +
                       _('Error %(errno)s: %(error)s') % {
             'errno':e.errno,
             'error':e.strerror
             })
             )
Пример #8
0
 def save_game (self, ui):
     jar = jar_game(ui)
     filename = os.path.join(self.save_path, self.get_filename(jar['game']))
     try:
         outfi = file(filename, 'w')
         pickle.dump(jar, outfi)
         outfi.close()
     except (OSError, IOError), e:
         show_message(
             title = _('Sudoku unable to save game.'),
             label = _('Sudoku unable to save game.'),
             message_type = gtk.MESSAGE_ERROR,
             sublabel = (_('Unable to save file %(filename)s.') % locals()
                       + '\n' +
                       _('Error %(errno)s: %(error)s') % {
             'errno':e.errno,
             'error':e.strerror
             })
             )
Пример #9
0
 def create_dir_safely (self, path):
     if not os.path.exists(path):
         try:
             os.makedirs(path)
         except OSError, e:
             if e.errno == errno.ENOSPC:
                 show_message(
                     title=_('No Space'),
                     label=_('No space left on disk'),
                     message_type=gtk.MESSAGE_ERROR,
                     sublabel=_('Sudoku is unable to created data folder %(path)s.')%locals() +\
                              _('There is no disk space left!')
                     )
             else:
                 show_message(
                     title='Error creating directory',
                     label='Error creating directory',
                     sublabel=_('Sudoku was unable to create data folder %(path)s.')%locals() +\
                     _('Error %(errno)s: %(error)s')%{'errno':e.errno,
                                                      'error':e.strerror}
                     )
Пример #10
0
 def create_dir_safely(self, path):
     if not os.path.exists(path):
         try:
             os.makedirs(path)
         except OSError, e:
             if e.errno == errno.ENOSPC:
                 show_message(
                     title = _('No Space'),
                     label = _('No space left on disk'),
                     message_type = gtk.MESSAGE_ERROR,
                     sublabel = _('Unable to create data folder %(path)s.') % locals() + '\n' + \
                                _('There is no disk space left!')
                     )
             else:
                 show_message(
                     title='Error creating directory',
                     label='Error creating directory',
                     sublabel=(_('Unable to create data folder %(path)s.') %
                               locals() + '\n' +
                               _('Error %(errno)s: %(error)s') % {
                                   'errno': e.errno,
                                   'error': e.strerror
                               }))
Пример #11
0
                          '\n' + _('Error %(errno)s: %(error)s') % {
                              'errno': e.errno,
                              'error': e.strerror
                          }))
        try:
            filename = list_of_finished_games = os.path.join(
                os.path.join(defaults.DATA_DIR, 'puzzles'), 'finished')
            ofi = open(list_of_finished_games, 'a')
            ofi.write(jar['game'].split('\n')[0] + '\n')
            ofi.close()
        except (OSError, IOError), e:
            show_message(
                title=_('Sudoku unable to mark game as finished.'),
                label=_('Sudoku unable to mark game as finished.'),
                message_type=gtk.MESSAGE_ERROR,
                sublabel=(_('Unable to save file %(filename)s.') % locals() +
                          '\n' + _('Error %(errno)s: %(error)s') % {
                              'errno': e.errno,
                              'error': e.strerror
                          }))

    def remove_from_saved_games(self, jar):
        previously_saved_game = os.path.join(self.save_path,
                                             self.get_filename(jar['game']))
        if os.path.exists(previously_saved_game):
            os.remove(os.path.join(previously_saved_game))

    def abandon_game(self, ui):
        jar = jar_game(ui)
        self.remove_from_saved_games(jar)
Пример #12
0
                'error':e.strerror
                })
                )
        try:
            filename = list_of_finished_games = os.path.join(
                os.path.join(defaults.DATA_DIR, 'puzzles'), 'finished'
                )
            ofi = open(list_of_finished_games, 'a')
            ofi.write(jar['game'].split('\n')[0]+'\n')
            ofi.close()
        except (OSError, IOError), e:
            show_message(
                title = _('Sudoku unable to mark game as finished.'),
                label = _('Sudoku unable to mark game as finished.'),
                message_type = gtk.MESSAGE_ERROR,
                sublabel = (_('Unable to save file %(filename)s.') % locals() + '\n' +
                          _('Error %(errno)s: %(error)s') % {
                'errno':e.errno,
                'error':e.strerror
                })
                )

    def remove_from_saved_games (self, jar):
        previously_saved_game = os.path.join(
            self.save_path, self.get_filename(jar['game'])
            )
        if os.path.exists(previously_saved_game):
            os.remove(os.path.join(previously_saved_game))

    def abandon_game (self, ui):
        jar  = jar_game(ui)
        self.remove_from_saved_games(jar)