From 8990c9c30a927e9aaab0cbbd53a71d73b6b1fbf3 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Wed, 12 Apr 2023 11:29:32 +0200 Subject: [PATCH] allow python -m netgen.gui to run python tkinter gui from main thread --- python/gui.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/python/gui.py b/python/gui.py index 1cd66155..5c29ab10 100644 --- a/python/gui.py +++ b/python/gui.py @@ -49,10 +49,6 @@ def StartGUI(): _Redraw(blocking=True) -if not netgen.libngpy._meshing._netgen_executable_started: - import os - if not "NETGEN_DOCUMENTATION_RST_FORMAT" in os.environ: - StartGUI() def Snapshot(w,h, filename=None): netgen.Redraw(blocking=True) @@ -65,3 +61,22 @@ def Snapshot(w,h, filename=None): im = PIL.Image.fromarray(image) im.save(filename) return image + +def run_pyfile(filename): + with open(filename) as f: + exec(f.read(), {}) + +if __name__ == "__main__": + import sys, threading + StartGUI() + if(len(sys.argv) > 1): + if(sys.argv[1].endswith(".py")): + t = threading.Thread(target=run_pyfile, args=(sys.argv[1],), + daemon=True) + t.start() + win.mainloop() +else: + if not netgen.libngpy._meshing._netgen_executable_started: + import os + if not "NETGEN_DOCUMENTATION_RST_FORMAT" in os.environ: + StartGUI()