kasemir / org.csstudio.display.builder

Update of org.csstudio.opibuilder.*
Eclipse Public License 1.0
2 stars 10 forks source link

Problem with generating widgets via script #557

Closed jevarlec closed 4 years ago

jevarlec commented 4 years ago

I wish to use a script to generate a large amount of widgets. To test this, I made the following test script:

from org.csstudio.display.builder.model import ChildrenProperty
from org.csstudio.display.builder.model.widgets import EmbeddedDisplayWidget

ypos = 0

children = ChildrenProperty.getChildren(widget)

for _ in range(10):

    wgt = EmbeddedDisplayWidget()

    wgt.setPropertyValue('resize', EmbeddedDisplayWidget.Resize.SizeToContent)
    wgt.setPropertyValue('y', ypos)
    wgt.setPropertyValue('file', 'digital_display.bob')
    ypos += 30

    children.addChild(wgt)

widget.setPropertyValue('children', children)
widget.setPropertyValue('height', ypos)

This script is then attached to a Group widget. When the display with the Group widget with the script is executed, Phoebus returns the following output:

at java.base/java.lang.reflect.Method.invoke(Method.java:566)
java.lang.UnsupportedOperationException: java.lang.UnsupportedOperationException: Use ChildrenProperty#addChild()/removeChild()

It seems to me that widget.setPropertyValue('children', children) is the culprit. It also says in the ChildrenProperty.java:

/** 'children' is a property to allow notifications,
     *  but setting its value or creating additional property instances
     *  is not supported.
     *
     *  <p>All access must be via the ContainerWidget.add/removeChild() methods.
     *
     *  <p>Notifications are sent with a list of elements added or removed,
     *  <u>not</u> the complete old resp. new value.
     */

But where is ContainerWidget? How do I add children to the Group widget or Display, since those do not have addChild/removeChild methods? Using BOY, one could call widget.getChildren, widget.addChild or widget.removeChild, so it was relatively simple. What is the standard way to do it with Display Builder?

And now the funny part: The widgets still get generated, even though there is an exception. But if you scroll down with the mouse cursor over the widget, it disappears. It reappears if you scroll up with cursor over the space where widget was located. But I am unsure if this is connected to the issue above.

Thank you for your help.

kasemir commented 4 years ago

Install the examples, then check for instance https://github.com/ControlSystemStudio/phoebus/tree/master/app/display/model/src/main/resources/examples/template_and_script where create_instances.py shows how to create widgets and add them.

jevarlec commented 4 years ago

Thanks, using widget.runtimeChildren().addChild(wgt) has indeed solved the exception issue.

But the other issue (the funny part) remains. Shall I open a new issue on github, or can we use this one?

kasemir commented 4 years ago

Can you package this as an example, for example one 'main.bob' with the script, one 'digital_display.bob' with the content of the embedded widget, all using loc:... or sim:... PVs for standalone testing/debugging?

jevarlec commented 4 years ago

script-test.tar.gz

I tested this with Phoebus and Eclipse based CSS.

Thanks for your help.

kasemir commented 4 years ago

Thanks for the example. Seems to work fine. What's the problem? I see nothing vanish when I move the mouse or scroll.

Screen Shot 2020-08-03 at 9 54 50 AM

jevarlec commented 4 years ago

I managed to reproduce it on a different machine. If you put your mouse over the embedded display widget and scroll down, it does not disappear? That's interesting. I will try to provide video.

kasemir commented 4 years ago

Yes. The up/down scrollbar works, you can also use the mouse wheel to scroll up/down when the mouse is in most of the display, but the mouse wheel cannot scroll up/down when your mouse pointer is on top of the embedded display because of https://github.com/ControlSystemStudio/phoebus/pull/1363 and https://github.com/ControlSystemStudio/phoebus/issues/1355. When the embedded content is larger so that the embedded display itself has a scroll bar, then the mouse wheel will scroll within that embedded display.

kasemir commented 4 years ago

When you run this display with an older version of the display builder, like the one for the Eclipse-based CS-Studio instead of the one for phoebus, then you can accidentally 'scroll' the content of the embedded display out of view, which is what has been fixed in the updates mentioned below, but only for the Phoebus-based sources.

jevarlec commented 4 years ago

That's it, thanks for all the help.