Show dynamically added methods in calltips list

This commit is contained in:
wmayer 2013-03-24 13:29:13 +01:00
parent 295f6c3058
commit 24f559be9a
2 changed files with 26 additions and 7 deletions

View File

@ -383,11 +383,18 @@ PyObject *FeaturePythonPyT<FeaturePyT>::getCustomAttributes(const char* attr) co
{
PY_TRY{
if (Base::streq(attr, "__dict__")){
PyObject* dict = FeaturePyT::getCustomAttributes(attr);
if (dict){
std::vector<std::string> Props = FeaturePyT::getDocumentObjectPtr()->getDynamicPropertyNames();
for (std::vector<std::string>::const_iterator it = Props.begin(); it != Props.end(); ++it)
PyDict_SetItem(dict, PyString_FromString(it->c_str()), PyString_FromString(""));
// Return the default dict
PyTypeObject *tp = this->ob_type;
PyObject* dict = PyDict_Copy(tp->tp_dict);
std::map<std::string,App::Property*> Map;
FeaturePyT::getPropertyContainerPtr()->getPropertyMap(Map);
for (std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it)
PyDict_SetItem(dict, PyString_FromString(it->first.c_str()), PyString_FromString(""));
for (std::map<std::string, PyObject*>::const_iterator it = dyn_methods.begin(); it != dyn_methods.end(); ++it)
PyDict_SetItem(dict, PyString_FromString(it->first.c_str()), PyString_FromString(""));
if (PyErr_Occurred()) {
Py_DECREF(dict);
dict = 0;
}
return dict;
}

View File

@ -41,6 +41,7 @@
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <App/DocumentPy.h>
#include <App/DocumentObjectPy.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Document.h>
#include <Gui/DocumentPy.h>
@ -232,8 +233,19 @@ QMap<QString, CallTip> CallTipsList::extractTips(const QString& context) const
Py::Object type(PyObject_Type(obj.ptr()), true);
Py::Object inst = obj; // the object instance
union PyType_Object typeobj = {&Base::PyObjectBase::Type};
bool subclass = (PyObject_IsSubclass(type.ptr(), typeobj.o) == 1);
if (subclass) obj = type;
union PyType_Object typedoc = {&App::DocumentObjectPy::Type};
if (PyObject_IsSubclass(type.ptr(), typedoc.o) == 1) {
// From the template Python object we don't query its type object because there we keep
// a list of additional methods that we won't see otherwise. But to get the correct doc
// strings we query the type's dict in the class itself.
// To see if we have a template Python object we check for the existence of supportedProperties
if (!type.hasAttr("supportedProperties")) {
obj = type;
}
}
else if (PyObject_IsSubclass(type.ptr(), typeobj.o) == 1) {
obj = type;
}
// If we have an instance of PyObjectBase then determine whether it's valid or not
if (PyObject_IsInstance(inst.ptr(), typeobj.o) == 1) {