Expose onBeforeChange to python document observer

This commit is contained in:
ickby
2017-08-15 06:26:26 +02:00
committed by wmayer
parent 0edf6892b3
commit 238c8a8567
6 changed files with 42 additions and 0 deletions

View File

@@ -76,6 +76,8 @@ DocumentObserverPython::DocumentObserverPython(const Py::Object& obj) : inst(obj
(&DocumentObserverPython::slotCreatedObject, this, _1));
this->connectDocumentDeletedObject = App::GetApplication().signalDeletedObject.connect(boost::bind
(&DocumentObserverPython::slotDeletedObject, this, _1));
this->connectDocumentChangedObject = App::GetApplication().signalBeforeChangeObject.connect(boost::bind
(&DocumentObserverPython::slotBeforeChangeObject, this, _1, _2));
this->connectDocumentChangedObject = App::GetApplication().signalChangedObject.connect(boost::bind
(&DocumentObserverPython::slotChangedObject, this, _1, _2));
@@ -247,6 +249,30 @@ void DocumentObserverPython::slotDeletedObject(const App::DocumentObject& Obj)
}
}
void DocumentObserverPython::slotBeforeChangeObject(const App::DocumentObject& Obj,
const App::Property& Prop)
{
Base::PyGILStateLocker lock;
try {
if (this->inst.hasAttr(std::string("slotBeforeChangeObject"))) {
Py::Callable method(this->inst.getAttr(std::string("slotBeforeChangeObject")));
Py::Tuple args(2);
args.setItem(0, Py::Object(const_cast<App::DocumentObject&>(Obj).getPyObject(), true));
// If a property is touched but not part of a document object then its name is null.
// In this case the slot function must not be called.
const char* prop_name = Obj.getPropertyName(&Prop);
if (prop_name) {
args.setItem(1, Py::String(prop_name));
method.apply(args);
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
void DocumentObserverPython::slotChangedObject(const App::DocumentObject& Obj,
const App::Property& Prop)
{