+ implement onDelete for Python proxy of view provider

This commit is contained in:
wmayer
2015-07-16 16:13:39 +02:00
parent 3241b1ece1
commit 6b3d7b17a7
2 changed files with 46 additions and 0 deletions

View File

@@ -670,6 +670,46 @@ void ViewProviderPythonFeatureImp::finishRestoring()
}
}
bool ViewProviderPythonFeatureImp::onDelete(const std::vector<std::string> & sub)
{
Base::PyGILStateLocker lock;
try {
App::Property* proxy = object->getPropertyByName("Proxy");
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
if (vp.hasAttr(std::string("onDelete"))) {
Py::Tuple seq(sub.size());
int index=0;
for (std::vector<std::string>::const_iterator it = sub.begin(); it != sub.end(); ++it) {
seq.setItem(index++, Py::String(*it));
}
if (vp.hasAttr("__object__")) {
Py::Callable method(vp.getAttr(std::string("onDelete")));
Py::Tuple args(1);
args.setItem(0, seq);
Py::Boolean ok(method.apply(args));
return (bool)ok;
}
else {
Py::Callable method(vp.getAttr(std::string("onDelete")));
Py::Tuple args(2);
args.setItem(0, Py::Object(object->getPyObject(), true));
args.setItem(1, seq);
Py::Boolean ok(method.apply(args));
return (bool)ok;
}
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
return true;
}
const char* ViewProviderPythonFeatureImp::getDefaultDisplayMode() const
{
// Run the getDefaultDisplayMode method of the proxy object.