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

PyDMRelatedDisplayButton not storing/loading its macros properly #973

Open
rcardenes opened this issue Feb 17, 2023 · 2 comments
Open

PyDMRelatedDisplayButton not storing/loading its macros properly #973

rcardenes opened this issue Feb 17, 2023 · 2 comments
Assignees
Labels

Comments

@rcardenes
Copy link

I'm designing a form with some related display buttons. I tried including a couple of macros (as the related forms are supposed to be generic). I did this through the Basic Settings Editor to make sure I didn't mess with the internal representation, and I managed to save macros, but when trying to open the Settings Editor again I was greeted with:

Failed to parse macro string: ['{"top": "FooBar"}']
Traceback (most recent call last):
  File "/home/software/venv/3.9.6/sysco/lib/python3.9/site-packages/pydm/utilities/macro.py", line 63, in parse_macro_string
    macros = json.loads(macro_string)
  File "/home/software/.pyenv/versions/3.9.6/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/home/software/.pyenv/versions/3.9.6/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/home/software/.pyenv/versions/3.9.6/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/software/venv/3.9.6/sysco/lib/python3.9/site-packages/pydm/widgets/designer_settings.py", line 261, in set_value_from_widget
    macros = parse_macro_string(value or "")
  File "/home/software/venv/3.9.6/sysco/lib/python3.9/site-packages/pydm/utilities/macro.py", line 67, in parse_macro_string
    raise ValueError("Could not parse macro argument as JSON.")
ValueError: Could not parse macro argument as JSON.

This works for PyDMEmbeddedDisplay though.

The main difference I see here is that PyDMEmbeddedDisplay stores the macros as a dictionary encoded as simple JSON string, where PyDMRelatedDisplayButton stores them as a list of strings. When restoring the macros, there's no problem with the simple string, but the code chokes on the list of strings.

Now, I'm not sure why the difference in storage choices, because there seems to be no good reason for PyDMRelatedDisplayButton to keep a list where a simple string would do, but you might have some insight that is escaping me :-)

Steps to Reproduce

  1. Create an empty form
  2. Add a PyDMRelatedDisplayButton
  3. Double click on it to open the Basic Settings Editor
  4. Add a macro
  5. Save the settings and close the Editor
  6. Reopen the Settings Editor form

Possible Solution
Change the storage choice for PyDMRelatedDisplayButton? It seems like using a simple string works fine for PyDMEmbeddedDisplay

My Platform
Happened on Linux, Python 3.9, latest stable PyDM (1.18.2)

@jbellister-slac
Copy link
Collaborator

Thank you for bringing this up! The reason macros are stored differently from the embedded display is that a related display button can have multiple files assigned to it. So for example a single button can have say four displays added to it, which the user can choose from when clicking the button at run time. And in this case the first macro string in the list would go to the first display, the second to the second, and so on. It's a way to be able to send a different set of macros to each display in case just having the same set shared among each display on the button would cause conflicts.

Haven't taken a look into the code yet, but I think we'll probably just need to update the basic settings editor to handle this case.

It the mean time, assigning macros using the Property Editor in the right panel should work, although not as nice of an interface.

@jbellister-slac jbellister-slac self-assigned this Feb 17, 2023
@rcardenes
Copy link
Author

I see. I'll try using the other editor and see what happens.

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

No branches or pull requests

2 participants