From 5daedfb035c839386f5330ae4c91171d55d90f9b 2009-04-22 09:05:25 From: florianlink Date: 2009-04-22 09:05:25 Subject: [PATCH] improved so that dict contains properties and that dir() shows all available things, including the derived base attributes git-svn-id: svn://svn.code.sf.net/p/pythonqt/code/trunk@70 ea8d5007-eb21-0410-b261-ccb3ea6e24a9 --- diff --git a/src/PythonQtClassInfo.cpp b/src/PythonQtClassInfo.cpp index 53d836f..f322c64 100644 --- a/src/PythonQtClassInfo.cpp +++ b/src/PythonQtClassInfo.cpp @@ -403,14 +403,11 @@ void PythonQtClassInfo::listDecoratorSlotsFromDecoratorProvider(QStringList& lis } } } - -QStringList PythonQtClassInfo::memberList(bool metaOnly) -{ - decorator(); +QStringList PythonQtClassInfo::propertyList() +{ QStringList l; - QString h; - if (_isQObject && _meta && !metaOnly) { + if (_isQObject && _meta) { int i; int numProperties = _meta->propertyCount(); for (i = 0; i < numProperties; i++) { @@ -418,6 +415,18 @@ QStringList PythonQtClassInfo::memberList(bool metaOnly) l << QString(p.name()); } } + return l; +} + +QStringList PythonQtClassInfo::memberList(bool metaOnly) +{ + decorator(); + + QStringList l; + QString h; + if (_isQObject && _meta && !metaOnly) { + l = propertyList(); + } // normal slots of QObject (or wrapper QObject) if (!metaOnly && _meta) { diff --git a/src/PythonQtClassInfo.h b/src/PythonQtClassInfo.h index 2b6fd38..1acbfff 100644 --- a/src/PythonQtClassInfo.h +++ b/src/PythonQtClassInfo.h @@ -148,6 +148,9 @@ public: //! get help string for the metaobject QString help(); + //! get list of all properties (on QObjects only, otherwise the list is empty) + QStringList propertyList(); + //! get list of all members QStringList memberList(bool metaOnly = false); diff --git a/src/PythonQtInstanceWrapper.cpp b/src/PythonQtInstanceWrapper.cpp index 53875d0..21c5c6a 100644 --- a/src/PythonQtInstanceWrapper.cpp +++ b/src/PythonQtInstanceWrapper.cpp @@ -225,17 +225,21 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name) } if (qstrcmp(attributeName, "__dict__")==0) { - QStringList l = wrapper->classInfo()->memberList(false); - PyObject* dict = PyDict_New(); + PyObject* dict = PyBaseObject_Type.tp_getattro(obj, name); + dict = PyDict_Copy(dict); + + // only the properties are missing, the rest is already available from + // PythonQtClassWrapper... + QStringList l = wrapper->classInfo()->propertyList(); foreach (QString name, l) { PyObject* o = PyObject_GetAttrString(obj, name.toLatin1().data()); - PyDict_SetItemString(dict, name.toLatin1().data(), o); - Py_DECREF(o); + if (o) { + PyDict_SetItemString(dict, name.toLatin1().data(), o); + Py_DECREF(o); + } else { + std::cerr << "PythonQtInstanceWrapper: something is wrong, could not get attribute " << name.toLatin1().data(); + } } - // TODO xxx: - // this does include python member methods, but not attributes, from where can we get - // the correct dict with the attributes of the derive - // Note: we do not put children into the dict, is would look confusing?! return dict; }