From: Jakob Cornell Date: Tue, 7 Jan 2020 02:30:23 +0000 (-0600) Subject: Use more friendly exit confirm dialogs X-Git-Url: https://jcornell.net/gitweb/gitweb.cgi?a=commitdiff_plain;h=2ea634d618f306cfc1663d9a5548c8307b6cf56a;p=tutoring-tool.git Use more friendly exit confirm dialogs --- diff --git a/main.py b/main.py index 41448c1..389a781 100644 --- a/main.py +++ b/main.py @@ -182,11 +182,13 @@ class MainView(View): def on_close(): if self.editor_views: next(iter(self.editor_views.values())).root.lift() - elif ( - not self.controller.dirty - or messagebox.askokcancel("Confirm", "You have unsaved changes. Quit anyway?") - ): - self.controller.save_state() + elif self.controller.dirty: + result = messagebox.askyesnocancel("Confirm", "You have unsaved changes. Save before exiting?") + if result is True: + self.controller.save_state() + if result is not None: + self.root.destroy() + else: self.root.destroy() self.root.protocol('WM_DELETE_WINDOW', on_close) @@ -388,8 +390,13 @@ class DataEditView(View): self.parent_view = parent_view def on_close(): - do = not self.dirty or messagebox.askokcancel("Confirm", "Discard changes?") - if do: + if self.dirty: + result = messagebox.askyesnocancel("Confirm", "Save data before closing?") + if result is True: + on_ok() + elif result is False: + self.finish() + else: self.finish() self.root = tk.Toplevel(parent) self.root.resizable(False, False)