X-Git-Url: https://harishankar.org/repos/?p=getaclue.git;a=blobdiff_plain;f=player_mainwindow.py;fp=player_mainwindow.py;h=89459ae4114f35cb7afa20c235d9269cc3ec7bbd;hp=3d528cce0afcbf5a11a216f8388939f3dedfc29f;hb=1f9de52c4798a22293aaf2c32611090a099d0ce4;hpb=0ab1dc52c24addeb82930f4d7013eaf5c178149e diff --git a/player_mainwindow.py b/player_mainwindow.py index 3d528cc..89459ae 100644 --- a/player_mainwindow.py +++ b/player_mainwindow.py @@ -33,6 +33,33 @@ class MainWindow: self.gtk_main_quit () + # callback for menu item reveal word activated event + def on_revealword_activate (self, menuitem): + if self.puzzle: + # reveal across/down word if any the position + if self.puzzle.data[self.selected_row][self.selected_col].occupied_across is True: + dlg = gtk.MessageDialog (self.window, gtk.DIALOG_MODAL, + gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, + "Are you sure you wish to reveal across word at current cell?") + # confirm that the user wants to reveal + if dlg.run () == gtk.RESPONSE_YES: + self.puzzle.reveal_word_across (self.selected_row, self.selected_col) + # redraw the grid to reveal the word + puzgrid = self.ui.get_object ("puzzlegrid") + puzgrid.queue_draw () + dlg.destroy () + if self.puzzle.data[self.selected_row][self.selected_col].occupied_down is True: + dlg = gtk.MessageDialog (self.window, gtk.DIALOG_MODAL, + gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, + "Are you sure wish to reveal down word at current cell?") + if dlg.run () == gtk.RESPONSE_YES: + self.puzzle.reveal_word_down (self.selected_row, self.selected_col) + # redraw the grid to reveal the word + puzgrid = self.ui.get_object ("puzzlegrid") + puzgrid.queue_draw () + dlg.destroy () + + # function to set the selected row/col based on the number clicked # on the clues list and also set the typing mode def set_selection_of_num (self, num, across = True): @@ -112,23 +139,25 @@ class MainWindow: # 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 + # set a guess only if not revealed + if self.puzzle.data[self.selected_row][self.selected_col].revealed is False: + 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 @@ -214,7 +243,7 @@ class MainWindow: # if it is backspace key then delete character at previous row/col # depending on the input mode. If across editing mode, then delete # at previous column else at previous row - elif key == "BackSpace": + elif key == "backspace": self.delete_prev_guess () drawarea.queue_draw () @@ -290,6 +319,17 @@ class MainWindow: ctx.move_to (col*30+10, row*30+20) ctx.show_text (self.puzzle.data[row][col].guess) + # if there is a revealed solution character at the location + if (self.puzzle.data[row][col].revealed is True and + (self.puzzle.data[row][col].occupied_across is True + or self.puzzle.data[row][col].occupied_down is True)): + ctx.set_source_rgb (0, 0, 0.8) + ctx.select_font_face ("Serif", cairo.FONT_SLANT_NORMAL, + cairo.FONT_WEIGHT_BOLD) + ctx.set_font_size (16) + ctx.move_to (col*30+10, row*30+20) + ctx.show_text (self.puzzle.data[row][col].char) + return False # load clues to the list