I have almost finished my Ubuntu App Showdown app, but would like to make it somewhat more robust, upon application quit I iterate through the open files checking for unsaved files, if any are found I pop up a dialog informing the user.
What I would like to happen is that if the user cancels the dialog the program resumes, if however the user clicks ok, both dialog and main window should close.
This is what I have so far.
self.connect("delete-event", self.CheckSave)
def CheckSave(self, arg1, arg2):
unsaved = False
for doc in self.Documents:
if doc.Saved == False:
unsaved = True
if unsaved:
print("Unsaved document")
Dialog = Gtk.Dialog("Really quit?", 0, Gtk.DialogFlags.MODAL)
Dialog.add_button(Gtk.STOCK_NO, Gtk.ResponseType.CANCEL)
Dialog.add_button(Gtk.STOCK_YES, Gtk.ResponseType.OK)
box = Dialog.get_content_area()
label1 = Gtk.Label("There are unsaved file(s).")
label2 = Gtk.Label("Are you sure you want to quit?")
box.add(label1)
box.add(label2)
box.show_all()
response = Dialog.run()
print(response)
if response == Gtk.ResponseType.OK:
return(False)
else:
return(True)
Dialog.destroy()
When the dialog runs it never output's the ResponseType.OK or ResponseType.CANCEL values, I get random negative numbers such as -4 or -6, the dialog also never closes and the main window keeps emitting dialog and requires a CTRL+c to quit it.