diff --git a/itkwidgets/__init__.py b/itkwidgets/__init__.py index 406bd732..872ddbac 100644 --- a/itkwidgets/__init__.py +++ b/itkwidgets/__init__.py @@ -9,9 +9,11 @@ register_itkwasm_imjoy_codecs() from .viewer import Viewer, view, compare_images +from .standalone_server import standalone_viewer __all__ = [ "Viewer", "view", "compare_images", + "standalone_viewer", ] diff --git a/itkwidgets/standalone.py b/itkwidgets/standalone_server.py similarity index 86% rename from itkwidgets/standalone.py rename to itkwidgets/standalone_server.py index 5dba0538..85a9cb7a 100644 --- a/itkwidgets/standalone.py +++ b/itkwidgets/standalone_server.py @@ -19,7 +19,7 @@ from itkwidgets.imjoy import register_itkwasm_imjoy_codecs_cli from itkwidgets._initialization_params import build_config, parse_input_data, build_init_data from pathlib import Path -from urllib.parse import urlencode +from urllib.parse import parse_qs, urlencode, urlparse def _snake_to_camel(variable): @@ -27,6 +27,25 @@ def _snake_to_camel(variable): return first + ''.join([w.capitalize() for w in words]) +async def standalone_viewer(url): + query = parse_qs(urlparse(url).query) + server_url = f"http://{SERVER_HOST}:{SERVER_PORT}" + workspace = query["workspace"][0] + token = query["token"][0] + + server = await connect_to_server({ + 'client_id': 'itkwidgets-interactive', + 'name': 'itkwidgets_interactive', + "server_url": server_url, + "workspace": workspace, + "token": token + }) + + svc = await server.get_service( + f'{workspace}/itkwidgets-client:itk-vtk-viewer') + return await svc.viewer() + + def input_dict(): user_input = vars(opts) if opts.image: @@ -124,4 +143,4 @@ def main(): parser.add_argument('--gradient-opacity', type=float, help='Set the gradient opacity in the volume rendering. Values range from 0.0 to 1.0.') opts = parser.parse_args() - main(opts) + main()