44
44
import javax .script .ScriptException ;
45
45
46
46
import org .scijava .Context ;
47
+ import org .scijava .command .CommandService ;
47
48
import org .scijava .log .LogService ;
48
49
import org .scijava .object .ObjectService ;
49
50
import org .scijava .plugin .Parameter ;
@@ -65,6 +66,9 @@ public class PythonScriptEngine extends AbstractScriptEngine {
65
66
@ Parameter
66
67
private LogService logService ;
67
68
69
+ @ Parameter
70
+ private CommandService commandService ;
71
+
68
72
public PythonScriptEngine (final Context context ) {
69
73
context .inject (this );
70
74
setLogService (logService );
@@ -78,10 +82,13 @@ public Object eval(final String script) throws ScriptException {
78
82
.filter (obj -> "PythonScriptRunner" .equals (objectService .getName (obj )))//
79
83
.findFirst ();
80
84
if (!pythonScriptRunner .isPresent ()) {
85
+ // Try to help user by running OptionsPython plugin
86
+ if (commandService != null ) {
87
+ commandService .run (OptionsPython .class , true );
88
+ }
81
89
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." );
85
92
}
86
93
return pythonScriptRunner .get ().apply (new Args (script , engineScopeBindings ,
87
94
scriptContext ));
0 commit comments