Python feature/observer related changes
* Add new API and signal handler in document observer * Pre initialize python handler function to improve performance. In case Python code use dynamic patching, i.e. add class method at runtime (which is rare and should be discouraged), the python feature can be re-initialized by simply assign proeprty Proxy again. * Add property tracking in DocumentObjectT * WidgetFactory adds support for accepting python QIcon, which is used by ViewProviderPythonFeature
This commit is contained in:
@@ -59,95 +59,38 @@ void DocumentObserverPython::removeObserver(const Py::Object& obj)
|
||||
|
||||
DocumentObserverPython::DocumentObserverPython(const Py::Object& obj) : inst(obj)
|
||||
{
|
||||
this->connectApplicationCreatedDocument = App::GetApplication().signalNewDocument.connect(boost::bind
|
||||
(&DocumentObserverPython::slotCreatedDocument, this, _1));
|
||||
this->connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument.connect(boost::bind
|
||||
(&DocumentObserverPython::slotDeletedDocument, this, _1));
|
||||
this->connectApplicationRelabelDocument = App::GetApplication().signalRelabelDocument.connect(boost::bind
|
||||
(&DocumentObserverPython::slotRelabelDocument, this, _1));
|
||||
this->connectApplicationActivateDocument = App::GetApplication().signalActiveDocument.connect(boost::bind
|
||||
(&DocumentObserverPython::slotActivateDocument, this, _1));
|
||||
this->connectApplicationUndoDocument = App::GetApplication().signalUndoDocument.connect(boost::bind
|
||||
(&DocumentObserverPython::slotUndoDocument, this, _1));
|
||||
this->connectApplicationRedoDocument = App::GetApplication().signalRedoDocument.connect(boost::bind
|
||||
(&DocumentObserverPython::slotRedoDocument, this, _1));
|
||||
#define signalCreatedDocument signalNewDocument
|
||||
#define signalCreatedObject signalNewObject
|
||||
#define signalRecomputedObject signalObjectRecomputed
|
||||
#define signalRecomputedDocument signalRecomputed
|
||||
#define signalActivateDocument signalActiveDocument
|
||||
#define signalDeletedDocument signalDeleteDocument
|
||||
|
||||
this->connectDocumentBeforeChange = App::GetApplication().signalBeforeChangeDocument.connect(boost::bind
|
||||
(&DocumentObserverPython::slotBeforeChangeDocument, this, _1, _2));
|
||||
this->connectDocumentChanged = App::GetApplication().signalChangedDocument.connect(boost::bind
|
||||
(&DocumentObserverPython::slotChangedDocument, this, _1, _2));
|
||||
this->connectDocumentCreatedObject = App::GetApplication().signalNewObject.connect(boost::bind
|
||||
(&DocumentObserverPython::slotCreatedObject, this, _1));
|
||||
this->connectDocumentDeletedObject = App::GetApplication().signalDeletedObject.connect(boost::bind
|
||||
(&DocumentObserverPython::slotDeletedObject, this, _1));
|
||||
this->connectDocumentBeforeChangeObject = App::GetApplication().signalBeforeChangeObject.connect(boost::bind
|
||||
(&DocumentObserverPython::slotBeforeChangeObject, this, _1, _2));
|
||||
this->connectDocumentChangedObject = App::GetApplication().signalChangedObject.connect(boost::bind
|
||||
(&DocumentObserverPython::slotChangedObject, this, _1, _2));
|
||||
#undef FC_PY_ELEMENT
|
||||
#define FC_PY_ELEMENT(_name,...) do{\
|
||||
FC_PY_GetCallable(obj.ptr(),"slot" #_name, py##_name);\
|
||||
if(!py##_name.isNone())\
|
||||
connect##_name = App::GetApplication().signal##_name.connect(\
|
||||
boost::bind(&DocumentObserverPython::slot##_name, this, ##__VA_ARGS__));\
|
||||
}while(0);
|
||||
|
||||
this->connectDocumentObjectRecomputed = App::GetApplication().signalObjectRecomputed.connect(boost::bind
|
||||
(&DocumentObserverPython::slotRecomputedObject, this, _1));
|
||||
this->connectDocumentRecomputed = App::GetApplication().signalRecomputed.connect(boost::bind
|
||||
(&DocumentObserverPython::slotRecomputedDocument, this, _1));
|
||||
|
||||
this->connectDocumentOpenTransaction = App::GetApplication().signalOpenTransaction.connect(boost::bind
|
||||
(&DocumentObserverPython::slotOpenTransaction, this, _1, _2));
|
||||
this->connectDocumentCommitTransaction = App::GetApplication().signalCommitTransaction.connect(boost::bind
|
||||
(&DocumentObserverPython::slotCommitTransaction, this, _1));
|
||||
this->connectDocumentAbortTransaction = App::GetApplication().signalAbortTransaction.connect(boost::bind
|
||||
(&DocumentObserverPython::slotAbortTransaction, this, _1));
|
||||
|
||||
this->connectDocumentStartSave = App::GetApplication().signalStartSaveDocument.connect(boost::bind
|
||||
(&DocumentObserverPython::slotStartSaveDocument, this, _1, _2));
|
||||
this->connectDocumentFinishSave = App::GetApplication().signalFinishSaveDocument.connect(boost::bind
|
||||
(&DocumentObserverPython::slotFinishSaveDocument, this, _1, _2));
|
||||
|
||||
this->connectObjectAppendDynamicProperty = App::GetApplication().signalAppendDynamicProperty.connect(boost::bind
|
||||
(&DocumentObserverPython::slotAppendDynamicProperty, this, _1));
|
||||
this->connectObjectRemoveDynamicProperty = App::GetApplication().signalRemoveDynamicProperty.connect(boost::bind
|
||||
(&DocumentObserverPython::slotRemoveDynamicProperty, this, _1));
|
||||
this->connectObjectChangePropertyEditor = App::GetApplication().signalChangePropertyEditor.connect(boost::bind
|
||||
(&DocumentObserverPython::slotChangePropertyEditor, this, _1));
|
||||
FC_PY_DOC_OBSERVER
|
||||
}
|
||||
|
||||
DocumentObserverPython::~DocumentObserverPython()
|
||||
{
|
||||
this->connectApplicationCreatedDocument.disconnect();
|
||||
this->connectApplicationDeletedDocument.disconnect();
|
||||
this->connectApplicationRelabelDocument.disconnect();
|
||||
this->connectApplicationActivateDocument.disconnect();
|
||||
this->connectApplicationUndoDocument.disconnect();
|
||||
this->connectApplicationRedoDocument.disconnect();
|
||||
|
||||
this->connectDocumentBeforeChange.disconnect();
|
||||
this->connectDocumentChanged.disconnect();
|
||||
this->connectDocumentCreatedObject.disconnect();
|
||||
this->connectDocumentDeletedObject.disconnect();
|
||||
this->connectDocumentBeforeChangeObject.disconnect();
|
||||
this->connectDocumentChangedObject.disconnect();
|
||||
this->connectDocumentObjectRecomputed.disconnect();
|
||||
this->connectDocumentRecomputed.disconnect();
|
||||
this->connectDocumentOpenTransaction.disconnect();
|
||||
this->connectDocumentCommitTransaction.disconnect();
|
||||
this->connectDocumentAbortTransaction.disconnect();
|
||||
this->connectDocumentStartSave.disconnect();
|
||||
this->connectDocumentFinishSave.disconnect();
|
||||
|
||||
this->connectObjectAppendDynamicProperty.disconnect();
|
||||
this->connectObjectRemoveDynamicProperty.disconnect();
|
||||
this->connectObjectChangePropertyEditor.disconnect();
|
||||
#undef FC_PY_ELEMENT
|
||||
#define FC_PY_ELEMENT(_name,...) connect##_name.disconnect();
|
||||
FC_PY_DOC_OBSERVER
|
||||
}
|
||||
|
||||
void DocumentObserverPython::slotCreatedDocument(const App::Document& Doc)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotCreatedDocument"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotCreatedDocument")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).getPyObject(), true));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).getPyObject(), true));
|
||||
Base::pyCall(pyCreatedDocument.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -159,12 +102,9 @@ void DocumentObserverPython::slotDeletedDocument(const App::Document& Doc)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotDeletedDocument"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotDeletedDocument")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).getPyObject(), true));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).getPyObject(), true));
|
||||
Base::pyCall(pyDeletedDocument.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -176,12 +116,9 @@ void DocumentObserverPython::slotRelabelDocument(const App::Document& Doc)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotRelabelDocument"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotRelabelDocument")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).getPyObject(), true));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).getPyObject(), true));
|
||||
Base::pyCall(pyRelabelDocument.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -193,12 +130,9 @@ void DocumentObserverPython::slotActivateDocument(const App::Document& Doc)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotActivateDocument"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotActivateDocument")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).getPyObject(), true));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).getPyObject(), true));
|
||||
Base::pyCall(pyActivateDocument.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -210,12 +144,9 @@ void DocumentObserverPython::slotUndoDocument(const App::Document& Doc)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotUndoDocument"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotUndoDocument")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).getPyObject(), true));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).getPyObject(), true));
|
||||
Base::pyCall(pyUndoDocument.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -223,16 +154,66 @@ void DocumentObserverPython::slotUndoDocument(const App::Document& Doc)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DocumentObserverPython::slotRedoDocument(const App::Document& Doc)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotRedoDocument"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotRedoDocument")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).getPyObject(), true));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).getPyObject(), true));
|
||||
Base::pyCall(pyRedoDocument.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentObserverPython::slotUndo()
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Base::pyCall(pyUndo.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentObserverPython::slotRedo()
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Base::pyCall(pyRedo.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentObserverPython::slotBeforeCloseTransaction(bool abort)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Boolean(abort));
|
||||
Base::pyCall(pyBeforeCloseTransaction.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentObserverPython::slotCloseTransaction(bool abort)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Boolean(abort));
|
||||
Base::pyCall(pyCloseTransaction.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -244,17 +225,14 @@ void DocumentObserverPython::slotBeforeChangeDocument(const App::Document& Doc,
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotBeforeChangeDocument"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotBeforeChangeDocument")));
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).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 = Doc.getPropertyName(&Prop);
|
||||
if (prop_name) {
|
||||
args.setItem(1, Py::String(prop_name));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).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 = Doc.getPropertyName(&Prop);
|
||||
if (prop_name) {
|
||||
args.setItem(1, Py::String(prop_name));
|
||||
Base::pyCall(pyBeforeChangeDocument.ptr(),args.ptr());
|
||||
}
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
@@ -267,17 +245,14 @@ void DocumentObserverPython::slotChangedDocument(const App::Document& Doc, const
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotChangedDocument"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotChangedDocument")));
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).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 = Doc.getPropertyName(&Prop);
|
||||
if (prop_name) {
|
||||
args.setItem(1, Py::String(prop_name));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(Doc).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 = Doc.getPropertyName(&Prop);
|
||||
if (prop_name) {
|
||||
args.setItem(1, Py::String(prop_name));
|
||||
Base::pyCall(pyChangedDocument.ptr(),args.ptr());
|
||||
}
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
@@ -290,12 +265,9 @@ void DocumentObserverPython::slotCreatedObject(const App::DocumentObject& Obj)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotCreatedObject"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotCreatedObject")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::DocumentObject&>(Obj).getPyObject(), true));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::DocumentObject&>(Obj).getPyObject(), true));
|
||||
Base::pyCall(pyCreatedObject.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -307,12 +279,9 @@ void DocumentObserverPython::slotDeletedObject(const App::DocumentObject& Obj)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotDeletedObject"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotDeletedObject")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::DocumentObject&>(Obj).getPyObject(), true));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::DocumentObject&>(Obj).getPyObject(), true));
|
||||
Base::pyCall(pyDeletedObject.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -325,17 +294,14 @@ void DocumentObserverPython::slotBeforeChangeObject(const App::DocumentObject& O
|
||||
{
|
||||
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);
|
||||
}
|
||||
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));
|
||||
Base::pyCall(pyBeforeChangeObject.ptr(),args.ptr());
|
||||
}
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
@@ -349,17 +315,14 @@ void DocumentObserverPython::slotChangedObject(const App::DocumentObject& Obj,
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotChangedObject"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotChangedObject")));
|
||||
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);
|
||||
}
|
||||
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));
|
||||
Base::pyCall(pyChangedObject.ptr(),args.ptr());
|
||||
}
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
@@ -372,12 +335,9 @@ void DocumentObserverPython::slotRecomputedObject(const App::DocumentObject& Obj
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotRecomputedObject"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotRecomputedObject")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::DocumentObject&>(Obj).getPyObject(), true));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::DocumentObject&>(Obj).getPyObject(), true));
|
||||
Base::pyCall(pyRecomputedObject.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -389,12 +349,23 @@ void DocumentObserverPython::slotRecomputedDocument(const App::Document& doc)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotRecomputedDocument"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotRecomputedDocument")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
Base::pyCall(pyRecomputedDocument.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentObserverPython::slotBeforeRecomputeDocument(const App::Document& doc)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
Base::pyCall(pyBeforeRecomputeDocument.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -406,13 +377,10 @@ void DocumentObserverPython::slotOpenTransaction(const App::Document& doc, std::
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotOpenTransaction"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotOpenTransaction")));
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
args.setItem(1, Py::String(str));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
args.setItem(1, Py::String(str));
|
||||
Base::pyCall(pyOpenTransaction.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -424,12 +392,9 @@ void DocumentObserverPython::slotCommitTransaction(const App::Document& doc)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotCommitTransaction"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotCommitTransaction")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
Base::pyCall(pyCommitTransaction.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -441,12 +406,9 @@ void DocumentObserverPython::slotAbortTransaction(const App::Document& doc)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotAbortTransaction"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotAbortTransaction")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
Base::pyCall(pyAbortTransaction.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -458,18 +420,15 @@ void DocumentObserverPython::slotAppendDynamicProperty(const App::Property& Prop
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotAppendDynamicProperty"))) {
|
||||
auto container = Prop.getContainer();
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotAppendDynamicProperty")));
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(container->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 = container->getPropertyName(&Prop);
|
||||
if (prop_name) {
|
||||
args.setItem(1, Py::String(prop_name));
|
||||
method.apply(args);
|
||||
}
|
||||
auto container = Prop.getContainer();
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(container->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 = container->getPropertyName(&Prop);
|
||||
if (prop_name) {
|
||||
args.setItem(1, Py::String(prop_name));
|
||||
Base::pyCall(pyAppendDynamicProperty.ptr(),args.ptr());
|
||||
}
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
@@ -482,18 +441,15 @@ void DocumentObserverPython::slotRemoveDynamicProperty(const App::Property& Prop
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotRemoveDynamicProperty"))) {
|
||||
auto container = Prop.getContainer();
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotRemoveDynamicProperty")));
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(container->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 = container->getPropertyName(&Prop);
|
||||
if (prop_name) {
|
||||
args.setItem(1, Py::String(prop_name));
|
||||
method.apply(args);
|
||||
}
|
||||
auto container = Prop.getContainer();
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(container->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 = container->getPropertyName(&Prop);
|
||||
if (prop_name) {
|
||||
args.setItem(1, Py::String(prop_name));
|
||||
Base::pyCall(pyRemoveDynamicProperty.ptr(),args.ptr());
|
||||
}
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
@@ -502,22 +458,19 @@ void DocumentObserverPython::slotRemoveDynamicProperty(const App::Property& Prop
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentObserverPython::slotChangePropertyEditor(const App::Property& Prop)
|
||||
void DocumentObserverPython::slotChangePropertyEditor(const App::Document &, const App::Property& Prop)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotChangePropertyEditor"))) {
|
||||
auto container = Prop.getContainer();
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotChangePropertyEditor")));
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(container->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 = container->getPropertyName(&Prop);
|
||||
if (prop_name) {
|
||||
args.setItem(1, Py::String(prop_name));
|
||||
method.apply(args);
|
||||
}
|
||||
auto container = Prop.getContainer();
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(container->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 = container->getPropertyName(&Prop);
|
||||
if (prop_name) {
|
||||
args.setItem(1, Py::String(prop_name));
|
||||
Base::pyCall(pyChangePropertyEditor.ptr(),args.ptr());
|
||||
}
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
@@ -530,13 +483,10 @@ void DocumentObserverPython::slotStartSaveDocument(const App::Document& doc, con
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotStartSaveDocument"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotStartSaveDocument")));
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
args.setItem(1, Py::String(file));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
args.setItem(1, Py::String(file));
|
||||
Base::pyCall(pyStartSaveDocument.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
@@ -548,13 +498,10 @@ void DocumentObserverPython::slotFinishSaveDocument(const App::Document& doc, co
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
if (this->inst.hasAttr(std::string("slotFinishSaveDocument"))) {
|
||||
Py::Callable method(this->inst.getAttr(std::string("slotFinishSaveDocument")));
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
args.setItem(1, Py::String(file));
|
||||
method.apply(args);
|
||||
}
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
|
||||
args.setItem(1, Py::String(file));
|
||||
Base::pyCall(pyFinishSaveDocument.ptr(),args.ptr());
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
|
||||
Reference in New Issue
Block a user