Getting parent class for an enum

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting parent class for an enum

Denis Rouzaud
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?

Phil, how complicate is it?
Do you have any interest/plan to do it...?

Cheers,
Denis


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: Getting parent class for an enum

Phil Thompson-5
On 16 May 2018, at 1:57 pm, Denis Rouzaud <[hidden email]> 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))

> 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.

I'll see what I can do for PyQt 5.11.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: Getting parent class for an enum

Florian Bruhin
On Thu, May 17, 2018 at 09:23:56AM +0100, Phil Thompson wrote:

> On 16 May 2018, at 1:57 pm, Denis Rouzaud <[hidden email]> 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 | [hidden email] (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
         I love long mails! | https://email.is-not-s.ms/

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Getting parent class for an enum

J Barchan
In reply to this post by Phil Thompson-5


On 17 May 2018 at 09:23, Phil Thompson <[hidden email]> wrote:
On 16 May 2018, at 1:57 pm, Denis Rouzaud <[hidden email]> 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))

> 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.

I'll see what I can do for PyQt 5.11.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

​I'm not sure whether ​I am hijacking a relevant thread, or whether this can already be done, but I would like to know how to (easily) get the symbolic string for an ItemDataRole constant:

class MySqlQueryModel(QSqlQueryModel):
    def data(self, index: QtCore.QModelIndex, role: QtCore.Qt.ItemDataRole=QtCore.Qt.DisplayRole) -> typing.Any:
        print(role)

​How do I get to print that role as, say, "DisplayRole" instead of as 0, for debugging?​



--
Kindest,
Jonathan

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: Getting parent class for an enum

Phil Thompson-5
In reply to this post by Florian Bruhin
On 17 May 2018, at 9:38 am, Florian Bruhin <[hidden email]> wrote:

>
> On Thu, May 17, 2018 at 09:23:56AM +0100, Phil Thompson wrote:
>> On 16 May 2018, at 1:57 pm, Denis Rouzaud <[hidden email]> 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! :)

C++ scoped enums are implemented as Python enums, but there are very few of them in Qt at the moment. Changing the implementation of traditional enums would (IMHO) cause compatibility issues.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: Getting parent class for an enum

Florian Bruhin
In reply to this post by J Barchan
On Thu, May 17, 2018 at 09:50:13AM +0100, J Barchan wrote:

> ​I'm not sure whether ​I am hijacking a relevant thread, or whether this
> can already be done, but I would like to know how to (easily) get the
> symbolic string for an ItemDataRole constant:
>
> class MySqlQueryModel(QSqlQueryModel):
>     def data(self, index: QtCore.QModelIndex, role:
> QtCore.Qt.ItemDataRole=QtCore.Qt.DisplayRole) -> typing.Any:
>         print(role)
>
> ​How do I get to print that role as, say, "DisplayRole" instead of as 0,
> for debugging?​
I wrote something to do that here:
https://github.com/qutebrowser/qutebrowser/blob/v1.3.0/qutebrowser/utils/debug.py#L96-L132

Florian

--
https://www.qutebrowser.org | [hidden email] (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
         I love long mails! | https://email.is-not-s.ms/

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Getting parent class for an enum

J Barchan


On 17 May 2018 at 10:12, Florian Bruhin <[hidden email]> wrote:
On Thu, May 17, 2018 at 09:50:13AM +0100, J Barchan wrote:
> ​I'm not sure whether ​I am hijacking a relevant thread, or whether this
> can already be done, but I would like to know how to (easily) get the
> symbolic string for an ItemDataRole constant:
>
> class MySqlQueryModel(QSqlQueryModel):
>     def data(self, index: QtCore.QModelIndex, role:
>
​​
QtCore.Qt.ItemDataRole=QtCore.Qt.DisplayRole) -> typing.Any:
>         print(role)
>
> ​How do I get to print that role as, say, "DisplayRole" instead of as 0,
> for debugging?​

I wrote something to do that here:
https://github.com/qutebrowser/qutebrowser/blob/v1.3.0/qutebrowser/utils/debug.py#L96-L132

Florian

--
https://www.qutebrowser.org | [hidden email] (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
         I love long mails! | https://email.is-not-s.ms/

​Dear Florian,

Thanks!  Your qenum_key() looks promising except for:​

  1. I cannot find anything suitable to pass in as `base`, e.g.
    qenum_key(QtCore.Qt, role, klass=QtCore.Qt.ItemDataRole)
    does not work.  I don't understand what it is I need here which has a base.staticMetaObject?
  2. Is this whole principle going to work for QtCore.Qt.ItemDataRole?  So far as I can see, it's not some kind of enum in PyQt, it's just a class derived from int with a bunch of sundry member variables for various values.
--
Kindest,
Jonathan

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: Getting parent class for an enum

