PropertyContainerPy: modified getPropertyByName()

Add 'checkOwner' argument to allow caller distinguish linked property
This commit is contained in:
Zheng, Lei
2019-07-19 11:49:49 +08:00
committed by wmayer
parent aaf0f2c80d
commit 673d035bb3
2 changed files with 21 additions and 7 deletions

View File

@@ -54,16 +54,19 @@ std::string PropertyContainerPy::representation(void) const
PyObject* PropertyContainerPy::getPropertyByName(PyObject *args)
{
char *pstr;
if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C
int checkOwner=0;
if (!PyArg_ParseTuple(args, "s|i", &pstr, &checkOwner)) // convert args: Python->C
return NULL; // NULL triggers exception
App::Property* prop = getPropertyContainerPtr()->getPropertyByName(pstr);
if (prop) {
return prop->getPyObject();
}
else {
PyErr_Format(PyExc_AttributeError, "Property container has no property '%s'", pstr);
return NULL;
if(!checkOwner || (checkOwner==1 && prop->getContainer()==getPropertyContainerPtr()))
return prop->getPyObject();
Py::TupleN res(Py::asObject(prop->getContainer()->getPyObject()),
Py::asObject(prop->getPyObject()));
return Py::new_reference_to(res);
}
PyErr_Format(PyExc_AttributeError, "Property container has no property '%s'", pstr);
return NULL;
}
PyObject* PropertyContainerPy::getPropertyTouchList(PyObject *args)