[wxPython-users] Re: wxProgressDialog problems

Robin Dunn robin at alldunn.com
Mon Feb 25 10:42:54 PST 2008


Larry Bates wrote:
> Robin Dunn wrote:
>> Larry Bates wrote:
>>> Robin Dunn wrote:
>>>> Larry Bates wrote:
>>
>>>>> Thoughts?
>>>>
>>>> Do the other code in a thread, and make the callback use 
>>>> wx.CallAfter or post an event so the update of the progress dialog 
>>>> can be done in the gui thread.  If the cancel button was pressed 
>>>> then set a flag that the download thread will check periodically so 
>>>> it knows to stop (or send the message in some other thread-safe way).
>>>>
>>>>
>>> Real newbie here.  It sounds like this would be the best way:
>>>
>>>  > or post an event so the update of the progress dialog can be done in
>>>  > the gui thread.
>>>
>>> I "really" tried on this one, but it exhibits the same behavior.  
>>> Can't ever click on the Cancel button.  See sample code below.
>>>
>>> Thanks for all your help.
>>
>> You still are not calling the app's MainLoop method.  And you seem to 
>> have missed the "Do the other code in a thread" part of my comment.
>>
>>
> 
>  >>> Do the other code in a thread, and make the callback use wx.CallAfter
>  >>> or post an event so the update of the progress dialog can be done in
>  >>> the gui thread.
> 
> Sorry, I read your instructions as "Do in a thread and make callback or 
> post
> an event..." Note the OR.
> 
> I tried running my other code in a separate thread, but Python DAVLIB 
> refuses run in a separate thread and I'm not up to a complete rewrite of 
> that code at the present.
> 
> I tried running the MainLoop in another thread, but it makes no difference.

To use wx in an alternate thread you need to do almost everything 
wx-related from that thread, essentially anything that interacts with 
the UI, including creating or modifying the app and window objects.  It 
is safe to use wx.PostEvent or wx.CallAfter from the non-gui thread in 
order to pass messages or to invoke other functions in the context of 
the gui thread.

Also, in your case you'll either need to create a top-level window, or 
call app.SetExitOnFrameDelete(False), otherwise the MainLoop will exit 
immediately since there are not any top-level windows existing at the 
time it is called.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list