[Pythonmac-SIG] app won't quit?
Charles Hartman
cohar at conncoll.edu
Tue May 28 18:50:20 CEST 2013
Chris, brilliant! Many thanks!
I included these lines in the __init__ for my app's Frame (or rather, in a
long SetupGUI method that is called by __init__):
item = self.fileMenu.Append(wx.ID_EXIT,'E&xit','Terminate the
program')
self.Bind(wx.EVT_MENU, self.OnClose, item)
Then farther down in the Frame code I have this method:
def OnClose(self, item):
wx.GetApp().ExitMainLoop()
That gets exactly the behavior Mac users are used to. I'll take your word
for it (until I can test on a Windows machine) that it will also work
cross-platform.
Should this be posted somewhere where newbies (like me again) who are
trying to combine Mac, Python, and wxPython can find it? It is *certainly* not
obvious.
On Tue, May 28, 2013 at 12:23 PM, Chris Barker - NOAA Federal <
chris.barker at noaa.gov> wrote:
> On Tue, May 28, 2013 at 9:11 AM, Charles Hartman <cohar at conncoll.edu>
> wrote:
> > Thanks, Chris. My app has a wx.Frame (subclassed, of course). It's
> there
> > that I've tried Binding EVT_CLOSE, but a breakpoint in the method I find
> is
> > never reached at all, including when I use menu or keyboard to Quit. On
> way
> > I've tried is this snippet I got from wxPyWiki. (The line that purports
> to
> > add an Exit item to the File menu does not in fact do that. Mac still
> keeps
> > Quit in the MyApp menu.)
>
> right -- wx tries hard to make you app more Mac-like by moving menu
> items around. If a menu item has ID ID_EXIT, it will get moved, maybe
> also if it is called "exit" or "quit". But you want that, yes?
>
> > item = self.fileMenu.Append(-1,'E&xit','Terminate the program')
> > self.Bind(wx.EVT_MENU, self.OnClose, item)
> > if wx.Platform=="__WXMAC__":
> > wx.App.SetMacExitMenuItemId(item.GetId())
> >
> > This doesn't work either; OnClose() is never reached.
>
> This is odd, but a few pointers. Try:
>
> item = self.fileMenu.Append(ex.ID_EXIT,'E&xit','Terminate the
> program')
> self.Bind(wx.EVT_MENU, self.OnClose, item)
> ## this shouldn't be needed if you use the ID above.
> > if wx.Platform=="__WXMAC__":
> > wx.App.SetMacExitMenuItemId(item.GetId())
>
> I think you're going to need to put together a sample app. The
> enclosed works. (I'd like to add the multiple-frame, app stays alive
> thing, though...)
>
> Oh, and you may want to try the "Widget Inspection Tool" -- it may
> show you something.
>
> -Chris
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
>
> Chris.Barker at noaa.gov
>
--
Charles O. Hartman
Poet in Residence
Lucy Marsh Haskell '19 Professor of Literatures in English
oak.conncoll.edu/cohar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20130528/f49f0950/attachment.html>
More information about the Pythonmac-SIG
mailing list