- last_occupied_col = self.selected_col
- while True:
- self.selected_col += step
- if self.selected_col < 0 or self.selected_col >= self.puzzle.cols:
- self.selected_col = last_occupied_col
- break
- if (self.puzzle.data[self.selected_row][self.selected_col].occupied_across is True
- or self.puzzle.data[self.selected_row][self.selected_col].occupied_down is True):
- break
+ if self.puzzle:
+ last_occupied_col = self.selected_col
+ while True:
+ self.selected_col += step
+ if self.selected_col < 0 or self.selected_col >= self.puzzle.cols:
+ self.selected_col = last_occupied_col
+ break
+ if (self.puzzle.data[self.selected_row][self.selected_col].occupied_across is True
+ or self.puzzle.data[self.selected_row][self.selected_col].occupied_down is True):
+ break
+
+ # set the guessed character in the grid at selected location and move the
+ # selection across or down as the case may be
+ def set_guess (self, guess_char):
+ if self.puzzle:
+ self.puzzle.data[self.selected_row][self.selected_col].guess = guess_char.upper ()
+ # across mode typing
+ if self.typing_mode == self.ACROSS:
+ # move by one character across but only if there is no block
+ # in between
+ old_col = self.selected_col
+ self.move_selection_across (1)
+ if abs (self.selected_col - old_col) > 1:
+ self.selected_col = old_col
+ # down mode typing
+ else:
+ # move by one character down but only if there is no block
+ # in between
+ old_row = self.selected_row
+ self.move_selection_updown (1)
+ if abs (self.selected_row - old_row) > 1:
+ self.selected_row = old_row
+
+ # delete the guessed char in the previous row/col depending on the input mode
+ # If input mode is ACROSS then delete guessed char at previous column else
+ # at previous row
+ def delete_prev_guess (self):
+ if self.puzzle:
+ if self.typing_mode == self.ACROSS:
+ # prevent deleting characters when there is a gap
+ old_sel_col = self.selected_col
+ self.move_selection_across (-1)
+ # only if there is no block inbetween delete
+ if abs (self.selected_col - old_sel_col) <= 1:
+ self.puzzle.data[self.selected_row][self.selected_col].guess = None
+ # reset selection
+ else:
+ self.selected_col = old_sel_col