How to find enum's in PyQt6?

Barry Scott barry at barrys-emacs.org
Sun Jul 10 12:13:28 BST 2022


On 08/07/2022 16:37, Florian Bruhin wrote:

> Hey,
>
> On Fri, Jul 08, 2022 at 04:13:53PM +0100, Barry Scott wrote:
>> I've ported Barry's Emacs to PyQt6 and managed to track down all the enums that it uses.
>>
>> But I'm not finding the enums that SCM Workbench uses.
>>
>> How do you suggest I can find the enums without asking the list each time.
>>
>> For example I'm current looking for these symbols from PyQt5 for PyQt6:
>>
>> QtWidgets.QAction.NoRole
>> QtCore.Qt.UserRole
>>
>> But I am bound to need to know how to port a lot more.
>>
>> I've used introspection in the past to track down symbols but that is
>> not yielding results yet.
> In the Qt documentation, you can find the enum type the value belongs
> to by looking at the class involved and searching for the value:
> https://doc.qt.io/qt-6/qaction.html#MenuRole-enum

I have been doing that with success.

> Thus, that would be QAction.MenuRole.NoRole.
>
> Or you ask PyQt5:
>
>      >>> from PyQt5.QtWidgets import QAction
>      >>> type(QAction.NoRole)
>      <class 'PyQt5.QtWidgets.QAction.MenuRole'>
>
> However, why bother doing this manually at all? I'm aware of three
> different tools to do this automatically.
>
> Mine:
> https://github.com/qutebrowser/qutebrowser/blob/qt6-v2/scripts/dev/rewrite_find_enums.py
> https://github.com/qutebrowser/qutebrowser/blob/qt6-v2/scripts/dev/rewrite_enums.py
> with a list of enum mappings here:
> https://github.com/qutebrowser/qutebrowser/blob/qt6-v2/scripts/dev/enums.txt

Thanks I got your tools running.

But I'm still none the wiser how to fix this:

    def _addMenu( self, menu, name, handler, enabler=None, 
icon_name=None, checker=None, group=None, role=QtWidgets
.QAction.MenuRole.NoRole ):
AttributeError: module 'PyQt6.QtWidgets' has no attribute 'QAction'

I am using the KDE build of Qt6/PyQt6 for Fedora copr that is version 6.2.3.

Is this a problem with this being an older version?

Barry

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220710/e74ef5c6/attachment.htm>


More information about the PyQt mailing list