diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2023-12-10 02:29:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-10 02:29:40 (GMT) |
commit | ca1bde894305a1b88fdbb191426547f35b7e9200 (patch) | |
tree | 812640d7048ab6410679c2e69f5ae77e548cc4f2 /Lib/idlelib/iomenu.py | |
parent | 23df46a1dde82bc5a51578d9443024cf85827b95 (diff) | |
download | cpython-ca1bde894305a1b88fdbb191426547f35b7e9200.zip cpython-ca1bde894305a1b88fdbb191426547f35b7e9200.tar.gz cpython-ca1bde894305a1b88fdbb191426547f35b7e9200.tar.bz2 |
IDLE: Tweak iomenu.IOBinding.maybesave (#112914)
Add docstring, use f-string, simplify code.
Diffstat (limited to 'Lib/idlelib/iomenu.py')
-rw-r--r-- | Lib/idlelib/iomenu.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py index 667623e..464126e 100644 --- a/Lib/idlelib/iomenu.py +++ b/Lib/idlelib/iomenu.py @@ -7,7 +7,7 @@ import tokenize from tkinter import filedialog from tkinter import messagebox -from tkinter.simpledialog import askstring +from tkinter.simpledialog import askstring # loadfile encoding. from idlelib.config import idleConf from idlelib.util import py_extensions @@ -180,24 +180,25 @@ class IOBinding: return True def maybesave(self): + """Return 'yes', 'no', 'cancel' as appropriate. + + Tkinter messagebox.askyesnocancel converts these tk responses + to True, False, None. Convert back, as now expected elsewhere. + """ if self.get_saved(): return "yes" - message = "Do you want to save %s before closing?" % ( - self.filename or "this untitled document") + message = ("Do you want to save " + f"{self.filename or 'this untitled document'}" + " before closing?") confirm = messagebox.askyesnocancel( title="Save On Close", message=message, default=messagebox.YES, parent=self.text) if confirm: - reply = "yes" self.save(None) - if not self.get_saved(): - reply = "cancel" - elif confirm is None: - reply = "cancel" - else: - reply = "no" + reply = "yes" if self.get_saved() else "cancel" + else: reply = "cancel" if confirm is None else "no" self.text.focus_set() return reply |