[wxPython-users] Re: threading
Josiah Carlson
jcarlson at uci.edu
Tue Mar 20 11:03:17 PDT 2007
Christian <ckkart at hoc.net> wrote:
> import wx
> from wx.grid import Grid,PyGridTableBase
> from wx.lib.evtmgr import eventManager as em
Is there a particular reason why you are using eventManager?
> from threading import Thread
>
> class Dummy:
> def run(self):
> for i in range(1000000):
> float(i)**2
> return 'finished'
>
> RESULT = wx.NewEventType()
> EVT_RESULT = wx.PyEventBinder(RESULT, 1)
>
> class ResultEvent(wx.PyCommandEvent):
> eventType = RESULT
> def __init__(self, windowID, msg):
> wx.PyCommandEvent.__init__(self, self.eventType, windowID)
> self.msg = msg
>
> def Clone( self ):
> self.__class__( self.GetId() )
Replace the above event stuff with:
import
wx.lib.newevent
ResultEvent, EVT_RESULT = wx.lib.newevent.NewCommandEvent()
> class WorkerThread(Thread):
> """Worker Thread Class."""
> def __init__(self, notify, fitter):
> """Init Worker Thread Class."""
[snip]
> event = ResultEvent(self._notify.GetId(), msg)
> self._notify.GetEventHandler().ProcessEvent(event)
Replace that last line with:
wx.PostEvent(self._notify, event)
> class TestFrame(wx.Frame):
> def __init__(self):
> wx.Frame.__init__(self, None, -1 ,'testing')
[snip]
> em.Register(self.fertig, EVT_RESULT, self)
Replace the em.Register(...) line with...
self.Bind(EVT_RESULT, self.fertig)
[snip]
Those changes make it work for me on linux.
- Josiah
More information about the wxpython-users
mailing list