+ implement onDelete for Python proxy of view provider
This commit is contained in:
parent
3241b1ece1
commit
6b3d7b17a7
|
@ -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.
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
void onChanged(const App::Property* prop);
|
||||
void startRestoring();
|
||||
void finishRestoring();
|
||||
bool onDelete(const std::vector<std::string> & sub);
|
||||
//@}
|
||||
|
||||
/** @name Display methods */
|
||||
|
@ -156,6 +157,11 @@ public:
|
|||
virtual void getTaskViewContent(std::vector<Gui::TaskView::TaskContent*>& c) const {
|
||||
ViewProviderT::getTaskViewContent(c);
|
||||
}
|
||||
virtual bool onDelete(const std::vector<std::string> & sub) {
|
||||
bool ok = imp->onDelete(sub);
|
||||
if (!ok) return ok;
|
||||
return ViewProviderT::onDelete(sub);
|
||||
}
|
||||
//@}
|
||||
|
||||
/** @name Restoring view provider from document load */
|
||||
|
|
Loading…
Reference in New Issue
Block a user