Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing/hiding DataBrowser widget's tracks from script/rule #401

Open
claudio-rosati opened this issue Jun 11, 2018 · 7 comments
Open

Showing/hiding DataBrowser widget's tracks from script/rule #401

claudio-rosati opened this issue Jun 11, 2018 · 7 comments

Comments

@claudio-rosati
Copy link
Collaborator

Is it possible to show/hide a track of a DataBrowser widget from a script or rule?

@kasemir
Copy link
Owner

kasemir commented Jun 11, 2018

No.

@claudio-rosati
Copy link
Collaborator Author

Is that something that can be easily added to the DataBrowser widget or not?

My colleague Miklós Boros asked me for this possibility as an alternative way of solving the problem detailed in #405.

I have asked him to watch this issue and the #405 one in order to give you a better understanding of the problem, answering to your questions about the issues.

@kasemir
Copy link
Owner

kasemir commented Jun 12, 2018

The display builder widget has a model, representation, and runtime.
The data browser has a similar model, representation (plot) and runtime (controller).
But the two run on a different time line.
The widget's model basically just contains the name of the *.plt file.
The widget's representation then creates the data browser model, plot and controller. This was put into the widget's representation so that the editor could show a preview of the plot.

To get access from a script, the quickest solution would be to add a 'getDataBrowserModel()' method to the data browser widget representation. That would open a way for a script to use widget.getUserData("_representation"). getDataBrowserModel () .. and then modify the data browser's traces etc. Not sure that's a good idea.

@claudio-rosati
Copy link
Collaborator Author

Miklós says that if #405 is fixed, than it can go for another path, using the full DataBrowser to hide/show the tracks and reload the OPI using the .plt file. So maybe #405 is more worth than enabling tracks from the widget.

@kasemir
Copy link
Owner

kasemir commented Jun 19, 2018

Issue 405 regarding the erroneous removal of archive data sources for *.plt setups that contain macros has been fixed.

And there is a way to access the model of the data browser from a script.
The example below shows how to do that for both the older databrowser2, and the JFX-based databrowser3 for the purpose of showing or hiding a selected trace of the data browser when running inside the widget.

# Enable/disable a trace in a Data Browser widget
#
# PVs:
# pvs[0] - PV to enable/disable the trace, e.g. loc://trace0(1)
#          (typically triggers the script)
# pvs[1] - PV for the index of the trace, e.g. loc://index0(0)
#          (typically doesn't need to trigger the script)
from org.csstudio.opibuilder.scriptUtil import PVUtil

enable = PVUtil.getLong(pvs[0]) > 0
index = PVUtil.getLong(pvs[1])
# print("Enable Trace %d: %s" % (index, str(enable)))

# print(widget.__class__.__name__)

if "getDataBrowserModel" in dir(widget):
    # For BOY code that uses databrowser3
    model = widget.getDataBrowserModel()
else:
    # For BOY code that uses databrowser2
    # Hack access to widget.controller.model,
    # which are private fields
    f = widget.getClass().getDeclaredField("controller")
    f.setAccessible(True)
    controller = f.get(widget)
    # print(controller.__class__.__name__)


    f = controller.getClass().getDeclaredField("model")
    f.setAccessible(True)
    model = f.get(controller)
    # print(model.__class__.__name__)

if model.getItems().size() > index:
    model.getItems().get(index).setVisible(enable > 0)

kasemir added a commit to ControlSystemStudio/phoebus that referenced this issue Jun 19, 2018
@kasemir
Copy link
Owner

kasemir commented Jun 19, 2018

Same example now also works with the phoebus version

@claudio-rosati
Copy link
Collaborator Author

Thank you Kay.
I’m in vacation from today for 2 weeks. I’ll integrate the updates as soon as I’ll be back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants