浏览代码

add documentation

Falko Schindler 1 年之前
父节点
当前提交
876323a3ad
共有 2 个文件被更改,包括 20 次插入1 次删除
  1. 2 1
      nicegui/functions/refreshable.py
  2. 18 0
      website/more_documentation/refreshable_documentation.py

+ 2 - 1
nicegui/functions/refreshable.py

@@ -58,12 +58,13 @@ class refreshable:
         self.targets.append(target)
         self.targets.append(target)
         return target.run(self.func)
         return target.run(self.func)
 
 
-    def refresh(self, **kwargs: Any) -> None:
+    def refresh(self, *args: Any, **kwargs: Any) -> None:
         self.prune()
         self.prune()
         for target in self.targets:
         for target in self.targets:
             if target.instance != self.instance:
             if target.instance != self.instance:
                 continue
                 continue
             target.container.clear()
             target.container.clear()
+            target.args = args or target.args
             target.kwargs.update(kwargs)
             target.kwargs.update(kwargs)
             result = target.run(self.func)
             result = target.run(self.func)
             if is_coroutine_function(self.func):
             if is_coroutine_function(self.func):

+ 18 - 0
website/more_documentation/refreshable_documentation.py

@@ -21,6 +21,24 @@ def main_demo() -> None:
 
 
 
 
 def more() -> None:
 def more() -> None:
+    @text_demo('Refreshable UI with parameters', '''
+        Here is a demo of how to use the refreshable decorator to create a UI that can be refreshed with different parameters.
+    ''')
+    def refreshable_with_parameters():
+        from datetime import datetime
+
+        import pytz
+
+        @ui.refreshable
+        def clock_ui(timezone: str):
+            ui.label(f'Current time in {timezone}:')
+            ui.label(datetime.now(tz=pytz.timezone(timezone)).strftime('%H:%M:%S'))
+
+        clock_ui('Europe/Berlin')
+        ui.button('Refresh', on_click=clock_ui.refresh)
+        ui.button('Refresh for New York', on_click=lambda: clock_ui.refresh('America/New_York'))
+        ui.button('Refresh for Tokyo', on_click=lambda: clock_ui.refresh('Asia/Tokyo'))
+
     @text_demo('Refreshable UI for input validation', '''
     @text_demo('Refreshable UI for input validation', '''
         Here is a demo of how to use the refreshable decorator to give feedback about the validity of user input.
         Here is a demo of how to use the refreshable decorator to give feedback about the validity of user input.
     ''')
     ''')