Implemented opening a puzzle
authorHarishankar <v.harishankar@gmail.com>
Wed, 8 Dec 2010 08:15:39 +0000 (13:45 +0530)
committerHarishankar <v.harishankar@gmail.com>
Wed, 8 Dec 2010 08:15:39 +0000 (13:45 +0530)
Implemented the open puzzle dialog. Also implemented confirmation
dialog whether really to quit or not on window closing event if
a puzzle is open.

crosswordpuzzlecreator.py
player_mainwindow.py
playerwindow.glade

index 4ffffb3..334895d 100644 (file)
@@ -148,7 +148,8 @@ class CrosswordPuzzleCreator:
                        sys.stdout.write (self.BLUE + "Across word at position: " + aword + "\n" + self.ENDCOL)
                        clue = raw_input (self.BRICKRED + "Clue for across word: " + self.ENDCOL)
                        self.puzzle.data[arow][acol].clue_across = clue
                        sys.stdout.write (self.BLUE + "Across word at position: " + aword + "\n" + self.ENDCOL)
                        clue = raw_input (self.BRICKRED + "Clue for across word: " + self.ENDCOL)
                        self.puzzle.data[arow][acol].clue_across = clue
-                       sys.stdout.write (self.BLUE + "Set the clue: \n" + self.puzzle.data[arow][acol].clue_across)
+                       sys.stdout.write (self.BLUE + "Set the clue: \n" +
+                                                               self.puzzle.data[arow][acol].clue_across + "\n")
                except crosswordpuzzle.NoWordException:
                        sys.stderr.write ("No across word found at that position\n")
 
                except crosswordpuzzle.NoWordException:
                        sys.stderr.write ("No across word found at that position\n")
 
@@ -158,7 +159,8 @@ class CrosswordPuzzleCreator:
                        sys.stdout.write (self.BLUE + "Down word at position: " + dword + "\n" + self.ENDCOL)
                        clue = raw_input (self.BRICKRED + "Clue for down word: " + self.ENDCOL)
                        self.puzzle.data[drow][dcol].clue_down = clue
                        sys.stdout.write (self.BLUE + "Down word at position: " + dword + "\n" + self.ENDCOL)
                        clue = raw_input (self.BRICKRED + "Clue for down word: " + self.ENDCOL)
                        self.puzzle.data[drow][dcol].clue_down = clue
-                       sys.stdout.write (self.BLUE + "Set the clue: \n" + self.puzzle.data[drow][dcol].clue_down)
+                       sys.stdout.write (self.BLUE + "Set the clue: \n" +
+                                                               self.puzzle.data[drow][dcol].clue_down + "\n")
                except crosswordpuzzle.NoWordException:
                        sys.stderr.write ("No down word found at that position\n")
 
                except crosswordpuzzle.NoWordException:
                        sys.stderr.write ("No down word found at that position\n")
 
index 8ee60a7..7aa3af7 100644 (file)
@@ -17,11 +17,20 @@ class MainWindow:
        ACROSS = 1
        DOWN = 2
 
        ACROSS = 1
        DOWN = 2
 
-       def gtk_main_quit (self, *args):
-               gtk.main_quit ()
+       # callback for menu item open activated event
+       def on_open_activate (self, menuitem):
+               dlg = gtk.FileChooserDialog ("Open a GetAClue puzzle", self.window,
+                               gtk.FILE_CHOOSER_ACTION_OPEN,
+                       (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
 
 
-       # callback for menu item quit activated event
-       def on_quit_activate (self, menuitem):
+               if dlg.run () == gtk.RESPONSE_OK:
+                       puzzlefile = dlg.get_filename ()
+                       self.open_file (puzzlefile)
+
+               dlg.destroy ()
+
+       # quit verification
+       def verify_quit (self):
                if self.puzzle:
                        dlg = gtk.MessageDialog (self.window, gtk.DIALOG_MODAL,
                                        gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO,
                if self.puzzle:
                        dlg = gtk.MessageDialog (self.window, gtk.DIALOG_MODAL,
                                        gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO,
@@ -30,8 +39,28 @@ class MainWindow:
                                dlg.destroy ()
                                return False
                        dlg.destroy ()
                                dlg.destroy ()
                                return False
                        dlg.destroy ()
+               return True
+
 
 
-               self.gtk_main_quit ()
+       # callback for main window destroy
+       def on_mainwindow_destroy (self, args):
+               gtk.main_quit ()
+
+
+       # callback for window closing dialog
+       def on_mainwindow_delete_event (self, window, event):
+               # verify whether really to quit or not if a puzzle is open
+               v = self.verify_quit ()
+               # return False for deleting and True for not deleting
+               return not v
+
+       # callback for menu item quit activated event
+       def on_quit_activate (self, menuitem):
+               # verify whether really to quit or not if a puzzle is open
+               v = self.verify_quit ()
+               # if verified, then quit
+               if v is True:
+                       self.window.destroy ()
 
        # callback for menu item clear grid activated event
        def on_cleargrid_activate (self, menuitem):
 
        # callback for menu item clear grid activated event
        def on_cleargrid_activate (self, menuitem):
index cde1419..83639ba 100644 (file)
@@ -25,7 +25,8 @@
     <property name="title" translatable="yes">GetAClue player</property>
     <property name="default_width">640</property>
     <property name="default_height">480</property>
     <property name="title" translatable="yes">GetAClue player</property>
     <property name="default_width">640</property>
     <property name="default_height">480</property>
-    <signal name="destroy" handler="gtk_main_quit"/>
+    <signal name="destroy" handler="on_mainwindow_destroy"/>
+    <signal name="delete_event" handler="on_mainwindow_delete_event"/>
     <child>
       <object class="GtkVBox" id="vbox1">
         <property name="visible">True</property>
     <child>
       <object class="GtkVBox" id="vbox1">
         <property name="visible">True</property>
@@ -47,6 +48,7 @@
                         <property name="visible">True</property>
                         <property name="label" translatable="yes">Open...</property>
                         <property name="use_underline">True</property>
                         <property name="visible">True</property>
                         <property name="label" translatable="yes">Open...</property>
                         <property name="use_underline">True</property>
+                        <signal name="activate" handler="on_open_activate"/>
                       </object>
                     </child>
                     <child>
                       </object>
                     </child>
                     <child>