use of org.python.core.PySystemState in project yamcs-studio by yamcs.
the class ExecutePythonScriptAction method run.
@Override
public void run() {
if (code == null) {
try {
ScriptStoreFactory.initPythonInterpreter();
} catch (Exception e) {
final String message = "Failed to initialize PythonInterpreter";
OPIBuilderPlugin.getLogger().log(Level.WARNING, message, e);
// $NON-NLS-1$
ConsoleService.getInstance().writeError(message + "\n" + e);
}
// read file
IPath absolutePath = getAbsolutePath();
state = new PySystemState();
// Add the path of script to python module search path
if (!isEmbedded() && absolutePath != null && !absolutePath.isEmpty()) {
// If it is a workspace file.
if (ResourceUtil.isExistingWorkspaceFile(absolutePath)) {
IPath folderPath = absolutePath.removeLastSegments(1);
String sysLocation = ResourceUtil.workspacePathToSysPath(folderPath).toOSString();
state.path.append(new PyString(sysLocation));
} else if (ResourceUtil.isExistingLocalFile(absolutePath)) {
IPath folderPath = absolutePath.removeLastSegments(1);
state.path.append(new PyString(folderPath.toOSString()));
}
}
interpreter = new PythonInterpreter(null, state);
GraphicalViewer viewer = getWidgetModel().getRootDisplayModel().getViewer();
if (viewer != null) {
Object obj = viewer.getEditPartRegistry().get(getWidgetModel());
if (obj != null && obj instanceof AbstractBaseEditPart) {
displayEditpart = (DisplayEditpart) (viewer.getContents());
widgetEditPart = (AbstractBaseEditPart) obj;
}
}
}
Job job = new Job("Execute Python Script") {
@Override
protected IStatus run(IProgressMonitor monitor) {
String taskName = isEmbedded() ? "Execute Python Script" : "Connecting to " + getAbsolutePath();
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
runTask();
monitor.done();
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
Aggregations