diff --git a/src/imagej/__init__.py b/src/imagej/__init__.py index 8fc174bf..cc5614eb 100644 --- a/src/imagej/__init__.py +++ b/src/imagej/__init__.py @@ -1125,6 +1125,7 @@ def init( ij_dir_or_version_or_endpoint=None, mode: Union[Mode, str] = Mode.HEADLESS, add_legacy=True, + override=False, headless=None, ): """Initialize an ImageJ2 environment. @@ -1183,6 +1184,13 @@ def init( the JVM and Python will both terminate when ImageJ closes! For further details, see: https://imagej.net/libs/imagej-legacy + :param override: + + Whether or not to override initialization blocks. If True, + unsupported/application breaking behavior, such as interactive mode on + macOS, will be possible. If False, initialization blocks preventing + unsupported/application breaking behavior are active. + :param headless: Deprecated. Please use the mode parameter instead. @@ -1205,7 +1213,7 @@ def init( macos = sys.platform == "darwin" - if macos and mode == Mode.INTERACTIVE and _is_main_thread(): + if macos and mode == Mode.INTERACTIVE and not override: raise EnvironmentError("Sorry, the interactive mode is not available on macOS.") if not sj.jvm_started(): @@ -1517,14 +1525,6 @@ def _includes_imagej_legacy(items: list): return any(item.startswith("net.imagej:imagej-legacy") for item in items) -def _is_main_thread(): - """Detect if on main thread running on the main thread. - - :return: Boolean indicating if the current thread is the main thread. - """ - return threading.current_thread() == threading.main_thread() - - def _set_ij_env(ij_dir): """ Create a list of required jars and add to the java classpath.