Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
+ implement onDelete for Python proxy of view provider
  • Loading branch information
wwmayer committed Jul 16, 2015
1 parent 3241b1e commit 6b3d7b1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Gui/ViewProviderPythonFeature.cpp
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/Gui/ViewProviderPythonFeature.h
Expand Up @@ -62,6 +62,7 @@ class GuiExport ViewProviderPythonFeatureImp
void onChanged(const App::Property* prop);
void startRestoring();
void finishRestoring();
bool onDelete(const std::vector<std::string> & sub);
//@}

/** @name Display methods */
Expand Down Expand Up @@ -156,6 +157,11 @@ class ViewProviderPythonFeatureT : public ViewProviderT
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 */
Expand Down

0 comments on commit 6b3d7b1

Please sign in to comment.