[PyQt] Getting parent class for an enum

Florian Bruhin me at the-compiler.org
Thu May 17 09:38:10 BST 2018


On Thu, May 17, 2018 at 09:23:56AM +0100, Phil Thompson wrote:
> On 16 May 2018, at 1:57 pm, Denis Rouzaud <denis.rouzaud at gmail.com> wrote:
> > 
> > Hi,
> > 
> > In the case of an enum (with Q_ENUM macro), it would be interesting to have a way to get the parent class to be able to get the meta enum from the enum value (enumValue):
> > 
> > base = type(enumValue).parentClass()
> > idx = base.staticMetaObject.indexOfEnumerator(type(enumValue).__name__)
> > metaenum = base.staticMetaObject.enumerator(idx)
> > 
> > Would it be possible to add this capability to sip.enumType ?
> > Either to return the parent class or directly the metaEnum?
> 
> Are you asking for an implementation of QMetaEnum.fromType()?
> 
> For example...
> 
>     metaenum = QMetaEnum.fromType(type(Qt.Key_F1))

That'd be useful indeed, IMHO!

> > Phil, how complicate is it?
> > Do you have any interest/plan to do it...?
> 
> It shouldn't be too difficult (famous last words). This area needs an update anyway to add support for Q_ENUM(), Q_FLAG() and Python enum objects.

Oh, if PyQt enums would be a subclass of Python's enum.Enum (or
enum.IntEnum) objects - that'd be nice! :)

Florian

-- 
https://www.qutebrowser.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
         I love long mails! | https://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180517/a18f279f/attachment.sig>


More information about the PyQt mailing list