Skip to content

Commit 9d9f8a9

Browse files
Show error dialog if there is no PythonScriptRunner
Currently the PythonScriptRunner is not integrated into the ImageJ Launcher so it is only available if Fiji is launched from python and it is inserted in the ObjectService. Now we provide an error message if it is not found in the ObjectService.
1 parent dbee7bd commit 9d9f8a9

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/main/java/org/scijava/plugins/scripting/python/PythonScriptEngine.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@
3737
import java.util.Set;
3838

3939
import javax.script.Bindings;
40-
import javax.script.ScriptException;
4140
import javax.script.ScriptEngine;
42-
import org.scijava.script.AbstractScriptEngine;
41+
import javax.script.ScriptException;
42+
4343
import org.scijava.Context;
4444
import org.scijava.log.LogService;
4545
import org.scijava.object.ObjectService;
4646
import org.scijava.plugin.Parameter;
47-
import org.scijava.plugins.scripting.python.PythonScriptRunner;
47+
import org.scijava.script.AbstractScriptEngine;
48+
import org.scijava.ui.DialogPrompt;
49+
import org.scijava.ui.UIService;
4850

4951
/**
5052
* A script engine for conda-based python.
@@ -60,6 +62,9 @@ public class PythonScriptEngine extends AbstractScriptEngine {
6062

6163
@Parameter
6264
LogService logService;
65+
66+
@Parameter
67+
UIService uiService;
6368

6469
public PythonScriptEngine(Context context) {
6570
context.inject(this);
@@ -69,7 +74,13 @@ public PythonScriptEngine(Context context) {
6974

7075
@Override
7176
public Object eval(String script) throws ScriptException {
72-
return objectService.getObjects(PythonScriptRunner.class).get(0).run(script, engineScopeBindings, scriptContext);
77+
if (objectService.getObjects(PythonScriptRunner.class).stream().count() > 0)
78+
return objectService.getObjects(PythonScriptRunner.class).get(0).run(script, engineScopeBindings, scriptContext);
79+
80+
uiService.showDialog("The PythonScriptRunner could not be found in the ObjectService. To use the\n" +
81+
"Conda Python 3 script engine Fiji must be launched from python inside a conda\n " +
82+
"environment and a PythonScriptRunner must be added to the ObjectService.\n", DialogPrompt.MessageType.ERROR_MESSAGE);
83+
return null;
7384
}
7485

7586
@Override

0 commit comments

Comments
 (0)