[Pythonmac-SIG] app won't quit?

Chris Barker - NOAA Federal chris.barker at noaa.gov
Tue May 28 22:54:41 CEST 2013


On Tue, May 28, 2013 at 1:25 PM, Charles Hartman <cohar at conncoll.edu> wrote:
> My app has only one frame, so for me it's not an issue.

fair enough.

> With the code I showed, the app quits if I press cmd-Q, select Quit from the
> app menu, or close the only window.  That's fine—though I wouldn't mind if
> (like most Mac apps) if closing the only window did not quit the app.

see the references I gave earlier if you want to bother with that.

 What
> I don't want is for cmd-Q or Quit from the app menu to do nothing—which is
> what was happening before.

fair enough.. what did you have before? but this should do it:

    def OnClose(self,Event):
        self.Destroy()

that will destroy the Frame, which should make wx exit.

If you don't do that, you may need to call

OnClose
    Event.Skip()

to make sure that the Close event keeps going and does its thing. If
you had a handler for it, and did not either Destroy the frame or
callSkip(), ,that might explain the behavior you saw.

Anyway, I've never needed to explicitly end the MainLoop.

-CHB


-Chris




> Maybe there's something better to call, in my OnClose(), than
> wx.GetApp().ExitMainLoop(), but I haven't yet found anything that makes the
> Quit happen.
>
>
> On Tue, May 28, 2013 at 4:00 PM, Chris Barker - NOAA Federal
> <chris.barker at noaa.gov> wrote:
>>
>> On Tue, May 28, 2013 at 9:50 AM, Charles Hartman <cohar at conncoll.edu>
>> wrote:
>> \
>> > 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'm still confused as to why you need that call to ExitMainLoop....
>>
>> And why this gets you Mac behavior -- the usual Mac behavior is for
>> the App NOT to exit when all its Frames are closed.
>>
>> > for it (until I can test on a Windows machine) that it will also work
>> > cross-platform.
>>
>> note that on any platform, I think this will cause the closing of the
>> Frame to kill the App, whether or not there are other frames open --
>> if you app supports having more than one frame open at a time, you
>> probably don't want that.
>>
>>
>> > 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.
>>
>> This Wiki Page:
>>
>> http://wiki.wxpython.org/Optimizing%20for%20Mac%20OS%20X
>>
>> Perhaps the term "Optimizing" is a mistake in that title -- these
>> aren't really optimizations...
>>
>> (note the the ID_EXIT is there already, but not the call to MainLoop
>> (which I still don't quite get the need for..)
>>
>> -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



-- 

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


More information about the Pythonmac-SIG mailing list