From: Harishankar Date: Wed, 8 Dec 2010 08:15:39 +0000 (+0530) Subject: Implemented opening a puzzle X-Git-Url: https://harishankar.org/repos/?a=commitdiff_plain;h=d1205cd99dbf7d06180235c19dda876c3cd53563;p=getaclue.git Implemented opening a puzzle Implemented the open puzzle dialog. Also implemented confirmation dialog whether really to quit or not on window closing event if a puzzle is open. --- diff --git a/crosswordpuzzlecreator.py b/crosswordpuzzlecreator.py index 4ffffb3..334895d 100644 --- a/crosswordpuzzlecreator.py +++ b/crosswordpuzzlecreator.py @@ -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 + "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") @@ -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 + "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") diff --git a/player_mainwindow.py b/player_mainwindow.py index 8ee60a7..7aa3af7 100644 --- a/player_mainwindow.py +++ b/player_mainwindow.py @@ -17,11 +17,20 @@ class MainWindow: 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, @@ -30,8 +39,28 @@ class MainWindow: 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): diff --git a/playerwindow.glade b/playerwindow.glade index cde1419..83639ba 100644 --- a/playerwindow.glade +++ b/playerwindow.glade @@ -25,7 +25,8 @@ GetAClue player 640 480 - + + True @@ -47,6 +48,7 @@ True Open... True +