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

MNT: make enums use python Enum class and updated Q_ENUM (no 's') #1146

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nstelter-slac
Copy link
Collaborator

@nstelter-slac nstelter-slac commented Dec 20, 2024

Using the python Enum class is a first step required for later support of enum macros in PySide6,
see https://doc.qt.io/qtforpython-6/PySide6/QtCore/QEnum.html.

Also these python 'Enums' provide some minor benefits like easier iteration, and are already compatible with PyQt5 enum macro.

Also remove our subclassing of enum classes, this isn't needed and not even allowed now that the enums are python 'Enums'.

Also we switch from 'Q_ENUMS' -> 'Q_ENUM' since its a newer verison of the enum macro for PyQt5.

We import 'Q_ENUM' directly from PyQt5 b/c its not provided by the qtpy abstraction layer. But this is fine since seems there is no nice enum abstraction that works for both PyQt5 and PySide6 anyway. The new enum macro for PySide6 will be added later, and which we use will be determined with conditional check of Qt wrapper.

Using the python Enum class is a first step required for later
support of enum macros in PySide6,
see https://doc.qt.io/qtforpython-6/PySide6/QtCore/QEnum.html.

Also these python 'Enums' provide some minor benefits like easier iteration,
and are already compatible with PyQt5 enums.

Also remove our subclassing of enum classes, this isn't needed and not
even allowed now that the enums are python 'Enums'.

Also we switch from 'Q_ENUMS' -> 'Q_ENUM' since its a newer verison
of the enum macro for PyQt5.

We import 'Q_ENUM' directly from PyQt5 b/c its not provided by the qtpy
abstraction layer. But this is fine since seems there is no nice
enum abstraction that works for both PyQt5 and PySide6 anyway. The
new enum macro for PySide6 will be added later, and which we use
will be determined with conditional check of Qt wrapper.
Copy link
Collaborator

@jbellister-slac jbellister-slac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To double check, all the from PyQt5.QtCore import Q_ENUM imports will go away either as part of or shortly after #1145 so PyDM will work ok in a pyside 6 environment?

Also I see quite a few of these when opening Qt Designer up with this branch. If this (or my other comments) are resolved as part of #1145 let me know, I haven't looked through that one yet since it says this PR should go first.

$ designer
Exception occurred while running Qt Designer.
TypeError: unable to convert a Python 'DisplayFormat' object to a C++ 'DisplayFormat' instance

Exception occurred while running Qt Designer.
TypeError: unable to convert a Python 'updateMode' object to a C++ 'updateMode' instance

Exception occurred while running Qt Designer.
TypeError: unable to convert a Python 'TimeBase' object to a C++ 'TimeBase' instance

etc...

pydm/widgets/datetime.py Outdated Show resolved Hide resolved
pydm/widgets/datetime.py Outdated Show resolved Hide resolved
Comment on lines 12 to 13
class PyDMLabel(QLabel, TextFormatter, PyDMWidget, DisplayFormat, new_properties=_labelRuleProperties):
class PyDMLabel(QLabel, TextFormatter, PyDMWidget, new_properties=_labelRuleProperties):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing DisplayFormat here (as well as in line_edit.py) will cause issues with saved ui files not being able to find the property in PyQt5, error I am seeing with the example label below.

This is where the idea to set up the enum this way came from
https://stackoverflow.com/questions/46917671/how-to-use-q-enums-in-pyqt

$ pydm examples/label/label.ui
<...>
AttributeError: type object 'PyDMLabel' has no attribute 'String'

@nstelter-slac nstelter-slac force-pushed the fix_pyqt5_enums branch 4 times, most recently from b7bbf3f to 390cc65 Compare January 10, 2025 20:40
@nstelter-slac nstelter-slac marked this pull request as draft January 10, 2025 21:28
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

Successfully merging this pull request may close these issues.

2 participants