##// END OF EJS Templates
added initial support for public member variable access via getters/setters...
florianlink -
r113:ab319fdfc38d
parent child
Show More
@@ -300,6 +300,13 static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
300 }
300 }
301 break;
301 break;
302 case PythonQtMemberInfo::NotFound:
302 case PythonQtMemberInfo::NotFound:
303 {
304 // check for a getter_
305 PythonQtMemberInfo member = wrapper->classInfo()->member(QByteArray("getter_") + attributeName);
306 if (member._type == PythonQtMemberInfo::Slot) {
307 return PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, member._slot, NULL, NULL, wrapper->_wrappedPtr);
308 }
309
303 // handle dynamic properties
310 // handle dynamic properties
304 if (wrapper->_obj) {
311 if (wrapper->_obj) {
305 QVariant v = wrapper->_obj->property(attributeName);
312 QVariant v = wrapper->_obj->property(attributeName);
@@ -307,6 +314,7 static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
307 return PythonQtConv::QVariantToPyObject(v);
314 return PythonQtConv::QVariantToPyObject(v);
308 }
315 }
309 }
316 }
317 }
310 break;
318 break;
311 default:
319 default:
312 // is an invalid type, go on
320 // is an invalid type, go on
@@ -339,7 +347,7 static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
339 static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObject *value)
347 static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObject *value)
340 {
348 {
341 QString error;
349 QString error;
342 char *attributeName;
350 const char *attributeName;
343 PythonQtInstanceWrapper *wrapper = (PythonQtInstanceWrapper *)obj;
351 PythonQtInstanceWrapper *wrapper = (PythonQtInstanceWrapper *)obj;
344
352
345 if ((attributeName = PyString_AsString(name)) == NULL)
353 if ((attributeName = PyString_AsString(name)) == NULL)
@@ -385,6 +393,19 static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObjec
385 } else if (member._type == PythonQtMemberInfo::EnumWrapper) {
393 } else if (member._type == PythonQtMemberInfo::EnumWrapper) {
386 error = QString("Enum '") + attributeName + "' can not be overwritten on " + obj->ob_type->tp_name + " object";
394 error = QString("Enum '") + attributeName + "' can not be overwritten on " + obj->ob_type->tp_name + " object";
387 } else if (member._type == PythonQtMemberInfo::NotFound) {
395 } else if (member._type == PythonQtMemberInfo::NotFound) {
396 // check for a setter_
397 PythonQtMemberInfo setter = wrapper->classInfo()->member(QByteArray("setter_") + attributeName);
398 if (setter._type == PythonQtMemberInfo::Slot) {
399 // call the setter and ignore the result value
400 void* result;
401 PyObject* args = PyTuple_New(1);
402 Py_INCREF(value);
403 PyTuple_SET_ITEM(args, 0, value);
404 PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, setter._slot, args, NULL, wrapper->_wrappedPtr, &result);
405 Py_DECREF(args);
406 return 0;
407 }
408
388 // handle dynamic properties
409 // handle dynamic properties
389 if (wrapper->_obj) {
410 if (wrapper->_obj) {
390 QVariant prop = wrapper->_obj->property(attributeName);
411 QVariant prop = wrapper->_obj->property(attributeName);
@@ -233,7 +233,7 PyObject *PythonQtSlotFunction_Call(PyObject *func, PyObject *args, PyObject *kw
233
233
234 PyObject *PythonQtSlotFunction_CallImpl(PythonQtClassInfo* classInfo, QObject* objectToCall, PythonQtSlotInfo* info, PyObject *args, PyObject * /*kw*/, void* firstArg, void** directReturnValuePointer)
234 PyObject *PythonQtSlotFunction_CallImpl(PythonQtClassInfo* classInfo, QObject* objectToCall, PythonQtSlotInfo* info, PyObject *args, PyObject * /*kw*/, void* firstArg, void** directReturnValuePointer)
235 {
235 {
236 int argc = PyTuple_Size(args);
236 int argc = args?PyTuple_Size(args):0;
237
237
238 #ifdef PYTHONQT_DEBUG
238 #ifdef PYTHONQT_DEBUG
239 std::cout << "called " << info->metaMethod()->typeName() << " " << info->metaMethod()->signature() << std::endl;
239 std::cout << "called " << info->metaMethod()->typeName() << " " << info->metaMethod()->signature() << std::endl;
General Comments 0
You need to be logged in to leave comments. Login now