use of org.csstudio.display.builder.model.properties.ScriptInfo in project org.csstudio.display.builder by kasemir.
the class ExampleModels method createModel.
/**
* @return {@link DisplayModel}
*/
public static DisplayModel createModel() {
final DisplayModel model = new DisplayModel();
model.setPropertyValue(CommonWidgetProperties.propWidth, 1400);
model.setPropertyValue(CommonWidgetProperties.propHeight, 20 * 50);
for (int i = 0; i < 200; ++i) {
final int x = 0 + (i / 20) * 132;
final int y = 0 + (i % 20) * 50;
final GroupWidget group = new GroupWidget();
group.setPropertyValue(CommonWidgetProperties.propName, "Group " + i);
group.setPropertyValue(CommonWidgetProperties.propX, x);
group.setPropertyValue(CommonWidgetProperties.propY, y);
group.setPropertyValue(CommonWidgetProperties.propWidth, 125);
group.setPropertyValue(CommonWidgetProperties.propHeight, 53);
final LabelWidget label = new LabelWidget();
label.setPropertyValue(CommonWidgetProperties.propName, "Label " + i);
label.setPropertyValue(CommonWidgetProperties.propX, 0);
label.setPropertyValue(CommonWidgetProperties.propY, 4);
label.setPropertyValue(CommonWidgetProperties.propWidth, 15);
label.setPropertyValue(CommonWidgetProperties.propHeight, 15);
label.setPropertyValue(CommonWidgetProperties.propText, Integer.toString(i));
group.runtimeChildren().addChild(label);
// For SWT implementation, rect. is not 'transparent',
// so needs to be behind text
final RectangleWidget rect = new RectangleWidget();
rect.setPropertyValue(CommonWidgetProperties.propName, "Rect " + i);
rect.setPropertyValue(CommonWidgetProperties.propX, 10);
rect.setPropertyValue(CommonWidgetProperties.propY, 0);
rect.setPropertyValue(CommonWidgetProperties.propWidth, 80);
rect.setPropertyValue(CommonWidgetProperties.propHeight, 19);
rect.setPropertyValue(CommonWidgetProperties.propScripts, Arrays.asList(new ScriptInfo("../org.csstudio.display.builder.runtime.test/examples/fudge_width.py", true, new ScriptPV("noise"))));
group.runtimeChildren().addChild(rect);
final TextUpdateWidget text = new TextUpdateWidget();
text.setPropertyValue(CommonWidgetProperties.propName, "Text " + i);
text.setPropertyValue(CommonWidgetProperties.propX, 30);
text.setPropertyValue(CommonWidgetProperties.propY, 4);
text.setPropertyValue(CommonWidgetProperties.propWidth, 45);
text.setPropertyValue(CommonWidgetProperties.propHeight, 15);
text.setPropertyValue(CommonWidgetProperties.propPVName, "ramp");
group.runtimeChildren().addChild(text);
model.runtimeChildren().addChild(group);
}
return model;
}
use of org.csstudio.display.builder.model.properties.ScriptInfo in project org.csstudio.display.builder by kasemir.
the class JFXActionsDialogDemo method start.
@Override
public void start(final Stage stage) {
final Widget widget = new Widget("demo");
final Macros macros = new Macros();
macros.add("S", "Test");
macros.add("N", "17");
final ActionInfos actions = new ActionInfos(Arrays.asList(new OpenDisplayActionInfo("Related Display", "../opi/some_file.opi", macros, Target.TAB), new WritePVActionInfo("Reset", "Test:CS:Reset", "1"), new ExecuteScriptActionInfo("Script", new ScriptInfo(ScriptInfo.EMBEDDED_PYTHON, "print 'hi'", false, Collections.emptyList()))));
final ActionsDialog dialog = new ActionsDialog(widget, actions);
final Optional<ActionInfos> result = dialog.showAndWait();
if (result.isPresent()) {
if (result.get().isExecutedAsOne())
System.out.println("Execute all commands as one:");
for (ActionInfo info : result.get().getActions()) {
if (info instanceof ExecuteScriptActionInfo) {
final ExecuteScriptActionInfo action = (ExecuteScriptActionInfo) info;
System.out.println("Execute " + action.getDescription() + ", " + action.getInfo() + ": " + action.getInfo().getText());
} else
System.out.println(info);
}
} else
System.out.println("Cancelled");
}
use of org.csstudio.display.builder.model.properties.ScriptInfo in project org.csstudio.display.builder by kasemir.
the class JFXScriptsDialogDemo method start.
@Override
public void start(final Stage stage) {
final List<ScriptInfo> scripts = new ArrayList<>();
scripts.add(new ScriptInfo("/tmp/demo1.py", true, new ScriptPV("pv1")));
scripts.add(new ScriptInfo("/tmp/demo2.py", false, new ScriptPV("pv1"), new ScriptPV("pv2", false)));
final ScriptsDialog dialog = new ScriptsDialog(new Widget("demo"), scripts);
final Optional<List<ScriptInfo>> result = dialog.showAndWait();
if (result.isPresent()) {
for (ScriptInfo info : result.get()) System.out.println(info + ", embedded text: " + info.getText());
} else
System.out.println("Cancelled");
}
use of org.csstudio.display.builder.model.properties.ScriptInfo in project org.csstudio.display.builder by kasemir.
the class WidgetRuntime method startScripts.
/**
* Start Scripts
*/
private void startScripts() {
// Start scripts triggered by PVs
final List<ScriptInfo> script_infos = widget.propScripts().getValue();
final List<RuleInfo> rule_infos = widget.propRules().getValue();
if ((script_infos.size() > 0) || (rule_infos.size() > 0)) {
final List<RuntimeScriptHandler> handlers = new ArrayList<>(script_infos.size() + rule_infos.size());
for (final ScriptInfo script_info : script_infos) {
try {
handlers.add(new RuntimeScriptHandler(widget, script_info));
} catch (final Exception ex) {
final StringBuilder buf = new StringBuilder();
buf.append("Script failed to compile\n");
try {
final DisplayModel model = widget.getDisplayModel();
buf.append("Display '").append(model.getDisplayName()).append("', ");
} catch (Exception ignore) {
// Skip display model
}
buf.append(widget).append(", ").append(script_info.getPath());
logger.log(Level.WARNING, buf.toString(), ex);
}
}
for (final RuleInfo rule_info : rule_infos) {
try {
handlers.add(new RuntimeScriptHandler(widget, rule_info));
} catch (final Exception ex) {
final StringBuilder buf = new StringBuilder();
buf.append("Rule failed to compile\n");
try {
final DisplayModel model = widget.getDisplayModel();
buf.append("Display '").append(model.getDisplayName()).append("', ");
} catch (Exception ignore) {
// Skip display model
}
buf.append(widget).append(", ").append(rule_info.getName());
logger.log(Level.WARNING, buf.toString(), ex);
}
}
script_handlers = handlers;
}
// Compile scripts invoked by actions
final List<ActionInfo> actions = widget.propActions().getValue().getActions();
if (actions.size() > 0) {
final Map<ExecuteScriptActionInfo, Script> scripts = new HashMap<>();
for (ActionInfo action_info : actions) {
if (!(action_info instanceof ExecuteScriptActionInfo))
continue;
final ExecuteScriptActionInfo script_action = (ExecuteScriptActionInfo) action_info;
try {
final MacroValueProvider macros = widget.getMacrosOrProperties();
final Script script = RuntimeScriptHandler.compileScript(widget, macros, script_action.getInfo());
scripts.put(script_action, script);
} catch (final Exception ex) {
final StringBuilder buf = new StringBuilder();
buf.append("Script for action failed to compile\n");
try {
final DisplayModel model = widget.getDisplayModel();
buf.append("Display '").append(model.getDisplayName()).append("', ");
} catch (Exception ignore) {
// Skip display model
}
buf.append(widget).append(", ").append(script_action);
logger.log(Level.WARNING, buf.toString(), ex);
}
}
if (scripts.size() > 0)
action_scripts = scripts;
}
// Signal that start() has completed
started.countDown();
}
use of org.csstudio.display.builder.model.properties.ScriptInfo in project org.csstudio.display.builder by kasemir.
the class ScriptsDialog method getScriptImage.
private ImageView getScriptImage(ScriptItem item) {
ImageView imageView = null;
if (item != null) {
final ScriptInfo info = item.getScriptInfo();
if (info != null) {
final String path = info.getPath();
if (ScriptInfo.isEmbedded(path)) {
if (ScriptInfo.isJavaScript(path))
imageView = JFXUtil.getIcon("javascript.png");
else if (ScriptInfo.isJython(path))
imageView = JFXUtil.getIcon("python.png");
else
// It should never happen.
imageView = JFXUtil.getIcon("unknown.png");
} else {
if (ScriptInfo.isJavaScript(path))
imageView = JFXUtil.getIcon("file-javascript.png");
else if (ScriptInfo.isJython(path))
imageView = JFXUtil.getIcon("file-python.png");
else
// It should never happen.
imageView = JFXUtil.getIcon("file-unknown.png");
}
}
}
if (imageView != null) {
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
}
return imageView;
}
Aggregations