This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Quitting IDLE on Mac doesn't save unsaved code
Type: behavior Stage: resolved
Components: IDLE, macOS Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ronaldoussoren Nosy List: Bruce.Sherwood, benjamin.peterson, georg.brandl, ned.deily, ronaldoussoren, taleinat, wordtech
Priority: critical Keywords: patch

Created on 2010-10-14 17:22 by Bruce.Sherwood, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue10107-py3k-31.patch ned.deily, 2010-10-26 06:11 patch for py3k and 31
issue10107-27.patch ned.deily, 2010-10-26 06:12 patch for 27
Messages (14)
msg118697 - (view) Author: Bruce Sherwood (Bruce.Sherwood) Date: 2010-10-14 17:22
It has just been discovered that at least since Python 2.6 on the Mac, quitting IDLE does not prompt to save unsaved code, which is then lost. The recently submitted diff for bringing Guilherme Polo's Google Summer of Code improvements into IDLE on Python 3 (ID 10079) does not fix the problem.
msg118739 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2010-10-15 05:36
The problem is that, by default on OS X, Tkinter uses Tk/Aqua which is itself a bona-fide OS X application and it creates the default menu options including a standard application quit.  Looks like IDLE needs to register a hook provided by Tk/Aqua for a "quit" callback.  (See http://permalink.gmane.org/gmane.comp.python.tkinter/1857).  I'm working on a patch for it.
msg118770 - (view) Author: Kevin Walzer (wordtech) * Date: 2010-10-15 13:33
Try something like this: 

root.createcommand('::tk::mac::Quit', <insert IDLE's shutdown function here>)

This will map whatever function IDLE calls to prompt the user to save data before closing, to the Apple quit event.
msg118776 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2010-10-15 14:08
Kevin, 

which versions of Tk does this work with?

IDLE should at least work with the versions of Tk 8.4 and 8.5 that Apple ships with OSX 10.4, 10.5 and 10.6 (the last one being the only one with built-in support for Tk 8.5)
msg118777 - (view) Author: Kevin Walzer (wordtech) * Date: 2010-10-15 14:12
Ronald--I think it works with both 8.4 and 8.5.
msg118792 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2010-10-15 16:08
Note that some discussion about this issue is taking place on the idle-dev mailing list.

Bruce Sherwood found the line "root.bind('<<close-all-windows>>', flist.close_all_callback)", which seems to be an unsuccessful attempt to achieve the wanted behavior.

Kevin Walzer mentioned that a grep on the idlelib code doesn't turn up any references to "tk::mac::Quit".

I don't have access to OSX for testing. Could someone please replace the root.bind call with what Kevin suggested, and see if it solves the problem?
msg118801 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2010-10-15 16:53
It looks like the '::tk::mac::Quit' callback does not exist in the Apple-supplied Tk 8.4.7 in OS X 10.5 and 10.4, although it does work with the Apple-supplied Tk 8.4.19(?) and 8.5 in 10.6 and with a current ActiveState 8.4.19 on 10.4 through 10.6.  However, instead of that, it looks like overriding the 'exit' callback will work fine on all of them.  In a simple test, I'm able to intercept the Tk app quitting, post a yes/no message, and then terminate the Tk app by destroying the root.  Next I'll try integrating into IDLE.
msg118855 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2010-10-16 03:58
Looks like the "exit" callback will work for IDLE but there are the usual edge cases and odd differences among the various branches and build options to work through and fix up.  Patch forthcoming.
msg119591 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2010-10-26 06:11
The attached patches implement an "exit" callback for IDLE on OS X that ensures IDLE will not terminate from an application Quit command without giving the opportunity to save files.
msg119592 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2010-10-26 06:21
BTW, the patched IDLEs were tested on 2.7 and py3k (3.2a3+) on 10.4, 10.5, and 10.6 with the Apple-supplied Tk 8.4 (all), the Apple-supplied Tk 8.5 (available only in 10.6), ActiveState Tk 8.4 (all), and ActiveState 8.5 (all).  And the patches have no affect nor are needed when linked with an X11-based Tk on OS X.
msg122553 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2010-11-27 20:47
Considering the discussion on the idle-dev list back in October about this issue, I think this low-risk, high-benefit fix should be going into all three upcoming releases.
msg123551 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2010-12-07 14:14
Ned: why does the patch change the signature of close_all_callback?

-    def close_all_callback(self, event):
+    def close_all_callback(self, *args, **kwds):
msg123557 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2010-12-07 15:28
Ned: never mind the command callback has a different signature than a keybinding.

Committed the patch for 3.2 in r87119.
msg123560 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2010-12-07 16:04
Merged to 3.1.x in r87120, merged to 2.7. in r87121.

Ned: thanks for looking into this, doubly so because Tk-on-OSX is involved.
History
Date User Action Args
2022-04-11 14:57:07adminsetgithub: 54316
2010-12-07 16:04:35ronaldoussorensetstatus: open -> closed
resolution: fixed
messages: + msg123560

stage: patch review -> resolved
2010-12-07 15:28:30ronaldoussorensetmessages: + msg123557
2010-12-07 14:14:15ronaldoussorensetmessages: + msg123551
2010-11-27 20:47:13ned.deilysetpriority: high -> critical
nosy: + georg.brandl, benjamin.peterson
messages: + msg122553

2010-10-26 06:21:24ned.deilysetmessages: + msg119592
2010-10-26 06:12:09ned.deilysetfiles: + issue10107-27.patch
2010-10-26 06:11:21ned.deilysetfiles: + issue10107-py3k-31.patch
priority: normal -> high

components: + macOS
assignee: ned.deily -> ronaldoussoren
keywords: + patch
nosy: ronaldoussoren, taleinat, wordtech, ned.deily, Bruce.Sherwood
messages: + msg119591
stage: needs patch -> patch review
2010-10-16 03:58:16ned.deilysetmessages: + msg118855
2010-10-15 16:53:25ned.deilysetmessages: + msg118801
2010-10-15 16:08:59taleinatsetmessages: + msg118792
2010-10-15 14:12:12wordtechsetmessages: + msg118777
2010-10-15 14:08:59ronaldoussorensetmessages: + msg118776
2010-10-15 13:33:55wordtechsetnosy: + wordtech
messages: + msg118770
2010-10-15 10:11:32ronaldoussorensetnosy: + ronaldoussoren
2010-10-15 05:36:23ned.deilysetassignee: ned.deily
messages: + msg118739
2010-10-14 22:24:06brian.curtinsetnosy: + taleinat
2010-10-14 22:11:57ned.deilysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2010-10-14 22:11:33ned.deilysetnosy: + ned.deily

stage: needs patch
2010-10-14 17:22:45Bruce.Sherwoodcreate