Переглянути джерело

let timer no longer update its parent element

Falko Schindler 2 роки тому
батько
коміт
16148c1fb9
2 змінених файлів з 2 додано та 6 видалено
  1. 1 0
      nicegui/elements/line_plot.py
  2. 1 6
      nicegui/timer.py

+ 1 - 0
nicegui/elements/line_plot.py

@@ -54,3 +54,4 @@ class LinePlot(Plot):
         self.fig.gca().set_xlim(min_x - pad_x, max_x + pad_x)
         self.fig.gca().set_ylim(min_y - pad_y, max_y + pad_y)
         self.view.set_figure(self.fig)
+        self.update()

+ 1 - 6
nicegui/timer.py

@@ -23,7 +23,6 @@ class Timer:
 
         One major drive behind the creation of NiceGUI was the necessity to have a simple approach to update the interface in regular intervals, for example to show a graph with incomming measurements.
         A timer will execute a callback repeatedly with a given interval.
-        The parent view container will be updated automatically, as long as the callback does not return `False`.
 
         :param interval: the interval in which the timer is called (can be changed during runtime)
         :param callback: function or coroutine to execute when interval elapses (can return `False` to prevent view update)
@@ -31,7 +30,6 @@ class Timer:
         :param once: whether the callback is only executed once after a delay specified by `interval` (default: `False`)
         """
 
-        parent = view_stack[-1]
         self.active = active
         self.interval = interval
 
@@ -47,16 +45,13 @@ class Timer:
         async def timeout():
             await asyncio.sleep(self.interval)
             await do_callback()
-            await parent.update()
 
         async def loop():
             while True:
                 try:
                     start = time.time()
                     if self.active:
-                        needs_update = await do_callback()
-                        if needs_update != False:
-                            await parent.update()
+                        await do_callback()
                     dt = time.time() - start
                     await asyncio.sleep(self.interval - dt)
                 except asyncio.CancelledError: