Fixed refresh speed so that interface is not blocked when debugging
authorLaurent Bessard
Mon, 14 Oct 2013 14:59:15 +0200
changeset 1366 3756ae754713
parent 1365 debc97102b23
child 1367 324767a092dc
Fixed refresh speed so that interface is not blocked when debugging
ProjectController.py
editors/Viewer.py
--- a/ProjectController.py	Mon Oct 14 12:28:44 2013 +0200
+++ b/ProjectController.py	Mon Oct 14 14:59:15 2013 +0200
@@ -7,6 +7,7 @@
 import shutil
 import wx
 import re, tempfile
+from math import ceil
 from types import ListType
 from threading import Timer, Lock, Thread
 from time import localtime
@@ -1407,12 +1408,19 @@
         self.IECdebug_lock.acquire()
         debug_ticks, buffers = self.SnapshotAndResetDebugValuesBuffers()
         self.IECdebug_lock.release()
+        start_time = time.time()
         if len(self.TracedIECPath) == len(buffers):
             for IECPath, values in zip(self.TracedIECPath, buffers):
                 if len(values) > 0:
                     self.CallWeakcallables(IECPath, "NewValues", debug_ticks, values)
             if len(debug_ticks) > 0:
                 self.CallWeakcallables("__tick__", "NewDataAvailable", debug_ticks)
+        
+        delay = time.time() - start_time
+        next_refresh = max(REFRESH_PERIOD - delay, 0.2 * delay)
+        if self.DispatchDebugValuesTimer is not None and self.DebugThread is not None:
+            self.DispatchDebugValuesTimer.Start(
+                int(next_refresh * 1000), oneShot=True)
         event.Skip()
 
     def KillDebugThread(self):
@@ -1435,7 +1443,8 @@
             self.AppFrame.ResetGraphicViewers()
         self.RegisterDebugVarToConnector()
         if self.DispatchDebugValuesTimer is not None:
-            self.DispatchDebugValuesTimer.Start(int(REFRESH_PERIOD * 1000))
+            self.DispatchDebugValuesTimer.Start(
+                int(REFRESH_PERIOD * 1000), oneShot=True)
         if self.DebugThread is None:
             self.DebugThread = Thread(target=self.DebugThreadProc)
             self.DebugThread.start()
--- a/editors/Viewer.py	Mon Oct 14 12:28:44 2013 +0200
+++ b/editors/Viewer.py	Mon Oct 14 14:59:15 2013 +0200
@@ -1054,19 +1054,20 @@
         self.ElementRefreshList_lock.release()
         
     def NewDataAvailable(self, ticks, *args, **kwargs):
-        refresh_rect = None
-        self.ElementRefreshList_lock.acquire()
-        for element in self.ElementRefreshList:
-            if refresh_rect is None:
-                refresh_rect = element.GetRedrawRect()
-            else:
-                refresh_rect.Union(element.GetRedrawRect())
-        self.ElementRefreshList = []
-        self.ElementRefreshList_lock.release()
-        
-        if refresh_rect is not None:
-            self.RefreshRect(self.GetScrolledRect(refresh_rect), False)
-    
+        if self.IsShown():
+            refresh_rect = None
+            self.ElementRefreshList_lock.acquire()
+            for element in self.ElementRefreshList:
+                if refresh_rect is None:
+                    refresh_rect = element.GetRedrawRect()
+                else:
+                    refresh_rect.Union(element.GetRedrawRect())
+            self.ElementRefreshList = []
+            self.ElementRefreshList_lock.release()
+            
+            if refresh_rect is not None:
+                self.RefreshRect(self.GetScrolledRect(refresh_rect), False)
+        
     def SubscribeAllDataConsumers(self):
         self.RefreshView()
         DebugViewer.SubscribeAllDataConsumers(self)