undo property test
This commit is contained in:
parent
a15b4f56d4
commit
174af377ae
50
qt5.py
50
qt5.py
@ -26,52 +26,4 @@ except ImportError as pyqt5_error:
|
||||
else:
|
||||
os.environ["QT_API"] = "pyqt5"
|
||||
QtCore.Signal = QtCore.pyqtSignal
|
||||
|
||||
|
||||
class Propertize(type):
|
||||
def __new__(cls, name, bases, dct):
|
||||
return type.__new__(
|
||||
cls,
|
||||
name[1:],
|
||||
tuple(Propertize.this_class(base) for base in bases),
|
||||
{
|
||||
attr_name: (
|
||||
property(attr, dct["set" + attr_name.capitalize()])
|
||||
if "set" + attr_name.capitalize() in dct
|
||||
else (
|
||||
Propertize.this_class(attr)
|
||||
if isinstance(attr, type)
|
||||
else attr
|
||||
)
|
||||
) for attr_name, attr in dct.items()
|
||||
}
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def this_class(cls):
|
||||
return Propertize(cls.__name__, cls.__bases__, cls.__dict__)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
class QParent:
|
||||
def __init__(self):
|
||||
self._b = 0
|
||||
def b(self):
|
||||
return self._b
|
||||
def setB(self, val):
|
||||
self._b = val
|
||||
|
||||
|
||||
class QTest(QParent, metaclass=Propertize):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._a = 0
|
||||
def a(self):
|
||||
return self._a
|
||||
def setA(self, val):
|
||||
self._a = val
|
||||
|
||||
|
||||
Point = Propertize.this_class(QtCore.QPoint)()
|
||||
p = Point(1, 2)
|
||||
print(p.x, p.y)
|
||||
|
Loading…
x
Reference in New Issue
Block a user