+ Add method load() to Document class in Python

This commit is contained in:
wmayer 2013-11-22 17:53:31 +01:00
parent ef6978e9df
commit 3153ccd8b2
2 changed files with 30 additions and 0 deletions

View File

@ -23,6 +23,11 @@
<UserDocu>Save the document under a new name to disk</UserDocu>
</Documentation>
</Methode>
<Methode Name="load">
<Documentation>
<UserDocu>Load the document from the given path</UserDocu>
</Documentation>
</Methode>
<Methode Name="restore">
<Documentation>
<UserDocu>Restore the document from disk</UserDocu>

View File

@ -88,6 +88,31 @@ PyObject* DocumentPy::saveAs(PyObject * args)
Py_Return;
}
PyObject* DocumentPy::load(PyObject * args)
{
char* filename=0;
if (!PyArg_ParseTuple(args, "s", &filename))
return NULL;
if (!filename || *filename == '\0') {
PyErr_Format(PyExc_ValueError, "Path is empty");
return NULL;
}
getDocumentPtr()->FileName.setValue(filename);
Base::FileInfo fi(filename);
if (!fi.isReadable()) {
PyErr_Format(PyExc_IOError, "No such file or directory: '%s'", filename);
return NULL;
}
try {
getDocumentPtr()->restore();
} catch (...) {
PyErr_Format(PyExc_IOError, "Reading from file '%s' failed", filename);
return NULL;
}
Py_Return;
}
PyObject* DocumentPy::restore(PyObject * args)
{
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C