Browse Source

trying to update all childs rcursively to update timer

Rodja Trappe 4 years ago
parent
commit
4e48b8894b
2 changed files with 13 additions and 2 deletions
  1. 2 1
      main.py
  2. 11 1
      nice_gui.py

+ 2 - 1
main.py

@@ -15,9 +15,10 @@ with ui.card():
             ui.label('C2')
             ui.label('C2')
             ui.label('C3')
             ui.label('C3')
 
 
-ui.run()
 
 
 with ui.row():
 with ui.row():
     ui.label('Time:')
     ui.label('Time:')
     time = ui.label()
     time = ui.label()
     ui.timer(0.1, lambda: time.set_text(datetime.now().strftime("%X")))
     ui.timer(0.1, lambda: time.set_text(datetime.now().strftime("%X")))
+
+ui.run()

+ 11 - 1
nice_gui.py

@@ -6,6 +6,9 @@ import inspect
 import time
 import time
 import asyncio
 import asyncio
 from utils import handle_exceptions, provide_arguments
 from utils import handle_exceptions, provide_arguments
+import icecream
+
+icecream.install()
 
 
 wp = jp.WebPage(delete_flag=False, title='Nice GUI', favicon='favicon.png')
 wp = jp.WebPage(delete_flag=False, title='Nice GUI', favicon='favicon.png')
 main = jp.Div(a=wp, classes='m-4 flex flex-col items-start gap-4')
 main = jp.Div(a=wp, classes='m-4 flex flex-col items-start gap-4')
@@ -70,12 +73,19 @@ class Ui(Starlette):
 
 
     def timer(self, inverval, callback):
     def timer(self, inverval, callback):
 
 
+        def update(view):
+            if view.components:
+                for v in view.components:
+                    update(v)
+
+            jp.run_task(view.update())
+
         async def loop():
         async def loop():
 
 
             while True:
             while True:
                 start = time.time()
                 start = time.time()
                 handle_exceptions(callback)()
                 handle_exceptions(callback)()
-                jp.run_task(wp.update())
+                update(view_stack[-1])
                 dt = time.time() - start
                 dt = time.time() - start
                 await asyncio.sleep(inverval - dt)
                 await asyncio.sleep(inverval - dt)