[PyQt] What happend to PyQt5.QtCore.pyqtWrapperType?

Marcus Ottosson konstruktion at gmail.com
Thu Feb 9 13:58:44 GMT 2017


Hi Phil,

Do you have any recommendations for alternatives to pyqtWrapperType when it
comes to metaclasses? I was using it to dynamically add signals to a
QObject.

class PropertyType(QtCore.pyqtWrapperType):
    """Metaclass for converting class attributes into pyqtProperties"""

    prefix = "__pyqtproperty__"

    def __new__(cls, name, bases, attrs):
        """Convert class properties into pyqtProperties"""

        for key, value in attrs.copy().items():
            if key.startswith("__"):
                continue

            notify = QtCore.pyqtSignal()

            def set_data(key, value):
                def set_data(self, value):
                    setattr(self, cls.prefix + key, value)
                    getattr(self, key + "Changed").emit()
                    self.__datachanged__.emit(self)
                return set_data

            attrs[key + "Changed"] = notify
            attrs[key] = QtCore.pyqtProperty(
                type(value) if value is not None else QtCore.QVariant,
                fget=lambda self, k=key: getattr(self, cls.prefix + k, None),
                fset=set_data(key, value),
                notify=notify)

        return super(PropertyType, cls).__new__(cls, name, bases, attrs)
class AbstractItem(QtCore.QObject):
    __metaclass__ = PropertyType
    __datachanged__ = QtCore.pyqtSignal(QtCore.QObject)

    def __str__(self):
        return self.name

    def __repr__(self):
        return "%s.%s(%r)" % (__name__, type(self).__name__, self.__str__())

Using type in place of pyqtWrapperType results in a:

TypeError: metaclass conflict: the metaclass of a derived class must
be a (non-strict) subclass of the metaclasses of all its bases

Production code here
<https://github.com/pyblish/pyblish-qml/blob/7c20ef38837cfbe91b28cb5c6a708c3c5aae96da/pyblish_qml/models.py#L94>
.

Any ideas?

Thanks.
​

On 18 January 2017 at 22:17, Phil Thompson <phil at riverbankcomputing.com>
wrote:

> On 18 Jan 2017, at 6:51 pm, Cody Scott <cody at perspexis.com> wrote:
> >
> > I'm looking at this code for inspiration on testing QML and I ran into
> this error.
> >
> > https://github.com/pyblish/pyblish-qml/blob/
> 635c82d75fa5d5e294339bf8265f05eb5ca3b5d3/pyblish_qml/models.py#L94
> >
> > AttributeError: module 'PyQt5.QtCore' has no attribute 'pyqtWrapperType'
> >
> > It doesn't appear to be available in PyQt5==5.7.1
> >
> > It is available in PyQt5==5.6
>
> It was an undocumented implementation detail that was removed as part of
> the adoption of the limited API.
>
> If code wants to get the meta-type used by PyQt then it should call type()
> on a PyQt type object.
>
> Phil
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt




-- 
*Marcus Ottosson*
konstruktion at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170209/df9ebe10/attachment-0001.html>


More information about the PyQt mailing list