use of org.csstudio.display.builder.model.properties.ScriptPV 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.ScriptPV 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.ScriptPV in project org.csstudio.display.builder by kasemir.
the class RulesTest method testValueAsExpression.
/**
* Rules that uses the value of a PV within an expression
*/
@Test
public void testValueAsExpression() throws Exception {
final Widget widget = new ImageWidget();
final RuleInfo rule = new RuleInfo("WidthFromPV", "data_width", true, Arrays.asList(new RuleInfo.ExprInfoString("true", "pv0")), Arrays.asList(new ScriptPV("XSize")));
System.out.println(rule);
final String script = RuleToScript.generatePy(widget, rule);
System.out.println(script);
// Script must read the PV
assertThat(script, containsString("PVUtil.get"));
}
use of org.csstudio.display.builder.model.properties.ScriptPV in project org.csstudio.display.builder by kasemir.
the class RulesTest method testColorRule.
/**
* Rule that uses color
*/
@Test
public void testColorRule() throws Exception {
final LabelWidget widget = new LabelWidget();
final WidgetProperty<WidgetColor> color = widget.propForegroundColor().clone();
color.setValue(new WidgetColor(1, 2, 3));
final RuleInfo rule = new RuleInfo("Color", "foreground_color", false, Arrays.asList(new RuleInfo.ExprInfoValue<WidgetColor>("pv0 > 10", color)), Arrays.asList(new ScriptPV("Whatever")));
System.out.println(rule);
final String script = RuleToScript.generatePy(widget, rule);
System.out.println(script);
// Script must create variables for colors
assertThat(script, containsString("colorVal"));
}
use of org.csstudio.display.builder.model.properties.ScriptPV in project org.csstudio.display.builder by kasemir.
the class RulesTest method testValueForCondition.
/**
* Rule that checks pv0>10 and picks a certain value for that
*/
@Test
public void testValueForCondition() throws Exception {
final ImageWidget widget = new ImageWidget();
final WidgetProperty<Integer> width = widget.propDataWidth().clone();
width.setValue(47);
final RuleInfo rule = new RuleInfo("WidthBasedOnPV", "data_width", false, Arrays.asList(new RuleInfo.ExprInfoValue<Integer>("pv0>10", width)), Arrays.asList(new ScriptPV("XSize")));
System.out.println(rule);
final String script = RuleToScript.generatePy(widget, rule);
System.out.println(script);
// Script must read the PV
assertThat(script, containsString("pv0 = PVUtil.getDouble(pvs[0])"));
}
Aggregations