ACROSS = 1
DOWN = 2
+ # quit verification
+ def verify_quit (self):
+ if self.puzzle:
+ dlg = gtk.MessageDialog (self.window, gtk.DIALOG_MODAL,
+ gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO,
+ "Puzzle is open. Are you sure you wish to quit?")
+ if dlg.run () <> gtk.RESPONSE_YES:
+ dlg.destroy ()
+ return False
+ dlg.destroy ()
+ return True
+
# callback for menu item open activated event
def on_open_activate (self, menuitem):
dlg = gtk.FileChooserDialog ("Open a GetAClue puzzle", self.window,
dlg.destroy ()
- # quit verification
- def verify_quit (self):
+ # callback for menu item save as activated event
+ def on_save_as_activate (self, menuitem):
if self.puzzle:
- dlg = gtk.MessageDialog (self.window, gtk.DIALOG_MODAL,
- gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO,
- "Puzzle is open. Are you sure you wish to quit?")
- if dlg.run () <> gtk.RESPONSE_YES:
- dlg.destroy ()
- return False
- dlg.destroy ()
- return True
+ dlg = gtk.FileChooserDialog ("Save GetAClue puzzle as", self.window,
+ gtk.FILE_CHOOSER_ACTION_SAVE,
+ (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE,
+ gtk.RESPONSE_OK))
+ if dlg.run () == gtk.RESPONSE_OK:
+ puzzlefile = dlg.get_filename ()
+ self.save_file (puzzlefile)
+ dlg.destroy ()
# callback for main window destroy
def on_mainwindow_destroy (self, args):
down.append ([ str(self.puzzle.data[word[1]][word[2]].numbered),
clue])
+ def save_file (self, file):
+ # try to save the file
+ try:
+ cPickle.dump (self.puzzle, open (file, "wb"), cPickle.HIGHEST_PROTOCOL)
+ except (IOError, OSError, cPickle.PicklingError):
+ dlg = gtk.MessageDialog (self.window, gtk.DIALOG_MODAL,
+ gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
+ "Error in saving puzzle")
+ dlg.run ()
+ dlg.destroy ()
+
+ # open a file
def open_file (self, file):
# try to open the file
try: