From 5824a64b6187dab327ae8b9ba51cbe8cd7e1ef23 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 2 Dec 2021 11:46:13 +0100 Subject: [PATCH] App: expose more methods of Document class to Python --- src/App/DocumentPy.xml | 50 ++++++++++++++++++++++++- src/App/DocumentPyImp.cpp | 79 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 125 insertions(+), 4 deletions(-) diff --git a/src/App/DocumentPy.xml b/src/App/DocumentPy.xml index c3dbdf7157..97a419a4ba 100644 --- a/src/App/DocumentPy.xml +++ b/src/App/DocumentPy.xml @@ -38,6 +38,24 @@ Restore the document from disk + + + Checks if the document is saved + + + + + Get the program version that a project file was created with + + + + + +For a regular document it returns its file name property. +For a temporary document it returns its transient directory. + + + Merges this document with another project file @@ -144,12 +162,42 @@ object of this document. Clear the undo stack of the document + + + Clear the whole document + + + + + Set a flag that allows or forbids to close a document + + + + + Check if the document can be closed. The default value is True + + recompute(objs=None): Recompute the document and returns the amount of recomputed features - + + + Check if any object must be recomputed + + + + + Purge the touched state of all objects + + + + + Check if any object is in touched state + + + Return the object with the given name diff --git a/src/App/DocumentPyImp.cpp b/src/App/DocumentPyImp.cpp index 18d1e1830a..0896d182b1 100644 --- a/src/App/DocumentPyImp.cpp +++ b/src/App/DocumentPyImp.cpp @@ -148,6 +148,30 @@ PyObject* DocumentPy::restore(PyObject * args) Py_Return; } +PyObject* DocumentPy::isSaved(PyObject* args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + bool ok = getDocumentPtr()->isSaved(); + return Py::new_reference_to(Py::Boolean(ok)); +} + +PyObject* DocumentPy::getProgramVersion(PyObject* args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + const char* version = getDocumentPtr()->getProgramVersion(); + return Py::new_reference_to(Py::String(version)); +} + +PyObject* DocumentPy::getFileName(PyObject* args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + const char* fn = getDocumentPtr()->getFileName(); + return Py::new_reference_to(Py::String(fn)); +} + PyObject* DocumentPy::mergeProject(PyObject * args) { char* filename; @@ -446,14 +470,39 @@ PyObject* DocumentPy::redo(PyObject * args) Py_Return; } -PyObject* DocumentPy::clearUndos(PyObject * args) +PyObject* DocumentPy::clearUndos(PyObject * args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; getDocumentPtr()->clearUndos(); Py_Return; } +PyObject* DocumentPy::clearDocument(PyObject * args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + getDocumentPtr()->clearDocument(); + Py_Return; +} + +PyObject* DocumentPy::setClosable(PyObject* args) +{ + PyObject* close; + if (!PyArg_ParseTuple(args, "O!", &PyBool_Type, &close)) + return nullptr; + getDocumentPtr()->setClosable(PyObject_IsTrue(close) ? true : false); + Py_Return; +} + +PyObject* DocumentPy::isClosable(PyObject* args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + bool ok = getDocumentPtr()->isClosable(); + return Py::new_reference_to(Py::Boolean(ok)); +} + PyObject* DocumentPy::recompute(PyObject * args) { PyObject *pyobjs = Py_None; @@ -497,6 +546,30 @@ PyObject* DocumentPy::recompute(PyObject * args) } PY_CATCH; } +PyObject* DocumentPy::mustExecute(PyObject* args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + bool ok = getDocumentPtr()->mustExecute(); + return Py::new_reference_to(Py::Boolean(ok)); +} + +PyObject* DocumentPy::isTouched(PyObject* args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + bool ok = getDocumentPtr()->isTouched(); + return Py::new_reference_to(Py::Boolean(ok)); +} + +PyObject* DocumentPy::purgeTouched(PyObject* args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + getDocumentPtr()->purgeTouched(); + Py_Return; +} + PyObject* DocumentPy::getObject(PyObject *args) { long id = -1;