From 745f00b28b1e9bd64b188d18f184afe3238977a2 Mon Sep 17 00:00:00 2001 From: Gabriel Selzer Date: Thu, 25 May 2023 15:35:10 -0500 Subject: [PATCH] Create gateway, run callbacks in same function --- src/imagej/__init__.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/imagej/__init__.py b/src/imagej/__init__.py index eb16a533..25bf753d 100644 --- a/src/imagej/__init__.py +++ b/src/imagej/__init__.py @@ -1223,15 +1223,17 @@ def run_callbacks(ij): # Show the GUI and block. global gateway - def show_gui_and_run_callbacks(ij): - ij.ui().showUI() - run_callbacks(ij) + def show_gui_and_run_callbacks(): + global gateway + gateway = _create_gateway() + gateway.ui().showUI() + run_callbacks(gateway) + return gateway if macos: # NB: This will block the calling (main) thread forever! try: - gateway = _create_gateway() - setupGuiEnvironment(lambda: show_gui_and_run_callbacks(gateway)) + setupGuiEnvironment(show_gui_and_run_callbacks) except ModuleNotFoundError as e: if e.msg == "No module named 'PyObjCTools'": advice = ( @@ -1251,15 +1253,13 @@ def show_gui_and_run_callbacks(ij): raise else: # Create and show the application. - gateway = _create_gateway() - show_gui_and_run_callbacks(gateway) + gateway = show_gui_and_run_callbacks() # We are responsible for our own blocking. # TODO: Poll using something better than ui().isVisible(). while gateway.ui().isVisible(): time.sleep(1) - del gateway - return None + return gateway # HEADLESS or INTERACTIVE mode: create the gateway and return it. return run_callbacks(_create_gateway())