Explorar el Código

Call Tk's update_idletasks when scheduling another wakeup, so the (digital watch) interface remains responsive under full load.

Joeri Exelmans hace 5 años
padre
commit
a5bd657f8d

+ 11 - 9
examples/digitalwatch/DigitalWatchGUI.py

@@ -536,17 +536,19 @@ class DigitalWatchGUI_Static(Frame):
 
     def drawChrono(self):
         chronoToDraw = self.__getChronoAsString()
-
-        self.clearDisplay()
-            
         if not self.battery:
             chronoToDraw = "88:88:88"
-            
-        self.chronoTag = self.displayCanvas.create_text((RECT_X0 + RECT_X1) / 2,
-                                                         (RECT_Y0 + RECT_Y1) / 2 + 5,
-                                                        font=FONT_TIME,
-                                                        justify="center",
-                                                        text=chronoToDraw)
+
+        if self.chronoTag:
+            self.displayCanvas.itemconfigure(self.chronoTag, text=chronoToDraw)
+        else:
+            self.clearDisplay()            
+            self.chronoTag = self.displayCanvas.create_text(
+                (RECT_X0 + RECT_X1) / 2,
+                (RECT_Y0 + RECT_Y1) / 2 + 5,
+                font=FONT_TIME,
+                justify="center",
+                text=chronoToDraw)
 
     def hideChrono(self):
         if self.chronoTag != None:

+ 1 - 3
examples/digitalwatch/model_digitalwatch.xml

@@ -128,9 +128,7 @@
 
           <state id="ChronoUpdate">
             <transition event="topLeftPressed" target="../TimeUpdate"/>
-            <!-- the rendering of the display takes a lot of CPU time (4.25 ms on my machine)
-                 so we don't re-render every 10 ms.. looks good enough -->
-            <transition after="30 ms" target=".">
+            <transition after="10 ms" target=".">
               <raise event="refreshChronoDisplay"/>
             </transition>
           </state>

+ 8 - 5
src/sccd/realtime/eventloop.py

@@ -11,11 +11,11 @@ class EventLoopImplementation(ABC):
         pass
 
     @abstractmethod
-    def schedule(self) -> Callable[[int, Callable[[],None]], ScheduledID]:
+    def schedule(self, timeout: int, callback: Callable[[],None]) -> ScheduledID:
         pass
 
     @abstractmethod
-    def cancel(self) -> Callable[[ScheduledID], None]:
+    def cancel(self, id: ScheduledID):
         pass
 
 
@@ -44,10 +44,13 @@ class EventLoop:
             pass
 
         # back to sleep
+        now = self.timer.now()
         next_wakeup = self.controller.next_wakeup()
         if next_wakeup:
-            sleep_duration = self.event_loop_convert(next_wakeup - self.controller.simulated_time)
-            self.scheduled = self.event_loop.schedule()(sleep_duration, self._wakeup)
+            # (next_wakeup - now) is negative, we are running behind
+            # not much we can do about it though
+            sleep_duration = max(0, self.event_loop_convert(next_wakeup - now))
+            self.scheduled = self.event_loop.schedule(sleep_duration, self._wakeup)
         else:
             self.scheduled = None
 
@@ -70,5 +73,5 @@ class EventLoop:
 
     def interrupt(self):
         if self.scheduled:
-            self.event_loop.cancel()(self.scheduled)
+            self.event_loop.cancel(self.scheduled)
         self._wakeup()

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 9 - 4
src/sccd/realtime/tkinter.py