Skip to content

Commit

Permalink
feat(server): add python option to disable web browser opening
Browse files Browse the repository at this point in the history
This adds a "server" argument, which can override the sys.argv argument and set whether or not
to open the web browser.

Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
  • Loading branch information
psavery committed Apr 14, 2022
1 parent dd79b5d commit 614b378
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions trame/internal/utils/logging.py
Expand Up @@ -5,7 +5,7 @@ def log_js_error(message):
print(f" > JS error | {message}")


def print_server_info(_fn=None):
def print_server_info(_fn=None, server=None, **kwargs):
"""Provide network info so clients can connect to the started server"""
from trame.internal.app import get_app_instance

Expand Down Expand Up @@ -40,7 +40,11 @@ def ready(**kwargs):
except TypeError:
_fn()

if not args.server:
nonlocal server
if server is None:
server = args.server

if not server:
import webbrowser
import asyncio

Expand Down
10 changes: 5 additions & 5 deletions trame/layouts/core.py
Expand Up @@ -115,6 +115,10 @@ def start(self, port=None, debug=None, **kwargs):
* exec_mode (str): "main" (default) or "task" for running in an
environment that already has an event loop,
such as a Jupyter notebook.
The kwargs will also be forwarded to print_server_info(), so that
the `server` kwarg may be used to indicate whether a new window
should be opened.
"""
_app = tri.get_app_instance()

Expand All @@ -126,11 +130,7 @@ def start(self, port=None, debug=None, **kwargs):
debug = args.dev

_app._debug = debug

if self.on_ready:
_app.on_ready = tri.print_server_info(self.on_ready)
else:
_app.on_ready = tri.print_server_info()
_app.on_ready = tri.print_server_info(self.on_ready, **kwargs)

# Dev validation
tri.validate_key_names()
Expand Down

0 comments on commit 614b378

Please sign in to comment.