##// END OF EJS Templates
improved so that dict contains properties and that dir() shows all available things, including the derived base attributes...
florianlink -
r34:5daedfb035c8
parent child
Show More
@@ -403,14 +403,11 void PythonQtClassInfo::listDecoratorSlotsFromDecoratorProvider(QStringList& lis
403 403 }
404 404 }
405 405 }
406
407 QStringList PythonQtClassInfo::memberList(bool metaOnly)
408 {
409 decorator();
410 406
407 QStringList PythonQtClassInfo::propertyList()
408 {
411 409 QStringList l;
412 QString h;
413 if (_isQObject && _meta && !metaOnly) {
410 if (_isQObject && _meta) {
414 411 int i;
415 412 int numProperties = _meta->propertyCount();
416 413 for (i = 0; i < numProperties; i++) {
@@ -418,6 +415,18 QStringList PythonQtClassInfo::memberList(bool metaOnly)
418 415 l << QString(p.name());
419 416 }
420 417 }
418 return l;
419 }
420
421 QStringList PythonQtClassInfo::memberList(bool metaOnly)
422 {
423 decorator();
424
425 QStringList l;
426 QString h;
427 if (_isQObject && _meta && !metaOnly) {
428 l = propertyList();
429 }
421 430
422 431 // normal slots of QObject (or wrapper QObject)
423 432 if (!metaOnly && _meta) {
@@ -148,6 +148,9 public:
148 148 //! get help string for the metaobject
149 149 QString help();
150 150
151 //! get list of all properties (on QObjects only, otherwise the list is empty)
152 QStringList propertyList();
153
151 154 //! get list of all members
152 155 QStringList memberList(bool metaOnly = false);
153 156
@@ -225,17 +225,21 static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
225 225 }
226 226
227 227 if (qstrcmp(attributeName, "__dict__")==0) {
228 QStringList l = wrapper->classInfo()->memberList(false);
229 PyObject* dict = PyDict_New();
228 PyObject* dict = PyBaseObject_Type.tp_getattro(obj, name);
229 dict = PyDict_Copy(dict);
230
231 // only the properties are missing, the rest is already available from
232 // PythonQtClassWrapper...
233 QStringList l = wrapper->classInfo()->propertyList();
230 234 foreach (QString name, l) {
231 235 PyObject* o = PyObject_GetAttrString(obj, name.toLatin1().data());
232 PyDict_SetItemString(dict, name.toLatin1().data(), o);
233 Py_DECREF(o);
236 if (o) {
237 PyDict_SetItemString(dict, name.toLatin1().data(), o);
238 Py_DECREF(o);
239 } else {
240 std::cerr << "PythonQtInstanceWrapper: something is wrong, could not get attribute " << name.toLatin1().data();
241 }
234 242 }
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
239 243 // Note: we do not put children into the dict, is would look confusing?!
240 244 return dict;
241 245 }
General Comments 0
You need to be logged in to leave comments. Login now