+ add slots for undo/redo to Python document observer

This commit is contained in:
wmayer 2015-02-18 21:36:47 +01:00
parent 22b63a7653
commit a869033925
2 changed files with 46 additions and 0 deletions

View File

@ -67,6 +67,10 @@ DocumentObserverPython::DocumentObserverPython(const Py::Object& obj) : inst(obj
(&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));
this->connectDocumentCreatedObject = App::GetApplication().signalNewObject.connect(boost::bind
(&DocumentObserverPython::slotCreatedObject, this, _1));
@ -82,6 +86,8 @@ DocumentObserverPython::~DocumentObserverPython()
this->connectApplicationDeletedDocument.disconnect();
this->connectApplicationRelabelDocument.disconnect();
this->connectApplicationActivateDocument.disconnect();
this->connectApplicationUndoDocument.disconnect();
this->connectApplicationRedoDocument.disconnect();
this->connectDocumentCreatedObject.disconnect();
this->connectDocumentDeletedObject.disconnect();
@ -156,6 +162,40 @@ void DocumentObserverPython::slotActivateDocument(const App::Document& Doc)
}
}
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);
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
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);
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
void DocumentObserverPython::slotCreatedObject(const App::DocumentObject& Obj)
{
Base::PyGILStateLocker lock;

View File

@ -65,6 +65,10 @@ private:
void slotDeletedObject(const App::DocumentObject& Obj);
/** The property of an observed object has changed */
void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop);
/** Undoes the last transaction of the document */
void slotUndoDocument(const App::Document& Doc);
/** Redoes the last undone transaction of the document */
void slotRedoDocument(const App::Document& Doc);
private:
Py::Object inst;
@ -75,6 +79,8 @@ private:
Connection connectApplicationDeletedDocument;
Connection connectApplicationRelabelDocument;
Connection connectApplicationActivateDocument;
Connection connectApplicationUndoDocument;
Connection connectApplicationRedoDocument;
Connection connectDocumentCreatedObject;
Connection connectDocumentDeletedObject;
Connection connectDocumentChangedObject;