def next(self): """Load the next problem. If no problem can be loaded, an error message is displayed. """ # loop over problems until a good one is found for problem in self.problems: self.problem = problem try: self.load(self.problem['sgf']) except (ValueError, IndexError): traceback.print_exc() else: self.current_rank.setText( _('current_rank') % self.problems.rank) if self.problem.get('rank'): rating = self.problem.get('rating') or 0 rank_value, rank = self.problem.get('rank') self.rating_box.setText( _('rating') % (rating, rank_value, rank)) else: self.rating_box.setText('') return else: level = self.problems.level ranks = map( lambda rank: '%d %s' % rank, map(self.problems.get_rank, [level + 3, level - 3]) ) self.comments_box.setText(_('no_problems_found') % tuple(ranks))
def onClick(self, control_id): if control_id == ControlIds.restart: self.restart_game() elif control_id == ControlIds.solution: self.solution_control.setLabel( _('hide_solution' if self.grid.toggle_hints() else 'show_solution') # noqa ) elif control_id == ControlIds.next_problem: self.solution_control.setLabel(_('show_solution')) self.grid.next()
def setup_labels(self): """Set up all status messages and the comments box.""" window = self.window self.current_rank = window.getControl(ControlIds.rank) self.rating_box = window.getControl(ControlIds.rating) self.comments_box = window.getControl(ControlIds.comments) self.error_control = window.getControl(ControlIds.error) self.success_control = window.getControl(ControlIds.success) self.success_control.setLabel(_('solved')) self.error_control.setLabel(_('off_path')) self.update_comment() self.update_messages()
def settings(self): """Display the setting dialog.""" dialog = xbmcgui.Dialog() problems_dir = dialog.browse( 0, _('get_problems_dir'), 'files', '', False, False, None ) if problems_dir: addon.setSetting('problems_dir', problems_dir) self.grid.load_problems(problems_dir) self.grid.next()
def onAction(self, action): """Handle the given action. If the action is not one that is to be handled, it will be passed on. """ try: action_id = action.getId() log(str(action_id)) if action_id == xbmcgui.ACTION_QUEUE_ITEM: return self.exit() elif self.grid.handle(action, self.getFocusId()): return elif action_id in INFO: self.settings() elif action.getButtonCode() == KeyCodes.n: self.solution_control.setLabel(_('show_solution')) self.grid.next() except Exception: traceback.print_exc() super(Game, self).onAction(action)
def exit(self): dialog = xbmcgui.Dialog() confirmed = dialog.yesno(_('exit_head'), _('exit_text')) if confirmed: self.grid.remove_controls(self) self.close()
def restart_game(self): self.solution_control.setLabel(_('show_solution')) self.grid.load(self.grid.sgf) self.grid.problem_solved(False) self.grid.update_messages()