wxTimer problem
abcd
codecraig at gmail.com
Fri Sep 15 15:47:30 EDT 2006
I have a python script which creates a wx.App, which creates a wx.Frame
(which has a wx.Timer).
looks sorta like this:
class MyProgram:
def __init__(self):
self.app = MyApp(0)
self.app.MainLoop()
class MyApp(wx.App):
def OnInit(self):
self.myframe= MyFrame()
self.myframe.Show(True)
self.SetTopWindow(self.myframe)
return True
class MyFrame(wx.Frame):
def __init__(self):
# do some other stuff here
# setup the timer
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
self.timer.Start(100)
def killTimer(self):
self.Unbind(wx.EVT_TIMER)
self.timer.Stop()
self.timer = None
....that's the jist of it.
Anyhow, so I startup python and import my script, which loads up the
wx.App, frame and all.
foo = MyProgram()
Then I close the frame. when the frame is closed it calls killTimer.
This method gets called and no exceptions occur.
Then...I create a new instance of the app and try to load the frame
again.
foo = MyProgram()
...and I am getting this error:
"timer can only be started from the main thread"
how can I fix this??
FYI, my script is being started by a new thread each time, so
ultimately we have....
def startProgram():
foo = MyProgram()
threading.Thread(target=startProgram).start()
Thanks in advance.
More information about the Python-list
mailing list