Skip to content

Commit

Permalink
On macOS with headless=False, show the GUI
Browse files Browse the repository at this point in the history
This uses jpype.setupGuiEnvironment. It works, but:

* You must have pyobjc installed from pip
  (conda packages did not work for me).

* With this change, it is now inconsistent whether
  imagej.init(headless=False) pops a GUI or not. On macOS yes, on
  Linux and Windows no, with ij.ui().showUI() needing to be called.

* This change does not fix the fact that imagej.init(headless=False)
  is non-blocking on Linux and Windows, but blocking on macOS. This
  is because on macOS the main thread must eternal stay busy doing
  the console event loop from this point forward.

See #23.
  • Loading branch information
ctrueden committed Dec 7, 2021
1 parent 27aea88 commit f54e59e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions imagej/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

from pathlib import Path

from jpype import JArray, JException, JImplementationFor, JObject
from jpype import JArray, JException, JImplementationFor, JObject, setupGuiEnvironment

from .config import __author__, __version__

Expand Down Expand Up @@ -121,7 +121,11 @@ def init(ij_dir_or_version_or_endpoint=None, headless=True, add_legacy=True):
ij = imagej.init('sc.fiji:fiji', headless=False)
"""
_create_jvm(ij_dir_or_version_or_endpoint, headless, add_legacy)
return _create_gateway()
if sys.platform == 'darwin' and not headless:
# NB: This will block the calling (main) thread forever!
setupGuiEnvironment(lambda: _create_gateway().ui().showUI())
else:
return _create_gateway()


def _create_jvm(ij_dir_or_version_or_endpoint, headless, add_legacy):
Expand Down

0 comments on commit f54e59e

Please sign in to comment.