I am tired of writing the same code for declaring Properties
for PySide2
:
class BackEnd(QObject):
my_prop_updated = Signal()
@Property(bool)
def my_prop(self):
print('getter invoked'))
return self._my_prop
@my_prop.setter
def set_my_prop(self, value):
print('setter invoked')
self._my_prop = value
self.my_prop_updated.emit()
def __init__(self):
super().__init__()
self._my_prop = None
Is there any way to make use of python descriptors with Properties
? Something like so:
class QTPropBool(Property):
my_prop_updated = Signal()
def my_getter(self, obj):
print('getter invoked')
return self._my_prop
def my_setter(self, obj, value):
print('setter invoked')
self._my_prop = value
self.my_prop_updated.emit()
def __init__(self):
super().__init__(bool, self.my_getter, self.my_setter, notify=self.my_prop_updated)
class BackEnd(QObject):
my_prop = QTPropBool()
It gives me an error:
AttributeError: 'PySide2.QtCore.Signal' object has no attribute 'emit'
Probably because it's Property
class, not QObject
and I am not invoking QObject
's constructor. Is there any way to avoid code duplication?