|
@@ -3,17 +3,17 @@ import multiprocessing
|
|
import os
|
|
import os
|
|
import sys
|
|
import sys
|
|
import webbrowser
|
|
import webbrowser
|
|
-from typing import List, Optional, Tuple, Union
|
|
|
|
|
|
+from typing import List, Optional, Tuple
|
|
|
|
|
|
import uvicorn
|
|
import uvicorn
|
|
from uvicorn.main import STARTUP_FAILURE
|
|
from uvicorn.main import STARTUP_FAILURE
|
|
from uvicorn.supervisors import ChangeReload, Multiprocess
|
|
from uvicorn.supervisors import ChangeReload, Multiprocess
|
|
|
|
|
|
-from . import globals, standalone_mode
|
|
|
|
|
|
+from . import globals, native_mode
|
|
|
|
|
|
|
|
|
|
def run(*,
|
|
def run(*,
|
|
- host: str = '0.0.0.0',
|
|
|
|
|
|
+ host: Optional[str] = None,
|
|
port: int = 8080,
|
|
port: int = 8080,
|
|
title: str = 'NiceGUI',
|
|
title: str = 'NiceGUI',
|
|
viewport: str = 'width=device-width, initial-scale=1',
|
|
viewport: str = 'width=device-width, initial-scale=1',
|
|
@@ -21,8 +21,9 @@ def run(*,
|
|
dark: Optional[bool] = False,
|
|
dark: Optional[bool] = False,
|
|
binding_refresh_interval: float = 0.1,
|
|
binding_refresh_interval: float = 0.1,
|
|
show: bool = True,
|
|
show: bool = True,
|
|
- standalone: bool = False,
|
|
|
|
- fullscreen: Union[bool, Tuple[int, int]] = False,
|
|
|
|
|
|
+ native: bool = False,
|
|
|
|
+ window_size: Optional[Tuple[int, int]] = None,
|
|
|
|
+ fullscreen: bool = False,
|
|
reload: bool = True,
|
|
reload: bool = True,
|
|
uvicorn_logging_level: str = 'warning',
|
|
uvicorn_logging_level: str = 'warning',
|
|
uvicorn_reload_dirs: str = '.',
|
|
uvicorn_reload_dirs: str = '.',
|
|
@@ -36,7 +37,7 @@ def run(*,
|
|
|
|
|
|
You can call `ui.run()` with optional arguments:
|
|
You can call `ui.run()` with optional arguments:
|
|
|
|
|
|
- :param host: start server with this host (default: `'0.0.0.0'`)
|
|
|
|
|
|
+ :param host: start server with this host (defaults to `'127.0.0.1` in native mode, otherwise `'0.0.0.0'`)
|
|
:param port: use this port (default: `8080`)
|
|
:param port: use this port (default: `8080`)
|
|
:param title: page title (default: `'NiceGUI'`, can be overwritten per page)
|
|
:param title: page title (default: `'NiceGUI'`, can be overwritten per page)
|
|
:param viewport: page meta viewport content (default: `'width=device-width, initial-scale=1'`, can be overwritten per page)
|
|
:param viewport: page meta viewport content (default: `'width=device-width, initial-scale=1'`, can be overwritten per page)
|
|
@@ -44,8 +45,9 @@ def run(*,
|
|
:param dark: whether to use Quasar's dark mode (default: `False`, use `None` for "auto" mode)
|
|
:param dark: whether to use Quasar's dark mode (default: `False`, use `None` for "auto" mode)
|
|
:param binding_refresh_interval: time between binding updates (default: `0.1` seconds, bigger is more CPU friendly)
|
|
:param binding_refresh_interval: time between binding updates (default: `0.1` seconds, bigger is more CPU friendly)
|
|
:param show: automatically open the UI in a browser tab (default: `True`)
|
|
:param show: automatically open the UI in a browser tab (default: `True`)
|
|
- :param standalone: open the UI in a standalone window (default: `False`, accepts size as tuple or True (800, 600), deactivates `show`, automatically finds an open port)
|
|
|
|
- :param fullscreen: open the UI in a fullscreen, standalone window (default: `False`, also activates `standalone`)
|
|
|
|
|
|
+ :param native: open the UI in a native window of size 800x600 (default: `False`, deactivates `show`, automatically finds an open port)
|
|
|
|
+ :param window_size: open the UI in a native window with the provided size (e.g. `(1024, 786)`, default: `None`, also activates `native`)
|
|
|
|
+ :param fullscreen: open the UI in a fullscreen window (default: `False`, also activates `native`)
|
|
:param reload: automatically reload the UI on file changes (default: `True`)
|
|
:param reload: automatically reload the UI on file changes (default: `True`)
|
|
:param uvicorn_logging_level: logging level for uvicorn server (default: `'warning'`)
|
|
:param uvicorn_logging_level: logging level for uvicorn server (default: `'warning'`)
|
|
:param uvicorn_reload_dirs: string with comma-separated list for directories to be monitored (default is current working directory only)
|
|
:param uvicorn_reload_dirs: string with comma-separated list for directories to be monitored (default is current working directory only)
|
|
@@ -57,8 +59,6 @@ def run(*,
|
|
:param kwargs: additional keyword arguments are passed to `uvicorn.run`
|
|
:param kwargs: additional keyword arguments are passed to `uvicorn.run`
|
|
'''
|
|
'''
|
|
globals.ui_run_has_been_called = True
|
|
globals.ui_run_has_been_called = True
|
|
- globals.host = host
|
|
|
|
- globals.port = port
|
|
|
|
globals.reload = reload
|
|
globals.reload = reload
|
|
globals.title = title
|
|
globals.title = title
|
|
globals.viewport = viewport
|
|
globals.viewport = viewport
|
|
@@ -72,11 +72,20 @@ def run(*,
|
|
return
|
|
return
|
|
|
|
|
|
if fullscreen:
|
|
if fullscreen:
|
|
- standalone = True
|
|
|
|
- if standalone:
|
|
|
|
|
|
+ native = True
|
|
|
|
+ if window_size:
|
|
|
|
+ native = True
|
|
|
|
+ if native:
|
|
show = False
|
|
show = False
|
|
- width, height = (800, 600) if standalone is True else standalone
|
|
|
|
- standalone_mode.activate(f'http://localhost:{port}', title, width, height, fullscreen)
|
|
|
|
|
|
+ host = host or '127.0.0.1'
|
|
|
|
+ port = native_mode.find_open_port()
|
|
|
|
+ width, height = window_size or (800, 600)
|
|
|
|
+ native_mode.activate(f'http://{host}:{port}', title, width, height, fullscreen)
|
|
|
|
+ else:
|
|
|
|
+ host = host or '0.0.0.0'
|
|
|
|
+
|
|
|
|
+ # NOTE: We save the URL in an environment variable so the subprocess started in reload mode can access it.
|
|
|
|
+ os.environ['NICEGUI_URL'] = f'http://{host}:{port}'
|
|
|
|
|
|
if show:
|
|
if show:
|
|
webbrowser.open(f'http://{host if host != "0.0.0.0" else "127.0.0.1"}:{port}/')
|
|
webbrowser.open(f'http://{host if host != "0.0.0.0" else "127.0.0.1"}:{port}/')
|