> Once every 50ms, which I think is not that frequent.
Actually this is probably a bit aggressive I would think.
Aggressive? That is only 20 fps.
> Unless you have any idea about how to make the timer events have
> higher priority, I'd be interested to read about wx.Yield. I couldn't
> find any explanation about it.
I still think that the main problem is your blocking the main thread
with your updates but... If you want to try it you can make your own
thread timer class using the threading and time modules and see if
that does anything different.
i.e) use something like this to replace wx.Timer
import threading
import time
class ThreadTimer(threading.Thread):
def __init__(self, parent)
self.parent = parent
self.continue = False
self.interval = 0
def run(self):
while continue:
time.sleep(self.interval)
event = MyCustomTimerEvent(...)
wx.PostEvent(self.parent, event)
def Start(self, interval):
self.interval = interval
self.start()
def Stop(self):
self.continue = False
Cody
Works great! I edited it and now my background function gets called
consistently even when the GUI is very busy.
Here's my edited version:
#threadtimer.py
import threading
import time
import wx
wxEVT_THREAD_TIMER = wx.NewEventType()
EVT_THREAD_TIMER = wx.PyEventBinder(wxEVT_THREAD_TIMER, 1)
class ThreadTimer(object):
def __init__(self, parent):
self.parent = parent
self.thread = Thread()
self.thread.parent = self
self.alive = False
def start(self, interval):
self.interval = interval
self.alive = True
self.thread.start()
def stop(self):
self.alive = False
class Thread(threading.Thread):
def run(self):
while self.parent.alive:
time.sleep(self.parent.interval / 1000.0)
event = wx.PyEvent()
event.SetEventType(wxEVT_THREAD_TIMER)
wx.PostEvent(self.parent.parent, event)
Thanks!
Now I have another problem. This one happened before this new
ThreadTimer, and still happens now. When my GUI is busy, and I press
the X button to close the window, it doesn't close it. Only when the
GUI stop working (because the simulation playback has finished) does
the application quit.
Any idea what to do?
Ram.