diff --git a/zndraw/app.py b/zndraw/app.py index 6f6357433..14019de74 100644 --- a/zndraw/app.py +++ b/zndraw/app.py @@ -21,13 +21,16 @@ def index(): try: token = session["token"] except KeyError: - token = uuid.uuid4().hex + if "token" in app.config: + token = app.config["token"] + else: + token = uuid.uuid4().hex session["token"] = token return render_template( - "index.html", + "index.jinja2", upgrade_insecure_requests=app.config["upgrade_insecure_requests"], - token=session["token"], + token=session["token"], ) diff --git a/zndraw/cli.py b/zndraw/cli.py index 6c7cb120c..bbf954546 100644 --- a/zndraw/cli.py +++ b/zndraw/cli.py @@ -46,12 +46,6 @@ def main( True, help="""Whether to compute bonds for the structure. If set to False, no bonds will be computed.""", ), - multiprocessing: bool = typer.Option( - False, - "--multiprocessing", - "-mp", - help="""Use multiprocessing to read data files. This will slow down the loading time, but enables loading large files in the background.""", - ), upgrade_insecure_requests: bool = typer.Option( False, hidden=True, @@ -79,7 +73,6 @@ def main( stop=stop, step=step, compute_bonds=compute_bonds, - multiprocessing=multiprocessing, upgrade_insecure_requests=upgrade_insecure_requests, use_token=use_token, ) diff --git a/zndraw/templates/index.html b/zndraw/templates/index.html deleted file mode 100644 index 0673fe9cc..000000000 --- a/zndraw/templates/index.html +++ /dev/null @@ -1,707 +0,0 @@ - - - - - {% if upgrade_insecure_requests %} - - {% endif %} - ZnDraw - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
-
-
-
- -
-
-
- - - - - - -
- -
-
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
-
-
-
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
-
- - - -
-
- - -
- - - - - - - - diff --git a/zndraw/templates/index.jinja2 b/zndraw/templates/index.jinja2 new file mode 100644 index 000000000..a4e694ab6 --- /dev/null +++ b/zndraw/templates/index.jinja2 @@ -0,0 +1,429 @@ + + + + + + {% if upgrade_insecure_requests %} + + {% endif %} + ZnDraw + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+ +
+
+
+ + + + + + +
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+
+ + + +
+
+ + +
+ + + + + + + + + \ No newline at end of file diff --git a/zndraw/view.py b/zndraw/view.py index b729032e3..69ce0c447 100644 --- a/zndraw/view.py +++ b/zndraw/view.py @@ -48,20 +48,13 @@ def view( stop: int, step: int, compute_bonds: bool, - multiprocessing: bool, use_token: bool = False, upgrade_insecure_requests: bool = False, ): - # if filename is not None: - # app.config["filename"] = filename - # app.config["start"] = start - # app.config["stop"] = stop - # app.config["step"] = step if not use_token: - app.config["uuid"] = "default" + app.config["token"] = "notoken" app.config["upgrade_insecure_requests"] = upgrade_insecure_requests app.config["compute_bonds"] = compute_bonds - app.config["multiprocessing"] = multiprocessing url = f"http://127.0.0.1:{port}" file_io = FileIO(filename, start, stop, step) @@ -75,9 +68,10 @@ def view( print(f"Starting ZnDraw server at {url}") if wv is not None and webview: - multiprocessing.Process( + wv_proc = mp.Process( target=_view_with_webview, args=(url, fullscreen), daemon=True - ).start() + ) + wv_proc.start() elif open_browser: webbrowser.open(url) @@ -95,4 +89,6 @@ def view( proc.terminate() proc.join() - # raise ValueError("ZnDraw server stopped unexpectedly") + if wv is not None and webview: + wv_proc.terminate() + wv_proc.join() diff --git a/zndraw/zndraw.py b/zndraw/zndraw.py index 748a31b7b..b3f44c3ea 100644 --- a/zndraw/zndraw.py +++ b/zndraw/zndraw.py @@ -62,7 +62,7 @@ class FileIO: @dataclasses.dataclass class ZnDrawBase: # collections.abc.MutableSequence url: str - token: str + token: str = "notoken" _target_sid: str = None @@ -417,7 +417,6 @@ class ZnDraw(ZnDrawBase): """ url: str = None - token: str = None jupyter: bool = False display_new: bool = True @@ -441,7 +440,6 @@ def __post_init__(self): "stop": None, "step": 1, "compute_bonds": True, - "multiprocessing": False, }, ) self._view_thread.start()