Skip to content

Commit

Permalink
IDLE: Tweak iomenu.IOBinding.maybesave (pythonGH-112914)
Browse files Browse the repository at this point in the history
Add docstring, use f-string, simplify code.
(cherry picked from commit ca1bde8)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
  • Loading branch information
terryjreedy authored and miss-islington committed Dec 10, 2023
1 parent 8c51e40 commit 2590bbf
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Lib/idlelib/iomenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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
Expand Down Expand Up @@ -180,24 +180,25 @@ def loadfile(self, filename):
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

Expand Down

0 comments on commit 2590bbf

Please sign in to comment.