From 444a351d888ee440ea7d7ed03db293f08f1c78d5 Mon Sep 17 00:00:00 2001 From: Jared Duffey Date: Fri, 6 Dec 2024 09:38:58 -0500 Subject: [PATCH] Added __iter__() and keys() to BaseGroup python binding * Made it possible to iterate over all of a BaseGroup's children Signed-off-by: Jared Duffey --- src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp b/src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp index d977dc8c12..98e6455afc 100644 --- a/src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp +++ b/src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp @@ -869,6 +869,8 @@ PYBIND11_MODULE(simplnx, mod) baseGroup.def("contains", py::overload_cast(&BaseGroup::contains, py::const_)); baseGroup.def("__getitem__", py::overload_cast(&BaseGroup::at), py::return_value_policy::reference_internal); baseGroup.def("__len__", &BaseGroup::getSize); + baseGroup.def("__iter__", [](BaseGroup& self) { return py::make_iterator(self.begin(), self.end()); }); + baseGroup.def("keys", [](const BaseGroup& self) { return self.getDataMap().getNames(); }); auto baseGroupType = py::enum_(baseGroup, "GroupType"); baseGroupType.value("BaseGroup", BaseGroup::GroupType::BaseGroup);