The best way to do this (after considerable experience trying
different ways is):
* Define a custom event, with a progress field
* Use the threading module to start a new thread
* Use the event as your interface to the GUI, i.e,
in the window with the progress bar, do an EVT_PROGRESS
to catch the event.
* Then update the progress bar in the event handler.
I'd be happy to post some code if you have any more problems. In
general with threads, you should always use the event mechanism.
Using gui mutex locks get very messy, and is only appropriate for
quick and dirty work. It's also nice to define your events like
this:
class wxMyEvent (wxPyEvent):
def __init__ (self, **kwargs):
wxPyEvent.__init__ (self)
self.SetEventType (...)
self.myfield = kwargs['myfield']
def toHash (self):
return { 'myfield' : self.myfield }
with all your events. That way, for example, if your event
notification ends, you can easily create a new event for the
notifcation using the similar kwargs interface. Example:
my_evt = ref_to_event
kwargs = my_evt.toHash ()
kwargs.update ({ 'other_opts' : 'some val' })
other_evt = wxOtherEvent (**kwargs)
That way, it's easy to chain events and event contents. Hope
that helps.
-- Mike
···
On Fri, Nov 15 @ 16:35, Antoon Pardon wrote:
On Fri, Nov 15, 2002 at 07:07:06AM -0700, Tim Hochberg wrote:
> > Is the wxThread usefull or should I stick to thread?
> >
> > Are there any particular advantages to using thread
> > or wxThread or threading (which seems to be another
> > possibility from the python libarary)?
>
> Use threading, not thread. Threading is the higher level interface to thread
> and is easier to use. Also, look at the Queue module. It's generally the
> easiest way to pass events between threads without having to worry too much
> about race conditions and deadlocks and whatnot.
But for sending information to the Window handler shouldn't I
stick to wxPostEvent? The Queue module seems very handy if
you have to synchronize multiple calculations or if you want
to communicate from the GUI thread to the others, but I have
the idea that in the specific case of sending something to
the GUI-thread I should make use of events. Am I missing
something?
--
Antoon Pardon
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
--
Michael Gilfix
mgilfix@eecs.tufts.edu
For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html