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) *  |
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) *  |
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) *  |
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('<>', 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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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. |
|
|