Implemented the reveal/hide solution functionality
authorHarishankar <v.harishankar@gmail.com>
Wed, 8 Dec 2010 04:39:28 +0000 (10:09 +0530)
committerHarishankar <v.harishankar@gmail.com>
Wed, 8 Dec 2010 04:39:28 +0000 (10:09 +0530)
Reveal/hiding the entire solution is now possible.
Next question: should the solution be protected using a flag?

crosswordpuzzle.py
player_mainwindow.py
playerwindow.glade

index 319a4fc..ffdd915 100644 (file)
@@ -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
 
 
index 89459ae..b384b54 100644 (file)
@@ -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:
index f8e9afe..500f359 100644 (file)
                 </child>
               </object>
             </child>
+            <child>
+              <object class="GtkMenuItem" id="puzzle">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Puzzle</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu4">
+                    <property name="visible">True</property>
+                    <property name="ubuntu_local">True</property>
+                    <child>
+                      <object class="GtkMenuItem" id="verify">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">_Verify your board...</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkMenuItem" id="cleargrid">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">_Clear all...</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
             <child>
               <object class="GtkMenuItem" id="view">
                 <property name="visible">True</property>
                       </object>
                     </child>
                     <child>
-                      <object class="GtkMenuItem" id="revealsolution">
+                      <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
                         <property name="visible">True</property>
-                        <property name="label" translatable="yes">Reveal _solution...</property>
-                        <property name="use_underline">True</property>
                       </object>
                     </child>
                     <child>
-                      <object class="GtkMenuItem" id="hidesolution">
+                      <object class="GtkMenuItem" id="revealsolution">
                         <property name="visible">True</property>
-                        <property name="label" translatable="yes">_Hide solution</property>
+                        <property name="label" translatable="yes">Reveal _solution...</property>
                         <property name="use_underline">True</property>
+                        <signal name="activate" handler="on_revealsolution_activate"/>
                       </object>
                     </child>
                     <child>
-                      <object class="GtkSeparatorMenuItem" id="sep2">
-                        <property name="visible">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="verify">
+                      <object class="GtkMenuItem" id="hidesolution">
                         <property name="visible">True</property>
-                        <property name="label" translatable="yes">_Verify your board...</property>
+                        <property name="label" translatable="yes">_Hide solution</property>
                         <property name="use_underline">True</property>
+                        <signal name="activate" handler="on_hidesolution_activate"/>
                       </object>
                     </child>
                   </object>