Raise a error when try to modify a read-only property.
Add get function as mandatory in QProperty constructor.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
1162a844bd
commit
6bd528978c
3 changed files with 22 additions and 6 deletions
|
|
@ -143,11 +143,11 @@ int qproperty_init(PyObject* self, PyObject* args, PyObject* kwds)
|
||||||
"designable", "scriptable", "stored", "user",
|
"designable", "scriptable", "stored", "user",
|
||||||
"constant", "final", 0};
|
"constant", "final", 0};
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds,
|
if (!PyArg_ParseTupleAndKeywords(args, kwds,
|
||||||
"O|OOOOsbbbbbb:QtCore.QProperty", (char**) kwlist,
|
"OO|OOOsbbbbbb:QtCore.QProperty", (char**) kwlist,
|
||||||
/*O*/&type,
|
/*OO*/ &type, &(data->fget),
|
||||||
/*OOOO*/ &(data->fget), &(data->fset), &(data->freset), &(data->fdel),
|
/*OOOO*/ &(data->fset), &(data->freset), &(data->fdel),
|
||||||
/*s*/&(data->doc),
|
/*s*/ &(data->doc),
|
||||||
/*bbbbbb*/&(data->designable), &(data->scriptable), &(data->stored), &(data->user), &(data->constant), &(data->final)))
|
/*bbbbbb*/ &(data->designable), &(data->scriptable), &(data->stored), &(data->user), &(data->constant), &(data->final)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!data->fset && data->fget)
|
if (!data->fset && data->fget)
|
||||||
|
|
@ -187,6 +187,8 @@ int qproperty_set(PyObject* self, PyObject* source, PyObject* value)
|
||||||
Py_INCREF(value);
|
Py_INCREF(value);
|
||||||
Shiboken::AutoDecRef result(PyObject_CallObject(data->fset, args));
|
Shiboken::AutoDecRef result(PyObject_CallObject(data->fset, args));
|
||||||
return (result.isNull() ? -1 : 0);
|
return (result.isNull() ? -1 : 0);
|
||||||
|
} else {
|
||||||
|
PyErr_SetString(PyExc_AttributeError, "Attibute read only");
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -373,7 +373,6 @@ int SignalManager::qt_metacall(QObject* object, QMetaObject::Call call, int id,
|
||||||
Py_XDECREF(pp_name);
|
Py_XDECREF(pp_name);
|
||||||
return id - metaObject->methodCount();
|
return id - metaObject->methodCount();
|
||||||
}
|
}
|
||||||
printf("access to property: %s-%s\n", mp.name(), mp.typeName());
|
|
||||||
typeResolver = Shiboken::TypeResolver::get(mp.typeName());
|
typeResolver = Shiboken::TypeResolver::get(mp.typeName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,16 @@ class MySize(QSize):
|
||||||
class ExtQObject(QObject):
|
class ExtQObject(QObject):
|
||||||
registeredproperty = QProperty(int)
|
registeredproperty = QProperty(int)
|
||||||
|
|
||||||
|
class MyObject(QObject):
|
||||||
|
'''Test Property'''
|
||||||
|
|
||||||
|
def readPP(self):
|
||||||
|
return 42
|
||||||
|
|
||||||
|
def trySetPP(self):
|
||||||
|
self.pp = 0
|
||||||
|
|
||||||
|
pp = QProperty(int, readPP)
|
||||||
|
|
||||||
class PropertyCase(unittest.TestCase):
|
class PropertyCase(unittest.TestCase):
|
||||||
'''Test case for QObject properties'''
|
'''Test case for QObject properties'''
|
||||||
|
|
@ -115,6 +125,11 @@ class PropertyWithConstructorCase(unittest.TestCase):
|
||||||
obj = QTimer(objectName='dummy')
|
obj = QTimer(objectName='dummy')
|
||||||
self.assertEqual(obj.objectName(), 'dummy')
|
self.assertEqual(obj.objectName(), 'dummy')
|
||||||
|
|
||||||
|
def testPythonProperty(self):
|
||||||
|
o = MyObject()
|
||||||
|
self.assertEqual(o.pp, 42)
|
||||||
|
o.pp = 0
|
||||||
|
self.assertRaises(AttributeError, o.trySetPP)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue