From d7084b7094c99003960b33d4bd4fb655248c6ab3 Mon Sep 17 00:00:00 2001 From: Harishankar Date: Wed, 8 Dec 2010 10:09:28 +0530 Subject: [PATCH] Implemented the reveal/hide solution functionality Reveal/hiding the entire solution is now possible. Next question: should the solution be protected using a flag? --- crosswordpuzzle.py | 6 ++++++ player_mainwindow.py | 24 +++++++++++++++++++++++ playerwindow.glade | 46 ++++++++++++++++++++++++++++++++------------ 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/crosswordpuzzle.py b/crosswordpuzzle.py index 319a4fc..ffdd915 100644 --- a/crosswordpuzzle.py +++ b/crosswordpuzzle.py @@ -636,5 +636,11 @@ class CrosswordPuzzle: break r += 1 + # reveal/hide the entire solution by resetting revealed flag at all cells + def reveal_solution (self, revealed=True): + # run through the grid and set revealed to False + for row in range (self.rows): + for col in range (self.cols): + self.data[row][col].revealed = revealed diff --git a/player_mainwindow.py b/player_mainwindow.py index 89459ae..b384b54 100644 --- a/player_mainwindow.py +++ b/player_mainwindow.py @@ -33,6 +33,30 @@ class MainWindow: self.gtk_main_quit () + # callback for menu item hide solution activated event + def on_hidesolution_activate (self, menuitem): + if self.puzzle: + # hide the solution + self.puzzle.reveal_solution (False) + puzgrid = self.ui.get_object ("puzzlegrid") + # redraw the grid + puzgrid.queue_draw () + + # callback for menu item reveal solution activated event + def on_revealsolution_activate (self, menuitem): + if self.puzzle: + # confirm first + dlg = gtk.MessageDialog (self.window, gtk.DIALOG_MODAL, + gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, + "This will reveal all words in the puzzle! Are you sure?") + if dlg.run () == gtk.RESPONSE_YES: + # reveal the solution + self.puzzle.reveal_solution () + # redraw the grid + puzgrid = self.ui.get_object ("puzzlegrid") + puzgrid.queue_draw () + dlg.destroy () + # callback for menu item reveal word activated event def on_revealword_activate (self, menuitem): if self.puzzle: diff --git a/playerwindow.glade b/playerwindow.glade index f8e9afe..500f359 100644 --- a/playerwindow.glade +++ b/playerwindow.glade @@ -73,6 +73,33 @@ + + + True + _Puzzle + True + + + True + True + + + True + _Verify your board... + True + + + + + True + _Clear all... + True + + + + + + True @@ -91,29 +118,24 @@ - + True - Reveal _solution... - True - + True - _Hide solution + Reveal _solution... True + - - True - - - - + True - _Verify your board... + _Hide solution True + -- 2.20.1