mirror of https://github.com/python/cpython.git
[3.11] IDLE: Tweak iomenu.IOBinding.maybesave (GH-112914) (#112918)
Add docstring, use f-string, simplify code.
(cherry picked from commit ca1bde8943
)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
parent
8c51e4030a
commit
671f3d3ccd
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
from tkinter import filedialog
|
from tkinter import filedialog
|
||||||
from tkinter import messagebox
|
from tkinter import messagebox
|
||||||
from tkinter.simpledialog import askstring
|
from tkinter.simpledialog import askstring # loadfile encoding.
|
||||||
|
|
||||||
from idlelib.config import idleConf
|
from idlelib.config import idleConf
|
||||||
from idlelib.util import py_extensions
|
from idlelib.util import py_extensions
|
||||||
|
@ -180,24 +180,25 @@ def loadfile(self, filename):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def maybesave(self):
|
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():
|
if self.get_saved():
|
||||||
return "yes"
|
return "yes"
|
||||||
message = "Do you want to save %s before closing?" % (
|
message = ("Do you want to save "
|
||||||
self.filename or "this untitled document")
|
f"{self.filename or 'this untitled document'}"
|
||||||
|
" before closing?")
|
||||||
confirm = messagebox.askyesnocancel(
|
confirm = messagebox.askyesnocancel(
|
||||||
title="Save On Close",
|
title="Save On Close",
|
||||||
message=message,
|
message=message,
|
||||||
default=messagebox.YES,
|
default=messagebox.YES,
|
||||||
parent=self.text)
|
parent=self.text)
|
||||||
if confirm:
|
if confirm:
|
||||||
reply = "yes"
|
|
||||||
self.save(None)
|
self.save(None)
|
||||||
if not self.get_saved():
|
reply = "yes" if self.get_saved() else "cancel"
|
||||||
reply = "cancel"
|
else: reply = "cancel" if confirm is None else "no"
|
||||||
elif confirm is None:
|
|
||||||
reply = "cancel"
|
|
||||||
else:
|
|
||||||
reply = "no"
|
|
||||||
self.text.focus_set()
|
self.text.focus_set()
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue