|
@@ -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:
|