pydm icon indicating copy to clipboard operation
pydm copied to clipboard

pydm application cannot find new widget

Open prjemian opened this issue 2 years ago • 8 comments

Describe the bug

While developing a new PyDMAbsoluteGeometry widget (issue #857, PR #865), received this error when trying the application with a screen file that uses the new widget. (No problems reading this in Qt designer.) Looking for the widget in the wrong place (AttributeError: module 'PyQt5.QtWidgets' has no attribute 'PyDMAbsoluteGeometry') but why?

(dev-pydm) zorinvm@zorin22:~/.../slaclab/pydm$ pydm -m "P=gp:,M=m1" ~/motorxU.ui
Traceback (most recent call last):
  File "/home/zorinvm/Apps/miniconda3/envs/dev-pydm/bin/pydm", line 33, in <module>
    sys.exit(load_entry_point('pydm', 'gui_scripts', 'pydm')())
  File "/home/zorinvm/Documents/projects/slaclab/pydm/pydm_launcher/main.py", line 116, in main
    app = pydm.PyDMApplication(
  File "/home/zorinvm/Documents/projects/slaclab/pydm/pydm/application.py", line 96, in __init__
    self.main_window.open(ui_file, macros, command_line_args)
  File "/home/zorinvm/Documents/projects/slaclab/pydm/pydm/main_window.py", line 335, in open
    new_widget = load_file(filename,
  File "/home/zorinvm/Documents/projects/slaclab/pydm/pydm/display.py", line 66, in load_file
    w = loader(file, args=args, macros=macros)
  File "/home/zorinvm/Documents/projects/slaclab/pydm/pydm/display.py", line 118, in load_ui_file
    _load_ui_into_display(f, d)
  File "/home/zorinvm/Documents/projects/slaclab/pydm/pydm/display.py", line 73, in _load_ui_into_display
    klass, _ = uic.loadUiType(uifile)
  File "/home/zorinvm/Apps/miniconda3/envs/dev-pydm/lib/python3.9/site-packages/PyQt5/uic/__init__.py", line 204, in loadUiType
    return (ui_globals[winfo["uiclass"]], getattr(QtWidgets, winfo["baseclass"]))
AttributeError: module 'PyQt5.QtWidgets' has no attribute 'PyDMAbsoluteGeometry'

Expected behavior widget should be found, no errors

Steps to Reproduce screen file in root of this repo branch

prjemian avatar May 13 '22 20:05 prjemian

So it doesn't seem to like having a custom widget as the top level widget. I couldn't see any issues with your code so I tried doing the same steps with a PyDMFrame instead of PyDMAbsoluteGeometry and got the same result.


Traceback (most recent call last):
  File "/home/jesseb/miniconda3/envs/pydm-environment/bin/pydm", line 8, in <module>
    sys.exit(main())
  <...>
    klass, _ = uic.loadUiType(uifile)
  File "/home/jesseb/miniconda3/envs/pydm-environment/lib/python3.8/site-packages/PyQt5/uic/__init__.py", line 204, in loadUiType
    return (ui_globals[winfo["uiclass"]], getattr(QtWidgets, winfo["baseclass"]))
AttributeError: module 'PyQt5.QtWidgets' has no attribute 'PyDMFrame'

jbellister-slac avatar May 13 '22 20:05 jbellister-slac

That does ring a bell, @jbellister-slac. I had briefly mentioned something like that before but couldn't recall why I thought that was the case.

It's not an obvious thing - it may just be a PyQt designer ui translation-related bug that still has yet to get fixed. Maybe pyqt + qt 5.15 will help? 🤞

klauer avatar May 13 '22 21:05 klauer

Good call on the qt update! I updated locally to 5.15.4 and the sample ui file does indeed open up after that. Unfortunately the test suite was right in that there are multiple compatibility issues right off the bat that make pydm fairly unusable with that version at the moment. I will need to look further into fixing those issues to make the upgrade possible.

jbellister-slac avatar May 13 '22 21:05 jbellister-slac

So it doesn't seem to like having a custom widget as the top level widget. I couldn't see any issues with your code so I tried doing the same steps with a PyDMFrame instead of PyDMAbsoluteGeometry and got the same result.

Not just as a top-level widget. Here, top-level is QWidget, then QHBoxLayout, then PyDMAbsoluteGeometry.

Clipboard01 .

prjemian avatar May 14 '22 15:05 prjemian

Picking a different PyDM widget (random choice: PyDMLogDisplay) and it displays. Clipboard01

note:

(dev-pydm) zorinvm@zorin22:~/.../slaclab/pydm$ conda list qt
# packages in environment at /home/zorinvm/Apps/miniconda3/envs/dev-pydm:
#
# Name                    Version                   Build  Channel
pyqt                      5.12.3           py39hf3d152e_8    conda-forge
pyqt-impl                 5.12.3           py39hde8b62d_8    conda-forge
pyqt5-sip                 4.19.18          py39he80948d_8    conda-forge
pyqtchart                 5.12             py39h0fcd23e_8    conda-forge
pyqtgraph                 0.12.4             pyhd8ed1ab_0    conda-forge
pyqtwebengine             5.12.1           py39h0fcd23e_8    conda-forge
pytest-qt                 4.0.2              pyhd8ed1ab_0    conda-forge
qt                        5.12.9               hda022c4_4    conda-forge
qtpy                      2.0.1              pyhd3eb1b0_0  
sphinxcontrib-qthelp      1.0.3                    pypi_0    pypi

prjemian avatar May 14 '22 15:05 prjemian

Good call on the qt update! I updated locally to 5.15.4 and the sample ui file does indeed open up after that. Unfortunately the test suite was right in that there are multiple compatibility issues right off the bat that make pydm fairly unusable with that version at the moment. I will need to look further into fixing those issues to make the upgrade possible.

How do I make this update locally without ruining my current environment? (the reason for new issue #872)

prjemian avatar May 18 '22 20:05 prjemian

I ran into the same issue I think when trying to update just the pyqt. The closest I've gotten to something working so far is creating a new environment like so (this should cause it to grab pyqt 5.15.4)

conda create -n pydm-test-env python=3.8 pyqt=5 pip numpy scipy six psutil pyqtgraph pydm -c conda-forge

and then having to copy over the libpyqt5.so file from an existing environment in order to get designer working again since the latest version from conda-forge dropped it. Something like:

cp miniconda3/envs/working-pydm-environment/plugins/designer/libpyqt5.so miniconda3/envs/pydm-test-env/plugins/designer/

Your test ui file then opens ok for me in both designer and pydm.

This is of course not good and will need to look into getting it working better, maybe starting with the pyqt feedstock and seeing if it's not too terrible a process to add back in that shared library. (I will note that this happened once before and getting it back did seem quite difficult)

jbellister-slac avatar May 18 '22 21:05 jbellister-slac

Just as a quick update to this, I did open up an issue on the pyqt-feedstock repo here but haven't heard back yet. Getting that fixed I think would be the cleanest way forward since then we could just use the updated version of pyqt from conda-forge.

jbellister-slac avatar May 25 '22 18:05 jbellister-slac