瀏覽代碼

Merge branch 'main' of github.com:zauberzeug/nicegui

Rodja Trappe 2 年之前
父節點
當前提交
c60c65143e
共有 6 個文件被更改,包括 15 次插入19 次删除
  1. 1 1
      nicegui/client.py
  2. 10 14
      nicegui/element.py
  3. 1 1
      nicegui/elements/spinner.py
  4. 1 1
      nicegui/nicegui.py
  5. 1 1
      nicegui/outbox.py
  6. 1 1
      nicegui/run.py

+ 1 - 1
nicegui/client.py

@@ -67,7 +67,7 @@ class Client:
     def build_response(self, request: Request, status_code: int = 200) -> Response:
         prefix = request.headers.get('X-Forwarded-Prefix', '')
         vue_html, vue_styles, vue_scripts = generate_vue_content()
-        elements = json.dumps({id: element.to_dict() for id, element in self.elements.items()})
+        elements = json.dumps({id: element._to_dict() for id, element in self.elements.items()})
         return templates.TemplateResponse('index.html', {
             'request': request,
             'client_id': str(self.id),

+ 10 - 14
nicegui/element.py

@@ -91,7 +91,7 @@ class Element(ABC, Visibility):
     def _collect_slot_dict(self) -> Dict[str, List[int]]:
         return {name: [child.id for child in slot.children] for name, slot in self.slots.items()}
 
-    def to_dict(self, *keys: str) -> Dict:
+    def _to_dict(self, *keys: str) -> Dict:
         if not keys:
             return {
                 'id': self.id,
@@ -245,22 +245,11 @@ class Element(ABC, Visibility):
             self._event_listeners.append(listener)
         return self
 
-    def handle_event(self, msg: Dict) -> None:
+    def _handle_event(self, msg: Dict) -> None:
         for listener in self._event_listeners:
             if listener.type == msg['type']:
                 events.handle_event(listener.handler, msg, sender=self)
 
-    def collect_descendant_ids(self) -> List[int]:
-        """Return a list of IDs of the element and each of its descendants.
-
-        The first ID in the list is that of the element itself.
-        """
-        ids: List[int] = [self.id]
-        for slot in self.slots.values():
-            for child in slot.children:
-                ids.extend(child.collect_descendant_ids())
-        return ids
-
     def update(self) -> None:
         """Update the element on the client side."""
         outbox.enqueue_update(self)
@@ -276,9 +265,16 @@ class Element(ABC, Visibility):
         data = {'id': self.id, 'name': name, 'args': args}
         outbox.enqueue_message('run_method', data, globals._socket_id or self.client.id)
 
+    def _collect_descendant_ids(self) -> List[int]:
+        ids: List[int] = [self.id]
+        for slot in self.slots.values():
+            for child in slot.children:
+                ids.extend(child._collect_descendant_ids())
+        return ids
+
     def clear(self) -> None:
         """Remove all child elements."""
-        descendants = [self.client.elements[id] for id in self.collect_descendant_ids()[1:]]
+        descendants = [self.client.elements[id] for id in self._collect_descendant_ids()[1:]]
         binding.remove(descendants, Element)
         for element in descendants:
             del self.client.elements[element.id]

+ 1 - 1
nicegui/elements/spinner.py

@@ -44,7 +44,7 @@ class Spinner(Element):
         :param color: color of the spinner (default: "primary")
         :param thickness: thickness of the spinner (applies to the "default" spinner only, default: 5.0)
         """
-        super().__init__('q-spinner' if type is 'default' else f'q-spinner-{type}')
+        super().__init__('q-spinner' if type == 'default' else f'q-spinner-{type}')
         self._props['size'] = size
         self._props['color'] = color
         self._props['thickness'] = thickness

+ 1 - 1
nicegui/nicegui.py

@@ -129,7 +129,7 @@ def handle_event(sid: str, msg: Dict) -> None:
     with client:
         sender = client.elements.get(msg['id'])
         if sender:
-            sender.handle_event(msg)
+            sender._handle_event(msg)
 
 
 @sio.on('javascript_response')

+ 1 - 1
nicegui/outbox.py

@@ -32,7 +32,7 @@ async def loop() -> None:
         coros = []
         try:
             for client_id, elements in update_queue.items():
-                elements = {element_id: element.to_dict() for element_id, element in elements.items()}
+                elements = {element_id: element._to_dict() for element_id, element in elements.items()}
                 coros.append(globals.sio.emit('update', elements, room=client_id))
             update_queue.clear()
             for client_id, message_type, data in message_queue:

+ 1 - 1
nicegui/run.py

@@ -47,7 +47,7 @@ def run(*,
     :param uvicorn_reload_includes: string with comma-separated list of glob-patterns which trigger reload on modification (default: `'.py'`)
     :param uvicorn_reload_excludes: string with comma-separated list of glob-patterns which should be ignored for reload (default: `'.*, .py[cod], .sw.*, ~*'`)
     :param exclude: comma-separated string to exclude elements (with corresponding JavaScript libraries) to save bandwidth
-      (possible entries: audio, chart, colors, interactive_image, joystick, keyboard, log, mermaid, scene, table, video)
+      (possible entries: audio, chart, colors, interactive_image, joystick, keyboard, log, markdown, mermaid, plotly, scene, table, video)
     :param tailwind: whether to use Tailwind (experimental, default: `True`)
     '''
     globals.ui_run_has_been_called = True