Skip to content

Commit

Permalink
feat: add --browser=qt to use an embedded browser instead of system one
Browse files Browse the repository at this point in the history
This also restore the --browser feature that was previously broken.
  • Loading branch information
maartenbreddels committed Sep 10, 2024
1 parent 88ff8da commit 19548bb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
39 changes: 32 additions & 7 deletions jdaviz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def main(filepaths=None, layout='default', instrument=None, browser='default',
# easily accessed e.g. in the file load dialog.
os.environ['JDAVIZ_START_DIR'] = os.path.abspath('.')

from solara.__main__ import cli
from jdaviz import solara
solara.config = layout.capitalize()
solara.data_list = file_list
Expand All @@ -76,11 +75,37 @@ def main(filepaths=None, layout='default', instrument=None, browser='default',
args += ['--auto-restart']
else:
args += ['--production']
cli(['run', 'jdaviz.solara',
'--theme-loader', 'plain',
'--theme-variant', theme,
'--host', host,
'--port', port] + args)
run_solara(host=host, port=port, theme=theme, browser=browser)


def run_solara(host, port, theme, browser):
os.environ["SOLARA_APP"] = "jdaviz.solara"
import solara.server.starlette
import solara.server.settings
solara.server.settings.theme.variant = theme
solara.server.settings.theme.loader = "plain"

server = solara.server.starlette.ServerStarlette(host="localhost", port=port)
print(f"Starting server on {server.base_url}")
server.serve_threaded()
server.wait_until_serving()
if browser == "qt":
from qtpy.QtWidgets import QApplication
from qtpy.QtWebEngineWidgets import QWebEngineView
from qtpy import QtCore

app = QApplication([""])
web = QWebEngineView()
web.resize(1000, 1000)
web.setUrl(QtCore.QUrl(server.base_url))
web.show()

app.exec_()
else:
import webbrowser
controller = webbrowser.get(None if browser == 'default' else browser)
controller.open(server.base_url)
server.join()


def _main(config=None):
Expand All @@ -100,7 +125,7 @@ def _main(config=None):
parser.add_argument('--instrument', type=str, default='nirspec',
help='Manually specifies which instrument parser to use, for Mosviz')
parser.add_argument('--browser', type=str, default='default',
help='Browser to use for application.')
help='Browser to use for application (use qt for embedded qt browser).')
parser.add_argument('--theme', choices=['light', 'dark'], default='light',
help='Theme to use for application.')
parser.add_argument('--verbosity', choices=_verbosity_levels, default='info',
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ docs = [
roman = [
"roman_datamodels>=0.17.1",
]
qt = [
"qtpy",
"PySide6"
]

[build-system]
requires = [
Expand Down

0 comments on commit 19548bb

Please sign in to comment.