@@ -209,17 +209,9 static PyObject *PythonQtClassWrapper_getattro(PyObject *obj, PyObject *name) | |||||
209 | return NULL; |
|
209 | return NULL; | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 |
static int PythonQtClassWrapper_setattro(PyObject *obj,PyObject *name,PyObject * |
|
212 | static int PythonQtClassWrapper_setattro(PyObject *obj,PyObject *name,PyObject *value) | |
213 | { |
|
213 | { | |
214 | QString error; |
|
214 | return PyType_Type.tp_setattro(obj,name,value); | |
215 | char *attributeName; |
|
|||
216 | if ((attributeName = PyString_AsString(name)) == NULL) { |
|
|||
217 | return -1; |
|
|||
218 | } |
|
|||
219 | PythonQtClassWrapper *wrapper = (PythonQtClassWrapper *)obj; |
|
|||
220 |
|
||||
221 | // TODO |
|
|||
222 | return -1; |
|
|||
223 | } |
|
215 | } | |
224 |
|
216 | |||
225 | /* |
|
217 | /* |
@@ -183,14 +183,14 int PythonQtInstanceWrapper_init(PythonQtInstanceWrapper * self, PyObject * args | |||||
183 | return 0; |
|
183 | return 0; | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 |
static PyObject *PythonQtInstanceWrapper_classname(PythonQtInstanceWrapper* |
|
186 | static PyObject *PythonQtInstanceWrapper_classname(PythonQtInstanceWrapper* obj) | |
187 | { |
|
187 | { | |
188 |
return PyString_FromString( |
|
188 | return PyString_FromString(obj->ob_type->tp_name); | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 |
static PyObject *PythonQtInstanceWrapper_help(PythonQtInstanceWrapper* |
|
191 | static PyObject *PythonQtInstanceWrapper_help(PythonQtInstanceWrapper* obj) | |
192 | { |
|
192 | { | |
193 |
return PythonQt::self()->helpCalled( |
|
193 | return PythonQt::self()->helpCalled(obj->classInfo()); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | static PyObject *PythonQtInstanceWrapper_delete(PythonQtInstanceWrapper * self) |
|
196 | static PyObject *PythonQtInstanceWrapper_delete(PythonQtInstanceWrapper * self) | |
@@ -232,6 +232,10 static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name) | |||||
232 | PyDict_SetItemString(dict, name.toLatin1().data(), o); |
|
232 | PyDict_SetItemString(dict, name.toLatin1().data(), o); | |
233 | Py_DECREF(o); |
|
233 | Py_DECREF(o); | |
234 | } |
|
234 | } | |
|
235 | // TODO xxx: | |||
|
236 | // this does include python member methods, but not attributes, from where can we get | |||
|
237 | // the correct dict with the attributes of the derive | |||
|
238 | ||||
235 | // Note: we do not put children into the dict, is would look confusing?! |
|
239 | // Note: we do not put children into the dict, is would look confusing?! | |
236 | return dict; |
|
240 | return dict; | |
237 | } |
|
241 | } | |
@@ -338,13 +342,21 static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObjec | |||||
338 | + QString(value->ob_type->tp_name) + " (" + PythonQtConv::PyObjGetRepresentation(value) + ")"; |
|
342 | + QString(value->ob_type->tp_name) + " (" + PythonQtConv::PyObjGetRepresentation(value) + ")"; | |
339 | } |
|
343 | } | |
340 | } else { |
|
344 | } else { | |
341 |
error = QString("Property '") + attributeName + "' of " + |
|
345 | error = QString("Property '") + attributeName + "' of " + obj->ob_type->tp_name + " object is not writable"; | |
342 | } |
|
346 | } | |
343 | } else { |
|
347 | } else if (member._type == PythonQtMemberInfo::Slot) { | |
344 | if (member._type == PythonQtMemberInfo::Slot) { |
|
348 | error = QString("Slot '") + attributeName + "' can not be overwritten on " + obj->ob_type->tp_name + " object"; | |
345 | error = QString("Slot '") + attributeName + "' can not be overwritten on " + wrapper->classInfo()->className() + " object"; |
|
|||
346 |
|
|
349 | } else if (member._type == PythonQtMemberInfo::EnumValue) { | |
347 |
|
|
350 | error = QString("EnumValue '") + attributeName + "' can not be overwritten on " + obj->ob_type->tp_name + " object"; | |
|
351 | } else if (member._type == PythonQtMemberInfo::NotFound) { | |||
|
352 | // if we are a derived python class, we allow setting attributes. | |||
|
353 | // if we are a direct CPP wrapper, we do NOT allow it, since | |||
|
354 | // it would be confusing to allow it because a wrapper will go away when it is not seen by python anymore | |||
|
355 | // and when it is recreated from a CPP pointer the attributes are gone... | |||
|
356 | if (obj->ob_type->tp_base != &PythonQtInstanceWrapper_Type) { | |||
|
357 | return PyBaseObject_Type.tp_setattro(obj,name,value); | |||
|
358 | } else { | |||
|
359 | error = QString("'") + attributeName + "' does not exist on " + obj->ob_type->tp_name + " and creating new attributes on C++ objects is not allowed"; | |||
348 | } |
|
360 | } | |
349 | } |
|
361 | } | |
350 |
|
362 | |||
@@ -389,7 +401,7 static PyObject * PythonQtInstanceWrapper_repr(PyObject * obj) | |||||
389 | return PyString_FromFormat("%s (C++ Object %p)", typeName, wrapper->_wrappedPtr); |
|
401 | return PyString_FromFormat("%s (C++ Object %p)", typeName, wrapper->_wrappedPtr); | |
390 | } |
|
402 | } | |
391 | } else { |
|
403 | } else { | |
392 | return PyString_FromFormat("%s (QObject %p)", wrapper->classInfo()->className(), qobj); |
|
404 | return PyString_FromFormat("%s (QObject %p)", typeName, wrapper->classInfo()->className(), qobj); | |
393 | } |
|
405 | } | |
394 | } |
|
406 | } | |
395 |
|
407 |
General Comments 0
You need to be logged in to leave comments.
Login now