From 83caf9d67ba419e0ab8769106a89a8f427e11a74 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 24 Feb 2014 11:30:27 +0100 Subject: [PATCH] + detect from Python whether a document is modified, give option to suppress warning from SendMsgToActiveView --- src/Gui/ApplicationPy.cpp | 9 ++++++--- src/Gui/DocumentPy.xml | 8 +++++++- src/Gui/DocumentPyImp.cpp | 5 +++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index f0f6d9abc579..373ec7fa9439 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -405,12 +405,15 @@ PyObject* Application::sExport(PyObject * /*self*/, PyObject *args,PyObject * /* PyObject* Application::sSendActiveView(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) { char *psCommandStr; - if (!PyArg_ParseTuple(args, "s",&psCommandStr)) // convert args: Python->C + PyObject *suppress=Py_False; + if (!PyArg_ParseTuple(args, "s|O!",&psCommandStr,&PyBool_Type,&suppress)) // convert args: Python->C return NULL; // NULL triggers exception const char* ppReturn=0; - if (!Instance->sendMsgToActiveView(psCommandStr,&ppReturn)) - Base::Console().Warning("Unknown view command: %s\n",psCommandStr); + if (!Instance->sendMsgToActiveView(psCommandStr,&ppReturn)) { + if (!PyObject_IsTrue(suppress)) + Base::Console().Warning("Unknown view command: %s\n",psCommandStr); + } // Print the return value to the output if (ppReturn) { diff --git a/src/Gui/DocumentPy.xml b/src/Gui/DocumentPy.xml index da5795a6c207..629a69ed4e1c 100644 --- a/src/Gui/DocumentPy.xml +++ b/src/Gui/DocumentPy.xml @@ -106,5 +106,11 @@ - + + + Returns True if the document is marked as modified, and False otherwse + + + + diff --git a/src/Gui/DocumentPyImp.cpp b/src/Gui/DocumentPyImp.cpp index 450fca8bda56..de06e242b939 100644 --- a/src/Gui/DocumentPyImp.cpp +++ b/src/Gui/DocumentPyImp.cpp @@ -321,6 +321,11 @@ Py::Object DocumentPy::getDocument(void) const } } +Py::Boolean DocumentPy::getModified(void) const +{ + return Py::Boolean(getDocumentPtr()->isModified()); +} + PyObject *DocumentPy::getCustomAttributes(const char* attr) const { // Note: Here we want to return only a document object if its