def can_be_closed(self):
"""
This overrides :meth:`Tab.can_be_closed` in order to display a
save dialog.
If the file has been saved, this returns True and the tab is
closed normally. Otherwise this method asks the user whether the
file should be saved, and returns False only if the user cancels
something (and thus wants to keep working on this file).
"""
if self.is_saved():
return True
if self.path is None:
msg = "Do you want to save your changes?"
else:
msg = ("Do you want to save your changes to %s?"
% os.path.basename(self.path))
answer = messagebox.askyesnocancel("Close file", msg)
if answer is None:
# cancel
return False
if answer:
# yes
return self.save()
# no was clicked, can be closed
return True
# TODO: document the overriding
评论列表
文章目录