Search in sources :

Example 1 with PV

use of org.csstudio.vtype.pv.PV 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();
        */
}
Also used : LocalPVFactory(org.csstudio.vtype.pv.local.LocalPVFactory) DisplayModel(org.csstudio.display.builder.model.DisplayModel) PV(org.csstudio.vtype.pv.PV) Widget(org.csstudio.display.builder.model.Widget) Test(org.junit.Test)

Example 2 with PV

use of org.csstudio.vtype.pv.PV in project org.csstudio.display.builder by kasemir.

the class RuntimeDemoSWT method run.

@Override
public void run() {
    final Display display = new Display();
    toolkit = new SWTRepresentation(display);
    RuntimeUtil.hookRepresentationListener(toolkit);
    // Load model in background
    RuntimeUtil.getExecutor().execute(() -> loadModel(display));
    while (!display.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    toolkit.shutdown();
    display.dispose();
    int refs = 0;
    for (final RefCountMap.ReferencedEntry<PV> ref : PVPool.getPVReferences()) {
        refs += ref.getReferences();
        logger.log(Level.SEVERE, "PV {0} left with {1} references", new Object[] { ref.getEntry().getName(), ref.getReferences() });
    }
    if (refs == 0)
        logger.log(Level.FINE, "All PV references were released, good job, get a cookie!");
    // JCA Context remains running, so need to exit() to really quit
    System.exit(0);
}
Also used : SWTRepresentation(org.csstudio.display.builder.representation.swt.SWTRepresentation) PV(org.csstudio.vtype.pv.PV) RefCountMap(org.csstudio.vtype.pv.RefCountMap) Display(org.eclipse.swt.widgets.Display)

Aggregations

PV (org.csstudio.vtype.pv.PV)2 DisplayModel (org.csstudio.display.builder.model.DisplayModel)1 Widget (org.csstudio.display.builder.model.Widget)1 SWTRepresentation (org.csstudio.display.builder.representation.swt.SWTRepresentation)1 RefCountMap (org.csstudio.vtype.pv.RefCountMap)1 LocalPVFactory (org.csstudio.vtype.pv.local.LocalPVFactory)1 Display (org.eclipse.swt.widgets.Display)1 Test (org.junit.Test)1