use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class RulesJythonScriptTest method testJythonScript.
@Test
public void testJythonScript() throws Exception {
final DisplayModel display = ModelLoader.resolveAndLoadModel("../org.csstudio.display.builder.runtime.test/examples/dummy.opi", "rules_test.opi");
final Widget widget = display.getChildren().parallelStream().filter(w -> w.getName().equals("Rectangle")).findFirst().get();
System.out.println(widget);
String pv_name = "loc://test2";
PVPool.addPVFactory(new LocalPVFactory());
final PV pv = PVPool.getPV(pv_name);
pv.write(1);
// Set widget variable in script
// final ScriptSupport scripting = new ScriptSupport();
// final Script script = scripting.compile("../org.csstudio.display.builder.runtime.test/examples/updateText.py");
/*
for (int run=0; run<10; ++run)
{
widget.setPropertyValue("text", "Initial");
String text = widget.getPropertyValue("text");
assertThat(text, equalTo("Initial"));
script.submit(widget).get();
assertThat(widget.getPropertyValue("text"), equalTo("Hello"));
widget.setPropertyValue("text", "Initial");
assertThat(widget.getPropertyValue("text"), equalTo("Initial"));
script.submit(widget).get();
assertThat(widget.getPropertyValue("text"), equalTo("Hello"));
}
scripting.close();
*/
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class RuntimeDemoSWT method loadModel.
private void loadModel(final Display display) {
try {
final DisplayModel model = ModelLoader.resolveAndLoadModel("examples/dummy.opi", Settings.display_path);
// Representation needs to be created in UI thread
toolkit.execute(() -> representModel(display, model));
} catch (final Exception ex) {
logger.log(Level.SEVERE, "Cannot start", ex);
}
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class RuntimeDemoJavaFX method loadModel.
private void loadModel() {
try {
final DisplayModel model = ModelLoader.resolveAndLoadModel("examples/dummy.opi", Settings.display_path);
// Representation needs to be created in UI thread
toolkit.execute(() -> representModel(model));
} catch (final Exception ex) {
logger.log(Level.SEVERE, "Cannot start", ex);
}
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class ActionUtil method openWebpage.
/**
* Open a web page
* @param source_widget Widget from which the action is invoked.
* Used to resolve the potentially relative path of the
* file specified in the action
* @param action Information on which URL to open
*/
private static void openWebpage(final Widget source_widget, final OpenWebpageActionInfo action) {
if (action.getURL().isEmpty()) {
logger.log(Level.WARNING, "Action without URL: {0}", action);
return;
}
try {
final String resolved_name = resolve(source_widget, action.getURL());
final DisplayModel top_model = source_widget.getTopDisplayModel();
final ToolkitRepresentation<Object, Object> toolkit = ToolkitRepresentation.getToolkit(top_model);
toolkit.execute(() -> {
try {
toolkit.openWebBrowser(resolved_name);
} catch (Exception ex) {
logger.log(Level.WARNING, "Cannot open " + action, ex);
toolkit.showErrorDialog(source_widget, "Cannot open " + resolved_name);
}
});
} catch (final Exception ex) {
logger.log(Level.WARNING, "Error handling " + action, ex);
ScriptUtil.showErrorDialog(source_widget, "Cannot open " + action.getURL() + ".\n\nSee log for details.");
}
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class ActionUtil method executeCommand.
/**
* Execute external command
* @param source_widget Widget from which the action is invoked
* @param action Command action to execute
*/
private static void executeCommand(final Widget source_widget, final ExecuteCommandActionInfo action) {
try {
// Path to resolve, after expanding macros
final Macros macros = source_widget.getEffectiveMacros();
final String command = MacroHandler.replace(macros, action.getCommand());
logger.log(Level.FINER, "{0}, effective macros {1} ({2})", new Object[] { action, macros, command });
// Resolve command relative to the source widget model (not 'top'!)
final DisplayModel widget_model = source_widget.getDisplayModel();
final String parent_file = widget_model.getUserData(DisplayModel.USER_DATA_INPUT_FILE);
final String parent_dir = ModelResourceUtil.getDirectory(ModelResourceUtil.getLocalPath(parent_file));
// Execute (this is already running on background thread)
logger.log(Level.FINE, "Executing command {0} in {1}", new Object[] { command, parent_dir });
final CommandExecutor executor = new CommandExecutor(command, new File(parent_dir));
executor.call();
} catch (final Throwable ex) {
logger.log(Level.WARNING, action + " failed", ex);
ScriptUtil.showErrorDialog(source_widget, "Cannot execute " + action + ".\n\nSee log for details.");
}
}
Aggregations