Re: Bug in wxPython? MessageDialog.ShowModal() returning always zero on OS X

Kevin Ollivier <[email protected]>
Newsgroups gmane.comp.python.wxpython.devel
Message-ID <[email protected]>
On May 13, 2015, at 8:21 AM, Robin Dunn <[email protected]> wrote:

> Jari Nevala wrote:
>> Hi,
>> 
>> I noticed recently that when a MessageDialog is created in a thread and
>> its ShowModal() is called, it always returns 0 on OS X. This is an
>> error, because it should return the wx.ID of the button pressed. On
>> Windows this does not happen.
>> 
>> When the MessageDialog is created in the main thread, the ShowModal()
>> returns correct value on OS X and PC.
>> 
>> The Mac I used to reproduce this problem is Macbook Air with OS X
>> version 10.9.5. wxPython version is 3.0.2.0. My PC is running Windowsx
>> 8.1 and also has wxPython 3.0.2.0 installed.
>> 
>> Below is code to reproduce the problem. See the comments.
>> Code also available in pastebin: http://pastebin.com/QbNkw5gz
>> 
>> So is this a bug in wxPython?
> 
> It's a known issue, but it only happens with stock dialogs shown before the MainLoop starts.  So the easy fix is to just move that code to a method and use wx.CallAfter or wx.CallLater in OnInit to invoke it right after the MainLoop starts processing events.

Also, it's important to note that Cocoa, and GUI libraries in general, are not thread-safe. On Mac there is a further restriction that the GUI must be started from the app's main thread. So the best practice is that you start the main loop in the main thread, and any time you want to call GUI code from a thread, as you do in the testThread method, you need to use wx.CallAfter or wx.CallLater to run the GUI code to ensure it runs in the main thread.

Regards,

Kevin

> -- 
> Robin Dunn
> Software Craftsman
> http://wxPython.org
> 
> -- 
> You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.