Skip to content

Commit bc24da1

Browse files
committed
Open Python options when scripts fail
Closes #13
1 parent 21037bf commit bc24da1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import javax.script.ScriptException;
4545

4646
import org.scijava.Context;
47+
import org.scijava.command.CommandService;
4748
import org.scijava.log.LogService;
4849
import org.scijava.object.ObjectService;
4950
import org.scijava.plugin.Parameter;
@@ -65,6 +66,9 @@ public class PythonScriptEngine extends AbstractScriptEngine {
6566
@Parameter
6667
private LogService logService;
6768

69+
@Parameter
70+
private CommandService commandService;
71+
6872
public PythonScriptEngine(final Context context) {
6973
context.inject(this);
7074
setLogService(logService);
@@ -78,10 +82,13 @@ public Object eval(final String script) throws ScriptException {
7882
.filter(obj -> "PythonScriptRunner".equals(objectService.getName(obj)))//
7983
.findFirst();
8084
if (!pythonScriptRunner.isPresent()) {
85+
// Try to help user by running OptionsPython plugin
86+
if (commandService != null) {
87+
commandService.run(OptionsPython.class, true);
88+
}
8189
throw new IllegalStateException(//
82-
"The PythonScriptRunner could not be found in the ObjectService. To use the\n" +
83-
"Python script engine, you must call scyjava.enable_scijava_scripting(context)\n" +
84-
"with this script engine's associated SciJava context before using it.");
90+
"The PythonScriptRunner could not be found.\n" +
91+
"To use the Python script engine, you must launch your application in Python mode.");
8592
}
8693
return pythonScriptRunner.get().apply(new Args(script, engineScopeBindings,
8794
scriptContext));

0 commit comments

Comments
 (0)