Florian Bruhin
On Thu, May 17, 2018 at 11:14:18AM +0100, J Barchan wrote:

> On 17 May 2018 at 10:12, Florian Bruhin <[hidden email]> wrote:
>
> > On Thu, May 17, 2018 at 09:50:13AM +0100, J Barchan wrote:
> > > ​I'm not sure whether ​I am hijacking a relevant thread, or whether this
> > > can already be done, but I would like to know how to (easily) get the
> > > symbolic string for an ItemDataRole constant:
> > >
> > > class MySqlQueryModel(QSqlQueryModel):
> > >     def data(self, index: QtCore.QModelIndex, role:
> > >
> > ​​
> > QtCore.Qt.ItemDataRole=QtCore.Qt.DisplayRole) -> typing.Any:
> > >         print(role)
> > >
> > > ​How do I get to print that role as, say, "DisplayRole" instead of as 0,
> > > for debugging?​
> >
> > I wrote something to do that here:
> > https://github.com/qutebrowser/qutebrowser/blob/v1.3.0/qutebrowser/utils/
> > debug.py#L96-L132
> >
> > Florian
> >
> > --
> > https://www.qutebrowser.org | [hidden email] (Mail/XMPP)
> >    GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
> >          I love long mails! | https://email.is-not-s.ms/
> >
>
> ​Dear Florian,
>
> Thanks!  Your qenum_key() looks promising *except for*:​
>
>
>    1. I cannot find anything suitable to pass in as `base`, e.g.
>
>    qenum_key(QtCore.Qt, role, klass=QtCore.Qt.ItemDataRole)
>
>    does not work.  I don't understand what it is I need here which has a
>    base.staticMetaObject?
>    2. Is this whole principle going to work for QtCore.Qt.ItemDataRole?  So
>    far as I can see, it's not some kind of enum in PyQt, it's just a class
>    derived from int with a bunch of sundry member variables for various
>    values.
Seems to work fine for me:

    >>> from qutebrowser.utils import debug
    >>> from PyQt5.QtCore import Qt
    >>> debug.qenum_key(Qt, Qt.DisplayRole)
    'DisplayRole'

(tried with PyQt 5.7.1 and 5.10)

Florian

--
https://www.qutebrowser.org | [hidden email] (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
         I love long mails! | https://email.is-not-s.ms/

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Getting parent class for an enum

J Barchan


On 17 May 2018 at 11:18, Florian Bruhin <[hidden email]> wrote:
On Thu, May 17, 2018 at 11:14:18AM +0100, J Barchan wrote:
> On 17 May 2018 at 10:12, Florian Bruhin <[hidden email]> wrote:
>
> > On Thu, May 17, 2018 at 09:50:13AM +0100, J Barchan wrote:
> > > ​I'm not sure whether ​I am hijacking a relevant thread, or whether this
> > > can already be done, but I would like to know how to (easily) get the
> > > symbolic string for an ItemDataRole constant:
> > >
> > > class MySqlQueryModel(QSqlQueryModel):
> > >     def data(self, index: QtCore.QModelIndex, role:
> > >
> > ​​
> > QtCore.Qt.ItemDataRole=QtCore.Qt.DisplayRole) -> typing.Any:
> > >         print(role)
> > >
> > > ​How do I get to print that role as, say, "DisplayRole" instead of as 0,
> > > for debugging?​
> >
> > I wrote something to do that here:
> > https://github.com/qutebrowser/qutebrowser/blob/v1.3.0/qutebrowser/utils/
> > debug.py#L96-L132
> >
> > Florian
> >
> > --
> > https://www.qutebrowser.org | [hidden email] (Mail/XMPP)
> >    GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
> >          I love long mails! | https://email.is-not-s.ms/
> >
>
> ​Dear Florian,
>
> Thanks!  Your qenum_key() looks promising *except for*:​
>
>
>    1. I cannot find anything suitable to pass in as `base`, e.g.
>
>    qenum_key(QtCore.Qt, role,
​​
klass=QtCore.Qt.ItemDataRole)
>
>    does not work.  I don't understand what it is I need here which has a
>    base.staticMetaObject?
>    2. Is this whole principle going to work for QtCore.Qt.ItemDataRole?  So
>    far as I can see, it's not some kind of enum in PyQt, it's just a class
>    derived from int with a bunch of sundry member variables for various
>    values.

Seems to work fine for me:

    >>> from qutebrowser.utils import debug
    >>> from PyQt5.QtCore import Qt
    >>> debug.qenum_key(Qt, Qt.DisplayRole)
    'DisplayRole'

(tried with PyQt 5.7.1 and 5.10)

Florian

--
https://www.qutebrowser.org | [hidden email] (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
         I love long mails! | https://email.is-not-s.ms/

​My humble apologies!

