diff --git a/pom.xml b/pom.xml index 0437627..d1d7b2d 100644 --- a/pom.xml +++ b/pom.xml @@ -100,6 +100,7 @@ org.scijava scijava-common + 2.100.0-SNAPSHOT org.scijava diff --git a/src/main/java/org/scijava/plugins/scripting/python/PythonScriptLanguage.java b/src/main/java/org/scijava/plugins/scripting/python/PythonScriptLanguage.java index f1c4417..b72c9a9 100644 --- a/src/main/java/org/scijava/plugins/scripting/python/PythonScriptLanguage.java +++ b/src/main/java/org/scijava/plugins/scripting/python/PythonScriptLanguage.java @@ -29,12 +29,16 @@ package org.scijava.plugins.scripting.python; +import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.List; +import java.util.Map; import javax.script.ScriptEngine; import org.scijava.Priority; +import org.scijava.launcher.Config; import org.scijava.plugin.Plugin; import org.scijava.script.AbstractScriptLanguage; import org.scijava.script.ScriptLanguage; @@ -47,9 +51,32 @@ * @see ScriptEngine */ @Plugin(type = ScriptLanguage.class, name = "Python (pyimagej)", - priority = Priority.VERY_LOW) + priority = Priority.VERY_HIGH) public class PythonScriptLanguage extends AbstractScriptLanguage { + private Boolean isActive = null; + + @Override + public boolean isActive() { + if (isActive == null) { + String configFileProp = System.getProperty("scijava.app.config-file"); + File configFile = configFileProp == null ? null : new File( + configFileProp); + if (configFile != null && configFile.canRead()) { + try { + final Map config = Config.load(configFile); + + final String cfgLaunchMode = config.get("launch-mode"); + if (cfgLaunchMode != null) isActive = cfgLaunchMode.equals("PYTHON"); + } + catch (IOException e) { + // Proceed gracefully if config file is not accessible. + } + } + } + return (isActive == null) ? false : isActive; + } + @Override public String getEngineName() { return "python";