Menu

#2616 Quit menu cannot be overridden

obsolete: 8.6b1.1
closed-works-for-me
5
2009-04-08
2009-04-08
No

The standard Quit menu item that appears in the application menu of Aqua Tcl/Tk applications on MacOS X appears to be hard-wired to do something (stop the mainloop?). This presents a real problem when the application needs special behavior to quit.

My specific problem is that I have a Python/Tkinter application that uses the Twisted networking library. Twisted takes over the tcl/tk event loop in a way that is transparent to tcl/tk, but a nasty side effect is that the Quit menu item has absolutely no effect!!! If I could bind to something to catch the menu item it would be fine, but I've not figured out a binding that works. The root window is not closed, so catching destroy from the window manager is not an option.

Please offer some way to modify the behavior of the Quit menu item for MacOS X Aqua Tcl/Tk applications. Or some way to hide that menu item so I can add my own.

(Note: the problem does not occur on unix and Windows because they don't automatically add a Quit menu item. I have to set my own so I can make it do whatever I like).

Discussion

  • Russell Owen

    Russell Owen - 2009-04-08

    Just after posting this Kevin Walzer provided an answer. The Quit menu on MacOS X calls the tcl "exit" function. One can easily intercept this in Python/Tkinter using createcommand, e.g.:

    root.createcommand('exit', myQuitFunction)

    It is a pity that a special technique is required (instead of treating Quit like any other menu item), but it certainly an easy trick.

     
  • Daniel A. Steffen

    This is already available, if the tcl proc '::tk::mac::Quit' is defined, it gets called instead of exit upon receipt of a 'quit' apple event (which is what the standard quit menu item sends, as well as other entities in the system such as the dock menu quit item or the graceful Finder restart/shutdown, this is why the quit menu item is special).
    If ::tk::mac::Quit returns false, the application is not quit.

    other default apple event handlers are also defined, c.f. tkMacOSXHLEvent.c

    please ask on tcl-mac if there are further questions about this.

     
  • Daniel A. Steffen

    • milestone: --> obsolete: 8.6b1.1
    • status: open --> closed-works-for-me