Add locked keyword to ViewProvider::addProperty
This commit is contained in:
committed by
Kacper Donat
parent
d6958ea1e6
commit
700c9a8a38
@@ -60,33 +60,56 @@ std::string ViewProviderPy::representation() const
|
||||
return "<View provider object>";
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::addProperty(PyObject *args)
|
||||
PyObject* ViewProviderPy::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))
|
||||
char *sType, *sName = nullptr, *sGroup = nullptr, *sDoc = nullptr;
|
||||
short attr = 0;
|
||||
PyObject *ro = Py_False, *hd = Py_False, *lk = Py_False;
|
||||
PyObject* enumVals = nullptr;
|
||||
const std::array<const char*, 10> kwlist {"type",
|
||||
"name",
|
||||
"group",
|
||||
"doc",
|
||||
"attr",
|
||||
"read_only",
|
||||
"hidden",
|
||||
"locked",
|
||||
"enum_vals",
|
||||
nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args,
|
||||
kwd,
|
||||
"ss|sethO!O!O!O",
|
||||
kwlist,
|
||||
&sType,
|
||||
&sName,
|
||||
&sGroup,
|
||||
"utf-8",
|
||||
&sDoc,
|
||||
&attr,
|
||||
&PyBool_Type,
|
||||
&ro,
|
||||
&PyBool_Type,
|
||||
&hd,
|
||||
&PyBool_Type,
|
||||
&lk,
|
||||
&enumVals)) {
|
||||
return nullptr;
|
||||
|
||||
if (sDoc) {
|
||||
sDocStr = sDoc;
|
||||
PyMem_Free(sDoc);
|
||||
}
|
||||
|
||||
App::Property* prop=nullptr;
|
||||
try {
|
||||
prop = getViewProviderPtr()->addDynamicProperty(sType,sName,sGroup,sDocStr.c_str(),attr,
|
||||
Base::asBoolean(ro), Base::asBoolean(hd));
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
throw Py::RuntimeError(e.what());
|
||||
}
|
||||
if (!prop) {
|
||||
std::stringstream str;
|
||||
str << "No property found of type '" << sType << "'" << std::ends;
|
||||
throw Py::TypeError(str.str());
|
||||
App::Property* prop = getViewProviderPtr()->addDynamicProperty(sType,
|
||||
sName,
|
||||
sGroup,
|
||||
sDoc,
|
||||
attr,
|
||||
Base::asBoolean(ro),
|
||||
Base::asBoolean(hd));
|
||||
|
||||
prop->setStatus(App::Property::LockDynamic, Base::asBoolean(lk));
|
||||
|
||||
// enum support
|
||||
auto* propEnum = freecad_cast<App::PropertyEnumeration*>(prop);
|
||||
if (propEnum && enumVals) {
|
||||
propEnum->setPyObject(enumVals);
|
||||
}
|
||||
|
||||
return Py::new_reference_to(this);
|
||||
|
||||
Reference in New Issue
Block a user