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 d114090
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 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 @@ -1197,6 +1198,8 @@ def init(
ij = imagej.init("sc.fiji:fiji", mode=imagej.Mode.GUI)
"""
global gateway

if headless is not None:
_logger.warning(
"The headless flag of imagej.init is deprecated. "
Expand Down Expand Up @@ -1225,11 +1228,8 @@ def run_callbacks(ij):
return ij

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 +1267,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 d114090

Please sign in to comment.