Jelajahi Sumber

improve ui.run example

Falko Schindler 2 tahun lalu
induk
melakukan
d0833194a1
2 mengubah file dengan 13 tambahan dan 13 penghapusan
  1. 6 5
      website/example.py
  2. 7 8
      website/reference.py

+ 6 - 5
website/example.py

@@ -1,6 +1,6 @@
 import inspect
 import re
-from typing import Callable, Union
+from typing import Callable, Optional, Union
 
 import docutils.core
 
@@ -19,8 +19,9 @@ BROWSER_COLOR = '#ffffff'
 
 class example:
 
-    def __init__(self, content: Union[Callable, type, str]) -> None:
+    def __init__(self, content: Union[Callable, type, str], browser_title: Optional[str] = None) -> None:
         self.content = content
+        self.browser_title = browser_title
 
     def __call__(self, f: Callable) -> Callable:
         with ui.row().classes('q-mb-xl'):
@@ -60,7 +61,7 @@ class example:
                 code = '\n'.join(code)
                 with python_window().classes(f'w-[43rem] overflow-auto'):
                     ui.markdown(code)
-                with browser_window().classes('w-80 browser-window'):
+                with browser_window(self.browser_title).classes('w-80 browser-window'):
                     f()
         return f
 
@@ -128,5 +129,5 @@ def bash_window() -> ui.card:
     return window(BASH_COLOR, BASH_BGCOLOR, title='bash')
 
 
-def browser_window() -> ui.card:
-    return window(BROWSER_COLOR, BROWSER_BGCOLOR, tab='NiceGUI')
+def browser_window(title: Optional[str] = None) -> ui.card:
+    return window(BROWSER_COLOR, BROWSER_BGCOLOR, tab=title or 'NiceGUI')

+ 7 - 8
website/reference.py

@@ -750,26 +750,25 @@ You can call `ui.run()` with optional arguments:
 - `title` (default: `'NiceGUI'`)
 - `favicon`: relative filepath to a favicon (default: `None`, NiceGUI icon will be used)
 - `dark`: whether to use Quasar's dark mode (default: `False`, use `None` for "auto" mode)
-- `main_page_classes`: configure Quasar classes of main page (default: `'q-pa-md column items-start'`)
-- `binding_refresh_interval`: time between binding updates (default: `0.1` seconds, bigger is more cpu friendly)
-- `show`: automatically open the ui in a browser tab (default: `True`)
-- `reload`: automatically reload the ui on file changes (default: `True`)
+- `binding_refresh_interval`: time between binding updates (default: `0.1` seconds, bigger is more CPU friendly)
+- `show`: automatically open the UI in a browser tab (default: `True`)
+- `reload`: automatically reload the UI on file changes (default: `True`)
 - `uvicorn_logging_level`: logging level for uvicorn server (default: `'warning'`)
 - `uvicorn_reload_dirs`: string with comma-separated list for directories to be monitored (default is current working directory only)
 - `uvicorn_reload_includes`: string with comma-separated list of glob-patterns which trigger reload on modification (default: `'.py'`)
 - `uvicorn_reload_excludes`: string with comma-separated list of glob-patterns which should be ignored for reload (default: `'.*, .py[cod], .sw.*, ~*'`)
 - `exclude`: comma-separated string to exclude elements (with corresponding JavaScript libraries) to save bandwidth
-(possible entries: chart, colors, interactive_image, joystick, keyboard, log, scene, upload, table)
+  (possible entries: chart, colors, interactive_image, joystick, keyboard, log, scene, upload, table)
 
 The environment variables `HOST` and `PORT` can also be used to configure NiceGUI.
 
 To avoid the potentially costly import of Matplotlib, you set the environment variable `MATPLOTLIB=false`.
 This will make `ui.plot` and `ui.line_plot` unavailable.
-''')
+''', browser_title='My App')
         def ui_run_example():
-            ui.label('dark page on port 7000 without reloading')
+            ui.label('page with custom title')
 
-            # ui.run(dark=True, port=7000, reload=False)
+            # ui.run(title='My App')
 
         # HACK: turn expensive line plot off after 10 seconds
         def handle_change(msg: Dict) -> None: