-
Notifications
You must be signed in to change notification settings - Fork 77
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
base: master
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this 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/label.py
Outdated
class PyDMLabel(QLabel, TextFormatter, PyDMWidget, DisplayFormat, new_properties=_labelRuleProperties): | ||
class PyDMLabel(QLabel, TextFormatter, PyDMWidget, new_properties=_labelRuleProperties): |
There was a problem hiding this comment.
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'
b7bbf3f
to
390cc65
Compare
390cc65
to
49d57d5
Compare
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.