+ expose onDocumentRestored to Python feature classes

This commit is contained in:
wmayer
2016-01-05 19:05:48 +01:00
parent 2709266e83
commit a83e09d6e2
3 changed files with 40 additions and 0 deletions

View File

@@ -154,6 +154,35 @@ void FeaturePythonImp::onChanged(const Property* prop)
}
}
void FeaturePythonImp::onDocumentRestored()
{
// Run the execute method of the proxy object.
Base::PyGILStateLocker lock;
try {
Property* proxy = object->getPropertyByName("Proxy");
if (proxy && proxy->getTypeId() == PropertyPythonObject::getClassTypeId()) {
Py::Object feature = static_cast<PropertyPythonObject*>(proxy)->getValue();
if (feature.hasAttr(std::string("onDocumentRestored"))) {
if (feature.hasAttr("__object__")) {
Py::Callable method(feature.getAttr(std::string("onDocumentRestored")));
Py::Tuple args;
method.apply(args);
}
else {
Py::Callable method(feature.getAttr(std::string("onDocumentRestored")));
Py::Tuple args(1);
args.setItem(0, Py::Object(object->getPyObject(), true));
method.apply(args);
}
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
PyObject *FeaturePythonImp::getPyObject(void)
{
// ref counter is set to 1