From 3797e35dbc3bf71519e389a14e6b362e9c03b8ba Mon Sep 17 00:00:00 2001 From: Pieter Hijma Date: Sun, 18 May 2025 15:09:55 +0200 Subject: [PATCH] Core: Add a Python interface for property rename --- src/App/PropertyContainer.pyi | 14 ++++++++++++++ src/App/PropertyContainerPyImp.cpp | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/App/PropertyContainer.pyi b/src/App/PropertyContainer.pyi index ce59ce118b..8226fc7e55 100644 --- a/src/App/PropertyContainer.pyi +++ b/src/App/PropertyContainer.pyi @@ -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. + """ + ... diff --git a/src/App/PropertyContainerPyImp.cpp b/src/App/PropertyContainerPyImp.cpp index 3d8aaed402..cde8b6abf0 100644 --- a/src/App/PropertyContainerPyImp.cpp +++ b/src/App/PropertyContainerPyImp.cpp @@ -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 +}