Search in sources :

Example 1 with ScriptInfo

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;
}
Also used : RectangleWidget(org.csstudio.display.builder.model.widgets.RectangleWidget) DisplayModel(org.csstudio.display.builder.model.DisplayModel) ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) TextUpdateWidget(org.csstudio.display.builder.model.widgets.TextUpdateWidget)

Example 2 with ScriptInfo

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");
}
Also used : ActionsDialog(org.csstudio.display.builder.representation.javafx.ActionsDialog) ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) Widget(org.csstudio.display.builder.model.Widget) ActionInfos(org.csstudio.display.builder.model.properties.ActionInfos) ActionInfo(org.csstudio.display.builder.model.properties.ActionInfo) WritePVActionInfo(org.csstudio.display.builder.model.properties.WritePVActionInfo) ExecuteScriptActionInfo(org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) ExecuteScriptActionInfo(org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo) Macros(org.csstudio.display.builder.model.macros.Macros) WritePVActionInfo(org.csstudio.display.builder.model.properties.WritePVActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)

Example 3 with ScriptInfo

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");
}
Also used : ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) ArrayList(java.util.ArrayList) Widget(org.csstudio.display.builder.model.Widget) ScriptsDialog(org.csstudio.display.builder.representation.javafx.ScriptsDialog) List(java.util.List) ArrayList(java.util.ArrayList) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV)

Example 4 with ScriptInfo

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();
}
Also used : Script(org.csstudio.display.builder.runtime.script.internal.Script) HashMap(java.util.HashMap) ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) ArrayList(java.util.ArrayList) ActionInfo(org.csstudio.display.builder.model.properties.ActionInfo) WritePVActionInfo(org.csstudio.display.builder.model.properties.WritePVActionInfo) ExecuteScriptActionInfo(org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo) ExecuteScriptActionInfo(org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo) MacroValueProvider(org.csstudio.display.builder.model.macros.MacroValueProvider) DisplayModel(org.csstudio.display.builder.model.DisplayModel) RuntimeScriptHandler(org.csstudio.display.builder.runtime.script.internal.RuntimeScriptHandler) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo)

Example 5 with ScriptInfo

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;
}
Also used : ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) ImageView(javafx.scene.image.ImageView)

Aggregations

ScriptInfo (org.csstudio.display.builder.model.properties.ScriptInfo)6 ExecuteScriptActionInfo (org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo)3 ArrayList (java.util.ArrayList)2 DisplayModel (org.csstudio.display.builder.model.DisplayModel)2 Widget (org.csstudio.display.builder.model.Widget)2 ActionInfo (org.csstudio.display.builder.model.properties.ActionInfo)2 ScriptPV (org.csstudio.display.builder.model.properties.ScriptPV)2 WritePVActionInfo (org.csstudio.display.builder.model.properties.WritePVActionInfo)2 HashMap (java.util.HashMap)1 List (java.util.List)1 ImageView (javafx.scene.image.ImageView)1 MacroValueProvider (org.csstudio.display.builder.model.macros.MacroValueProvider)1 Macros (org.csstudio.display.builder.model.macros.Macros)1 ActionInfos (org.csstudio.display.builder.model.properties.ActionInfos)1 OpenDisplayActionInfo (org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)1 RuleInfo (org.csstudio.display.builder.model.rules.RuleInfo)1 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)1 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)1 RectangleWidget (org.csstudio.display.builder.model.widgets.RectangleWidget)1 TextUpdateWidget (org.csstudio.display.builder.model.widgets.TextUpdateWidget)1