def refresh_board(self): """Refresh the contents of the grid.""" if not self.grid: log('No grid found during board refresh', log.LOGDEBUG) return self.position_marker.setImage( get_image("shadow_%s.png" % self.next_player_name)) self.update_messages() self.update_labels() self.update_comment() # refresh all points for x in xrange(self.game.get_size()): for y in xrange(self.game.get_size()): pos = (x, y) if pos in self.marks: self.grid[x][y].mark('mark') elif pos in self.triangles: self.grid[x][y].mark('triangle') elif pos in self.squares: self.grid[x][y].mark('square') elif pos in self.circles: self.grid[x][y].mark('circle') elif pos in self.marks: self.grid[x][y].mark('mark') else: self.grid[x][y].mark() self.grid[x][y].set_player(self.board.board[x][y]) self.mark_hints()
def onInit(self): log('initialising') # get controls self.grid_control = self.getControl(ControlIds.grid) self.next_control = self.getControl(ControlIds.next_problem) self.solution_control = self.getControl(ControlIds.solution) self.clock = self.getControl(ControlIds.clock) self.clock_thread = thread.start_new_thread(self.clock_ticker, tuple()) # init the grid self.grid = self.get_grid()
def update_comment(self, comment=None): """Set the comment to the given comment, or the current SGF comment. If no comment is provided, the comment of the current SGF node will be displayed. :param str or None comment: the comment to be displayed """ if not self.comments_box: log('No comments box found during comment refresh', log.LOGDEBUG) return if comment is None: comment = self.current_comment.replace('FORCE', '').replace('RIGHT', '') # noqa self.comments_box.setText(comment)
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 handle(self, action, focused): """Handle the given action. :param xbmcgui,Action action: the action :param int focused: the id of the focused button :returns: whether the action was handled, or None if nothing was done """ # if a different control is focused, move the current tile # to the left most one, so that it will get rolled over when # control returns to the grid if focused != self.control.getId(): self.current = self.grid[self.current.x][0] return False self.control.controlRight(self.control) try: action_id = action.getId() if action_id in DIRECTIONS: self.select(self.current.next(action_id)) return True else: return self.handle_key(action_id) except KeyError as e: log(str(e))