浏览代码

documentation

Falko Schindler 3 年之前
父节点
当前提交
16aa01f2b2
共有 2 个文件被更改,包括 15 次插入1 次删除
  1. 6 0
      main.py
  2. 9 1
      nicegui/elements/log.py

+ 6 - 0
main.py

@@ -264,6 +264,12 @@ with example(ui.line_plot):
     ]), active=False)
     ]), active=False)
     ui.checkbox('active').bind_value(line_updates.active)
     ui.checkbox('active').bind_value(line_updates.active)
 
 
+with example(ui.log):
+    from datetime import datetime
+
+    log = ui.log().classes('h-16')
+    ui.button('Log time', on_click=lambda: log.push(datetime.now().strftime("%X.%f")[:-5]))
+
 with example(ui.joystick):
 with example(ui.joystick):
 
 
     ui.joystick(
     ui.joystick(

+ 9 - 1
nicegui/elements/log.py

@@ -12,14 +12,22 @@ class LogView(CustomView):
 class Log(Element):
 class Log(Element):
 
 
     def __init__(self):
     def __init__(self):
+        """Log view
+
+        Create a log view that allows to add new lines without re-transmitting the whole history to the client.
+        """
 
 
         super().__init__(LogView())
         super().__init__(LogView())
 
 
         self.classes('border whitespace-pre font-mono')
         self.classes('border whitespace-pre font-mono')
 
 
-    async def push(self, line: str):
+    async def push_async(self, line: str):
 
 
         await asyncio.gather(*[
         await asyncio.gather(*[
             self.view.run_method(f'push("{line}")', socket)
             self.view.run_method(f'push("{line}")', socket)
             for socket in WebPage.sockets[Element.wp.page_id].values()
             for socket in WebPage.sockets[Element.wp.page_id].values()
         ])
         ])
+
+    def push(self, line: str):
+
+        asyncio.get_event_loop().create_task(self.push_async(line))