[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] How to get Qt enum class
From:       Florian Bruhin <me () the-compiler ! org>
Date:       2014-08-29 7:34:07
Message-ID: 20140829073407.GE28617 () lupin
[Download RAW message or body]

This is a MIME-formatted message.  If you see this text it means that your
E-mail software does not support MIME-formatted messages.

[Attachment #2 (multipart/signed)]
This is a MIME-formatted message.  If you see this text it means that your
E-mail software does not support MIME-formatted messages.


Hi,

* Phil Thompson <phil@riverbankcomputing.com> [2014-08-14 14:50:18 +0100]:
> On 07/08/2014 7:27 am, Florian Bruhin wrote:
> >Hi,
> >
> >I wrote a function to get the key name in a Qt enum from a value,
> >intended for debugging mainly. This is how it looks right now:
> >
> > <snip>
> >
> >Now ideally I'd just pass in the value and nothing else, however I
> >didn't find a way to get the Qt class where the enum is in, e.g. get
> >QFont when I have QFont.Sunken:
> >
> >>>>QFont.Bold.__class__
> ><class 'PyQt5.QtGui.Weight'>
> >>>>QFont.Bold.__class__.__class__
> ><class 'sip.enumtype'>
> >
> >Is there a way I could do this, or do I have to pass this explicitely?
> 
> Currently QFont.Weight.__qualname__ returns 'Weight'. Maybe it should return
> 'QFont.Weight' instead, the argument being that an enum is a type and should
> be treated like a nested class.
> 
> Would that solve your problem?

Hmm. It'd certainly make it a bit easier.

However that sparks an idea: Would it be possible for enum *members*
to have a __name__ and a __qualname__? Basically like this:

    >>> QFont.Bold.__name__
    'Bold'
    >>> QFont.Bold.__qualname__
    'QFont.Bold'  # or maybe 'QFont.Weight.Bold'?

That'd basically do what my qenum_key function does, but without all
the guesswork.

Florian

-- 
http://www.the-compiler.org | me@the-compiler.org (Mail/XMPP)
             GPG 0xFD55A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/

[Attachment #5 (application/pgp-signature)]
[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic