[Idle-dev] Submitted Guilherme Polo's enhancement

Kevin Walzer kw at codebykevin.com
Fri Oct 15 14:17:34 CEST 2010

On 10/15/10 12:25 AM, Bruce Sherwood wrote:
> I'm trying to find out why when you quit on the Mac unsaved changes
> don't trigger an invitation to save the file. Instead, IDLE quits and
> you lose your edits.
> There is code to bind cmd-q to the edit window and, on the Mac, to the
> Tk root, through macosxSupport.setupApp which calls macosxSupport
> overrideRootMenu. I've tried printing something in the callback
> routine (FileList.close_all_callback), and I don't see the print. I've
> tried commenting out one or both of these bindings, and I can still
> quit with cmd-q. I've looked a bit at the tkinter code. I'm beginning
> to have the sinking feeling that there's something in the library
> _tkinter.so itself that is swallowing cmd-q and not sending it to
> tkinter, so it doesn't get to IDLE. I have the vague notion that there
> have been some problems with tkinter on the Mac, but I don't know any
> details....?
> Is there someone who reads this idle-dev list who knows enough about
> _tkinter.so on the Mac to be able to say whether this could be the
> problem? If _tkinter.so doesn't pass through to IDLE a cmd-q event (or
> the equivalent menu choice to quit), there's nothing we can do to make
> IDLE work properly on the Mac without changes to _tkinter.so. I don't
> feel competent to design a clean simple tkinter test to prove the
> point and post a bug report.

Tk on the Mac has a built in command called ::tk::mac::Quit, which 
corresponds to the "quit" Apple event. If this command is not defined, 
then I believe the default behavior for Tk on the Mac is to quit (when 
accessed from the menu--not sure about Command-Q). I think the right way 
to manage this in IDLE would be to do something like this:

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

This will map whatever function IDLE calls to prompt the user to save 
data before closing, to the Apple quit event.

(Sorry I don't have time to submit a patch, but hopefully this can point 
someone in the right direction.)


Kevin Walzer
Code by Kevin

More information about the IDLE-dev mailing list