Browse Source

rename index_client to auto_index_client

Falko Schindler 1 year ago
parent
commit
0f1728809f
6 changed files with 14 additions and 14 deletions
  1. 1 1
      examples/ros2/ros2_ws/src/gui/gui/node.py
  2. 4 4
      nicegui/app.py
  3. 3 3
      nicegui/client.py
  4. 2 2
      nicegui/nicegui.py
  5. 2 2
      nicegui/storage.py
  6. 2 2
      tests/conftest.py

+ 1 - 1
examples/ros2/ros2_ws/src/gui/gui/node.py

@@ -17,7 +17,7 @@ class NiceGuiNode(Node):
         self.cmd_vel_publisher = self.create_publisher(Twist, 'cmd_vel', 1)
         self.subscription = self.create_subscription(Pose, 'pose', self.handle_pose, 1)
 
-        with Client.index_client:
+        with Client.auto_index_client:
             with ui.row().classes('items-stretch'):
                 with ui.card().classes('w-44 text-center items-center'):
                     ui.label('Control').classes('text-2xl')

+ 4 - 4
nicegui/app.py

@@ -7,7 +7,7 @@ from fastapi import FastAPI, HTTPException, Request
 from fastapi.responses import FileResponse, StreamingResponse
 from fastapi.staticfiles import StaticFiles
 
-from . import background_tasks, core, helpers
+from . import background_tasks, helpers
 from .app_config import AppConfig, RunConfig
 from .client import Client
 from .logging import log
@@ -65,14 +65,14 @@ class App(FastAPI):
         """Start NiceGUI. (For internal use only.)"""
         self._state = State.STARTING
         for t in self._startup_handlers:
-            helpers.safe_invoke(t, Client.index_client)
+            helpers.safe_invoke(t, Client.auto_index_client)
         self._state = State.STARTED
 
     def stop(self) -> None:
         """Stop NiceGUI. (For internal use only.)"""
         self._state = State.STOPPING
         for t in self._shutdown_handlers:
-            helpers.safe_invoke(t, Client.index_client)
+            helpers.safe_invoke(t, Client.auto_index_client)
         self._state = State.STOPPED
 
     def on_connect(self, handler: Union[Callable, Awaitable]) -> None:
@@ -125,7 +125,7 @@ class App(FastAPI):
         This will programmatically stop the server.
         Only possible when auto-reload is disabled.
         """
-        if core.app._run_config.reload:  # pylint: disable=protected-access
+        if self._run_config.reload:
             raise RuntimeError('calling shutdown() is not supported when auto-reload is enabled')
         if self.native.main_window:
             self.native.main_window.destroy()

+ 3 - 3
nicegui/client.py

@@ -35,7 +35,7 @@ class Client:
     instances: Dict[str, Client] = {}
     """Maps client IDs to clients."""
 
-    index_client: Client
+    auto_index_client: Client
     """The client that is used to render the auto-index page."""
 
     def __init__(self, page: page, *, shared: bool = False) -> None:
@@ -70,9 +70,9 @@ class Client:
         self._temporary_socket_id: Optional[str] = None
 
     @property
-    def is_index_client(self) -> bool:
+    def is_auto_index_client(self) -> bool:
         """Return True if this client is the auto-index client."""
-        return self is self.index_client
+        return self is self.auto_index_client
 
     @property
     def ip(self) -> Optional[str]:

+ 2 - 2
nicegui/nicegui.py

@@ -38,12 +38,12 @@ static_files = StaticFiles(
 )
 app.mount(f'/_nicegui/{__version__}/static', static_files, name='static')
 
-Client.index_client = Client(page('/'), shared=True).__enter__()  # pylint: disable=unnecessary-dunder-call
+Client.auto_index_client = Client(page('/'), shared=True).__enter__()  # pylint: disable=unnecessary-dunder-call
 
 
 @app.get('/')
 def _get_index(request: Request) -> Response:
-    return Client.index_client.build_response(request)
+    return Client.auto_index_client.build_response(request)
 
 
 @app.get(f'/_nicegui/{__version__}' + '/libraries/{key:path}')

+ 2 - 2
nicegui/storage.py

@@ -101,7 +101,7 @@ class Storage:
         """
         request: Optional[Request] = request_contextvar.get()
         if request is None:
-            if context.get_client().is_index_client:
+            if context.get_client().is_auto_index_client:
                 raise RuntimeError('app.storage.browser can only be used with page builder functions '
                                    '(https://nicegui.io/documentation/page)')
             raise RuntimeError('app.storage.browser needs a storage_secret passed in ui.run()')
@@ -121,7 +121,7 @@ class Storage:
         """
         request: Optional[Request] = request_contextvar.get()
         if request is None:
-            if context.get_client().is_index_client:
+            if context.get_client().is_auto_index_client:
                 raise RuntimeError('app.storage.user can only be used with page builder functions '
                                    '(https://nicegui.io/documentation/page)')
             raise RuntimeError('app.storage.user needs a storage_secret passed in ui.run()')

+ 2 - 2
tests/conftest.py

@@ -56,9 +56,9 @@ def reset_globals() -> Generator[None, None, None]:
     importlib.reload(core)
     Client.instances.clear()
     Client.page_routes.clear()
-    Client.index_client = Client(page('/'), shared=True).__enter__()
+    Client.auto_index_client = Client(page('/'), shared=True).__enter__()
     app.reset()
-    app.get('/')(Client.index_client.build_response)
+    app.get('/')(Client.auto_index_client.build_response)
     binding.reset()