Adding support for preventing too much call to refresh flooding wx call stack while debugging
--- a/graphics/GraphicCommons.py Wed Feb 15 00:27:31 2012 +0100
+++ b/graphics/GraphicCommons.py Wed Feb 15 00:29:02 2012 +0100
@@ -27,6 +27,7 @@
from math import *
from types import *
import datetime
+from threading import Semaphore
#-------------------------------------------------------------------------------
# Common constants
@@ -304,6 +305,7 @@
self.DataConsumers = {}
self.LastRefreshTime = gettime()
+ self.RefreshLock = Semaphore()
self.RefreshTimer = wx.Timer(self, -1)
self.Bind(wx.EVT_TIMER, self.OnRefreshTimer, self.RefreshTimer)
@@ -327,9 +329,9 @@
return self.Debug
def Inhibit(self, inhibit):
- self.Inhibited = inhibit
for consumer, iec_path in self.DataConsumers.iteritems():
consumer.Inhibit(inhibit)
+ self.Inhibited = inhibit
def AddDataConsumer(self, iec_path, consumer):
if self.DataProducer is None:
@@ -368,23 +370,24 @@
self.RefreshNewData()
event.Skip()
- def NewDataAvailable(self):
+ def NewDataAvailable(self, *args, **kwargs):
self.RefreshTimer.Stop()
if not self.Inhibited:
current_time = gettime()
- if current_time - self.LastRefreshTime > REFRESH_PERIOD:
- self.LastRefreshTime = current_time
+ if current_time - self.LastRefreshTime > REFRESH_PERIOD and self.RefreshLock.acquire(False):
+ self.LastRefreshTime = gettime()
self.Inhibit(True)
- wx.CallAfter(self.RefreshViewOnNewData)
+ wx.CallAfter(self.RefreshViewOnNewData, *args, **kwargs)
- def RefreshViewOnNewData(self):
+ def RefreshViewOnNewData(self, *args, **kwargs):
if self:
- self.RefreshNewData()
+ self.RefreshNewData(*args, **kwargs)
self.RefreshTimer.Start(int(REFRESH_PERIOD * 1000), oneShot=True)
- def RefreshNewData(self):
+ def RefreshNewData(self, *args, **kwargs):
self.Inhibit(False)
-
+ self.RefreshLock.release()
+
#-------------------------------------------------------------------------------
# Viewer Rubberband
#-------------------------------------------------------------------------------