Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callback mechanism for GUI mode #301

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
18 changes: 9 additions & 9 deletions src/imagej/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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
elevans marked this conversation as resolved.
Show resolved Hide resolved
return None
return gateway

# HEADLESS or INTERACTIVE mode: create the gateway and return it.
return run_callbacks(_create_gateway())
Expand Down