Skip to content

Commit

Permalink
Always initialize the gateway attribute
Browse files Browse the repository at this point in the history
The global gateway attribute is only created on macOS
in GUI mode. This commit moves the gateway attribute to
the module scope and attaches the gateway from the
_create_gateway() for all modes. This makes it possible
to access the last initialized ImageJ gateway by accessing
the gateway attribute of the imagej module.
  • Loading branch information
elevans committed Jul 15, 2024
1 parent d0eed46 commit ec41fe6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/imagej/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
__author__ = "ImageJ2 developers"
__version__ = sj.get_version("pyimagej")

gateway = None
_logger = logging.getLogger(__name__)
_init_callbacks = []
_rai_lock = threading.Lock()
Expand Down Expand Up @@ -1224,12 +1225,10 @@ def run_callbacks(ij):
callback(ij)
return ij

global gateway
if mode == Mode.GUI:
# Show the GUI and block.
global gateway

def show_gui_and_run_callbacks():
global gateway
gateway = _create_gateway()
gateway.ui().showUI()
run_callbacks(gateway)
Expand Down Expand Up @@ -1267,7 +1266,9 @@ def show_gui_and_run_callbacks():
return gateway

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

return run_callbacks(gateway)


def when_imagej_starts(f) -> None:
Expand Down

0 comments on commit ec41fe6

Please sign in to comment.