Core: Add a Python interface for property rename
This commit is contained in:
committed by
Yorik van Havre
parent
e7f8f2f48c
commit
18d87df6f1
@@ -211,3 +211,17 @@ class PropertyContainer(Persistence):
|
||||
Object with buffer protocol support.
|
||||
"""
|
||||
...
|
||||
|
||||
@constmethod
|
||||
def renameProperty(self, oldName: str, newName: str) -> None:
|
||||
"""
|
||||
renameProperty(oldName, newName) -> None
|
||||
|
||||
Rename a property.
|
||||
|
||||
oldName : str
|
||||
Old property name.
|
||||
newName : str
|
||||
New property name.
|
||||
"""
|
||||
...
|
||||
|
||||
@@ -704,3 +704,25 @@ int PropertyContainerPy::setCustomAttributes(const char* attr, PyObject* obj)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject* PropertyContainerPy::renameProperty(PyObject* args) const
|
||||
{
|
||||
char* oldName {};
|
||||
char* newName {};
|
||||
if (PyArg_ParseTuple(args, "ss", &oldName, &newName) == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Property* prop = getPropertyContainerPtr()->getDynamicPropertyByName(oldName);
|
||||
if (!prop) {
|
||||
PyErr_Format(PyExc_AttributeError, "Property container has no dynamic property '%s'", oldName);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY
|
||||
{
|
||||
prop->getContainer()->renameDynamicProperty(prop, newName);
|
||||
Py_Return;
|
||||
}
|
||||
PY_CATCH
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user