Fix missing python addProperty and removeProperty of Document object

This commit is contained in:
Florian Foinant-Willig
2023-03-16 22:48:59 +01:00
committed by wwmayer
parent b1c848b8db
commit a290fe8ae1
2 changed files with 72 additions and 24 deletions

View File

@@ -40,6 +40,37 @@
using namespace App;
PyObject* DocumentPy::addProperty(PyObject *args)
{
char *sType,*sName=nullptr,*sGroup=nullptr,*sDoc=nullptr;
short attr=0;
std::string sDocStr;
PyObject *ro = Py_False, *hd = Py_False;
if (!PyArg_ParseTuple(args, "s|ssethO!O!", &sType,&sName,&sGroup,"utf-8",&sDoc,&attr,
&PyBool_Type, &ro, &PyBool_Type, &hd))
return nullptr;
if (sDoc) {
sDocStr = sDoc;
PyMem_Free(sDoc);
}
getDocumentPtr()->addDynamicProperty(sType,sName,sGroup,sDocStr.c_str(),attr,
Base::asBoolean(ro), Base::asBoolean(hd));
return Py::new_reference_to(this);
}
PyObject* DocumentPy::removeProperty(PyObject *args)
{
char *sName;
if (!PyArg_ParseTuple(args, "s", &sName))
return nullptr;
bool ok = getDocumentPtr()->removeDynamicProperty(sName);
return Py_BuildValue("O", (ok ? Py_True : Py_False));
}
// returns a string which represent the object e.g. when printed in python
std::string DocumentPy::representation() const
{
@@ -363,13 +394,13 @@ PyObject* DocumentPy::importLinks(PyObject *args)
objs.push_back(static_cast<DocumentObjectPy*>(seq[i].ptr())->getDocumentObjectPtr());
}
}
else {
Base::PyTypeCheck(&obj, &DocumentObjectPy::Type,
"Expect first argument to be either a document object, sequence of document objects or None");
if (obj)
objs.push_back(static_cast<DocumentObjectPy*>(obj)->getDocumentObjectPtr());
}
else {
Base::PyTypeCheck(&obj, &DocumentObjectPy::Type,
"Expect first argument to be either a document object, sequence of document objects or None");
if (obj)
objs.push_back(static_cast<DocumentObjectPy*>(obj)->getDocumentObjectPtr());
}
if (objs.empty())
objs = getDocumentPtr()->getObjects();
@@ -380,7 +411,7 @@ PyObject* DocumentPy::importLinks(PyObject *args)
for (size_t i=0;i<ret.size();++i)
tuple.setItem(i,Py::Object(ret[i]->getPyObject(),true));
return Py::new_reference_to(tuple);
}
}
PY_CATCH
}
@@ -857,20 +888,20 @@ PyObject* DocumentPy::getLinksTo(PyObject *args)
return nullptr;
PY_TRY {
Base::PyTypeCheck(&pyobj, &DocumentObjectPy::Type, "Expect the first argument of type document object");
Base::PyTypeCheck(&pyobj, &DocumentObjectPy::Type, "Expect the first argument of type document object");
DocumentObject *obj = nullptr;
if (pyobj)
obj = static_cast<DocumentObjectPy*>(pyobj)->getDocumentObjectPtr();
if (pyobj)
obj = static_cast<DocumentObjectPy*>(pyobj)->getDocumentObjectPtr();
std::set<DocumentObject *> links;
getDocumentPtr()->getLinksTo(links,obj,options,count);
Py::Tuple ret(links.size());
int i=0;
for (auto o : links)
ret.setItem(i++,Py::Object(o->getPyObject(),true));
return Py::new_reference_to(ret);
}
}
PY_CATCH
}