Falko Schindler пре 2 година
родитељ
комит
112d58f1fa
3 измењених фајлова са 10 додато и 2 уклоњено
  1. 5 2
      main.py
  2. 2 0
      nicegui/elements/group.py
  3. 3 0
      nicegui/elements/update.py

+ 5 - 2
main.py

@@ -221,10 +221,10 @@ with example(ui.number):
 with example(ui.color_input):
     color_label = ui.label('Change my color!')
     ui.color_input(label='Color', value='#000000',
-                   on_change=lambda e: color_label.style(f'color:{e.value}'))
+                   on_change=lambda e: ui.update(color_label.style(f'color:{e.value}')))
 
 with example(ui.color_picker):
-    picker = ui.color_picker(on_pick=lambda e: button.style(f'background-color:{e.color}!important'))
+    picker = ui.color_picker(on_pick=lambda e: ui.update(button.style(f'background-color:{e.color}!important')))
     button = ui.button(on_click=picker.open).props('icon=colorize')
 
 with example(ui.radio):
@@ -300,6 +300,7 @@ with example(ui.chart):
 
     def update():
         chart.options.series[0].data[:] = random(2)
+        ui.update(chart)
 
     chart = ui.chart({
         'title': False,
@@ -315,6 +316,7 @@ with example(ui.chart):
 with example(ui.table):
     def update():
         table.options.rowData[0].age += 1
+        ui.update(table)
 
     table = ui.table({
         'columnDefs': [
@@ -436,6 +438,7 @@ with example(clear):
     def add_face():
         with container:
             ui.icon('face')
+        ui.update(container)
     add_face()
 
     ui.button('Add', on_click=add_face)

+ 2 - 0
nicegui/elements/group.py

@@ -3,6 +3,7 @@ from __future__ import annotations
 from typing import List
 
 import justpy as jp
+from nicegui.task_logger import create_task
 
 from ..binding import active_links, bindable_properties, bindings
 from ..globals import view_stack
@@ -58,3 +59,4 @@ class Group(Element):
                 del bindable_properties[(obj_id, name)]
 
         self.view.delete_components()
+        create_task(self.view.update())

+ 3 - 0
nicegui/elements/update.py

@@ -1,3 +1,4 @@
+import asyncio
 from typing import List
 
 from ..task_logger import create_task
@@ -5,5 +6,7 @@ from .element import Element
 
 
 def update(self, *elements: List[Element]) -> None:
+    if not asyncio.get_event_loop().is_running():
+        return
     for element in elements:
         create_task(element.view.update())