I was confused in the PyCharm IDE, which highlights ​passing QtCore.Qt for base with error message "Type '[Qt]' doesn't have expected attribute 'staticMetaObject'", and then stepping through qenum_key hit that 
except AttributeError:
code path, and I thought it had gone wrong.  I now understand how your code works, and that path is expected in my case!

For my case, I want to know the symbolic value in a role variable, which has already been converted to an int.  That means I must pass qenum_key() a
klass=QtCore.Qt.ItemDataRole
hint.  I now confirm my
qenum_key(QtCore.Qt, role, klass=QtCore.Qt.ItemDataRole)
is the correct formulation for me.

​I shall now ​add your qenum_key() & qflags_key() to my utility functions!  Thanks :)


--
Kindest,
Jonathan

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: Getting parent class for an enum

Kyle Altendorf
In reply to this post by Phil Thompson-5


On 2018-05-17 04:55, Phil Thompson wrote:

> On 17 May 2018, at 9:38 am, Florian Bruhin <[hidden email]> wrote:
>>
>> On Thu, May 17, 2018 at 09:23:56AM +0100, Phil Thompson wrote:
>>> On 16 May 2018, at 1:57 pm, Denis Rouzaud <[hidden email]>
>>> 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! :)
>
> C++ scoped enums are implemented as Python enums, but there are very
> few of them in Qt at the moment. Changing the implementation of
> traditional enums would (IMHO) cause compatibility issues.

Deprecate the classic implementation for 'awhile' and also provide them
all as Python enums?  I'll also note that type(MyEnum.a_value) -> MyEnum
so that part is easy with Python enums.

Cheers,
-kyle
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: Getting parent class for an enum

Phil Thompson-5
On 17 May 2018, at 2:11 pm, Kyle Altendorf <[hidden email]> wrote:

> On 2018-05-17 04:55, Phil Thompson wrote:
>> On 17 May 2018, at 9:38 am, Florian Bruhin <[hidden email]> wrote:
>>> On Thu, May 17, 2018 at 09:23:56AM +0100, Phil Thompson wrote:
>>>> On 16 May 2018, at 1:57 pm, Denis Rouzaud <[hidden email]> 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! :)
>> C++ scoped enums are implemented as Python enums, but there are very
>> few of them in Qt at the moment. Changing the implementation of
>> traditional enums would (IMHO) cause compatibility issues.
>
> Deprecate the classic implementation for 'awhile' and also provide them all as Python enums?  I'll also note that type(MyEnum.a_value) -> MyEnum so that part is easy with Python enums.

A member of a scoped enum is only exposed as an attribute of the enum.

A member of a traditional enum has the same visibility as the enum itself.

Changing the implementation would mean changing any code that used any enum member.

Switching to Python enums and also exposing the emum members (to maintain compatibility) seems pointless to me.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: Getting parent class for an enum

Phil Thompson-5
In reply to this post by Phil Thompson-5
On 17 May 2018, at 9:23 am, Phil Thompson <[hidden email]> wrote:

>
> On 16 May 2018, at 1:57 pm, Denis Rouzaud <[hidden email]> 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))

...on second thoughts, that's not what you are asking for.

For Qt enums you should be able to do that using __module__ and __qualname__ (now that qualname is fixed) to find the class and its meta-object.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: Getting parent class for an enum

Phil Thompson-5
In reply to this post by Phil Thompson-5
On 17 May 2018, at 2:48 pm, Phil Thompson <[hidden email]> wrote:

>
> On 17 May 2018, at 2:11 pm, Kyle Altendorf <[hidden email]> wrote:
>> On 2018-05-17 04:55, Phil Thompson wrote:
>>> On 17 May 2018, at 9:38 am, Florian Bruhin <[hidden email]> wrote:
>>>> On Thu, May 17, 2018 at 09:23:56AM +0100, Phil Thompson wrote:
>>>>> On 16 May 2018, at 1:57 pm, Denis Rouzaud <[hidden email]> 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! :)
>>> C++ scoped enums are implemented as Python enums, but there are very
>>> few of them in Qt at the moment. Changing the implementation of
>>> traditional enums would (IMHO) cause compatibility issues.
>>
>> Deprecate the classic implementation for 'awhile' and also provide them all as Python enums?  I'll also note that type(MyEnum.a_value) -> MyEnum so that part is easy with Python enums.
>
> A member of a scoped enum is only exposed as an attribute of the enum.
>
> A member of a traditional enum has the same visibility as the enum itself.
>
> Changing the implementation would mean changing any code that used any enum member.
>
> Switching to Python enums and also exposing the emum members (to maintain compatibility) seems pointless to me.

What I've actually done is to make the members of traditional enums visible from within the scope of the enum (as well as being visible from the same scope as the enum).

This means that you *should* change your code to use the scope (ie. Qt.Key.Key_F1 rather than Qt.Key_F1) but you don't *have* to. However you will have to for PyQt6.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt