Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
App: expose more methods of Document class to Python
  • Loading branch information
wwmayer committed Dec 2, 2021
1 parent 96cbb3d commit 526dc1a
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 4 deletions.
50 changes: 49 additions & 1 deletion src/App/DocumentPy.xml
Expand Up @@ -38,6 +38,24 @@
<UserDocu>Restore the document from disk</UserDocu>
</Documentation>
</Methode>
<Methode Name="isSaved">
<Documentation>
<UserDocu>Checks if the document is saved</UserDocu>
</Documentation>
</Methode>
<Methode Name="getProgramVersion">
<Documentation>
<UserDocu>Get the program version that a project file was created with</UserDocu>
</Documentation>
</Methode>
<Methode Name="getFileName">
<Documentation>
<UserDocu>
For a regular document it returns its file name property.
For a temporary document it returns its transient directory.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="mergeProject">
<Documentation>
<UserDocu>Merges this document with another project file</UserDocu>
Expand Down Expand Up @@ -144,12 +162,42 @@ object of this document.
<UserDocu>Clear the undo stack of the document</UserDocu>
</Documentation>
</Methode>
<Methode Name="clearDocument">
<Documentation>
<UserDocu>Clear the whole document</UserDocu>
</Documentation>
</Methode>
<Methode Name="setClosable">
<Documentation>
<UserDocu>Set a flag that allows or forbids to close a document</UserDocu>
</Documentation>
</Methode>
<Methode Name="isClosable">
<Documentation>
<UserDocu>Check if the document can be closed. The default value is True</UserDocu>
</Documentation>
</Methode>
<Methode Name="recompute">
<Documentation>
<UserDocu>recompute(objs=None): Recompute the document and returns the amount of recomputed features</UserDocu>
</Documentation>
</Methode>
<Methode Name="getObject">
<Methode Name="mustExecute">
<Documentation>
<UserDocu>Check if any object must be recomputed</UserDocu>
</Documentation>
</Methode>
<Methode Name="purgeTouched">
<Documentation>
<UserDocu>Purge the touched state of all objects</UserDocu>
</Documentation>
</Methode>
<Methode Name="isTouched">
<Documentation>
<UserDocu>Check if any object is in touched state</UserDocu>
</Documentation>
</Methode>
<Methode Name="getObject">
<Documentation>
<UserDocu>Return the object with the given name</UserDocu>
</Documentation>
Expand Down
79 changes: 76 additions & 3 deletions src/App/DocumentPyImp.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 526dc1a

Please sign in to comment.