[Core] Use keyword arguments in DocumentObjectPy addProperty
This commit is contained in:
committed by
Yorik van Havre
parent
c95a99cd6f
commit
49dfaaefa0
@@ -76,14 +76,17 @@ Py::Object DocumentObjectPy::getDocument() const
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* DocumentObjectPy::addProperty(PyObject *args)
|
||||
PyObject* DocumentObjectPy::addProperty(PyObject *args, PyObject *kwd)
|
||||
{
|
||||
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))
|
||||
PyObject* enumVals = nullptr;
|
||||
const std::array<const char *, 9> kwlist {"type","name","group","doc","attr","read_only","hidden","enum_vals",nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(
|
||||
args, kwd, "ss|sethO!O!O", kwlist, &sType, &sName, &sGroup, "utf-8",
|
||||
&sDoc, &attr, &PyBool_Type, &ro, &PyBool_Type, &hd, &enumVals))
|
||||
return nullptr;
|
||||
|
||||
if (sDoc) {
|
||||
@@ -91,8 +94,21 @@ PyObject* DocumentObjectPy::addProperty(PyObject *args)
|
||||
PyMem_Free(sDoc);
|
||||
}
|
||||
|
||||
getDocumentObjectPtr()->addDynamicProperty(sType,sName,sGroup,sDocStr.c_str(),attr,
|
||||
Base::asBoolean(ro), Base::asBoolean(hd));
|
||||
Property *prop = getDocumentObjectPtr()->
|
||||
addDynamicProperty(sType,sName,sGroup,sDocStr.c_str(),attr,
|
||||
Base::asBoolean(ro), Base::asBoolean(hd));
|
||||
|
||||
// enum support
|
||||
auto* propEnum = dynamic_cast<App::PropertyEnumeration*>(prop);
|
||||
if (propEnum) {
|
||||
if (enumVals && PySequence_Check(enumVals)) {
|
||||
std::vector<std::string> enumValsAsVector;
|
||||
for (Py_ssize_t i = 0; i < PySequence_Length(enumVals); ++i) {
|
||||
enumValsAsVector.emplace_back(PyUnicode_AsUTF8(PySequence_GetItem(enumVals,i)));
|
||||
}
|
||||
propEnum->setEnums(enumValsAsVector);
|
||||
}
|
||||
}
|
||||
|
||||
return Py::new_reference_to(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user