From 5e408445bea3cc66ccea0752de8ce47858ea02ad Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 31 Dec 2022 13:01:20 +0100 Subject: [PATCH] Gui: expose Document::save()/saveAs() to Python --- src/Gui/DocumentPy.xml | 12 ++++++++++++ src/Gui/DocumentPyImp.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Gui/DocumentPy.xml b/src/Gui/DocumentPy.xml index 6775d9a9a5..dfc0354719 100644 --- a/src/Gui/DocumentPy.xml +++ b/src/Gui/DocumentPy.xml @@ -97,6 +97,18 @@ Return a list of mdi views of a given type.\n type : str\n Type name. + + + save() -> bool\n +Attempts to save the document + + + + + saveAs() -> bool\n +Attempts to save the document under a new name + + sendMsgToViews(msg) -> None\n diff --git a/src/Gui/DocumentPyImp.cpp b/src/Gui/DocumentPyImp.cpp index e31e3bb0e7..0d105081ff 100644 --- a/src/Gui/DocumentPyImp.cpp +++ b/src/Gui/DocumentPyImp.cpp @@ -276,6 +276,30 @@ PyObject* DocumentPy::mdiViewsOfType(PyObject *args) PY_CATCH; } +PyObject* DocumentPy::save(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + PY_TRY { + bool ok = getDocumentPtr()->save(); + return Py::new_reference_to(Py::Boolean(ok)); + } + PY_CATCH; +} + +PyObject* DocumentPy::saveAs(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + PY_TRY { + bool ok = getDocumentPtr()->saveAs(); + return Py::new_reference_to(Py::Boolean(ok)); + } + PY_CATCH; +} + PyObject* DocumentPy::sendMsgToViews(PyObject *args) { char* msg;