From 2ea634d618f306cfc1663d9a5548c8307b6cf56a Mon Sep 17 00:00:00 2001 From: Jakob Cornell Date: Mon, 6 Jan 2020 20:30:23 -0600 Subject: [PATCH] Use more friendly exit confirm dialogs --- main.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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) -- 2.30.2