From 6317e20bec0e62d0630a7147c38df4f09ff38a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sun, 11 Aug 2024 13:22:52 +0200 Subject: [PATCH] Start adding bindings for extensions. --- src/mobase/mobase.cpp | 2 +- src/mobase/wrappers/basic_classes.cpp | 33 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/mobase/mobase.cpp b/src/mobase/mobase.cpp index 2a7de45..7387be9 100644 --- a/src/mobase/mobase.cpp +++ b/src/mobase/mobase.cpp @@ -29,7 +29,7 @@ PYBIND11_MODULE(mobase, m) // exceptions // - py::register_exception(m, "Exception"); + py::register_exception(m, "MO2Exception"); py::register_exception(m, "InvalidNXMLinkException"); py::register_exception(m, "IncompatibilityException"); py::register_exception(m, "InvalidVersionException"); diff --git a/src/mobase/wrappers/basic_classes.cpp b/src/mobase/wrappers/basic_classes.cpp index 54eb483..ee25b2b 100644 --- a/src/mobase/wrappers/basic_classes.cpp +++ b/src/mobase/wrappers/basic_classes.cpp @@ -360,6 +360,38 @@ namespace mo2::python { py::implicitly_convertible>(); } + void add_iextensionlist_classes(py::module_ m) + { + // TODO: add all bindings here + + py::class_(m, "Extension"); + + py::class_(m, "IExtensionList") + .def("installed", &IExtensionList::installed, "identifier"_a) + .def( + "enabled", + py::overload_cast(&IExtensionList::enabled, py::const_), + "identifier"_a) + .def( + "__getitem__", + [](IExtensionList const& self, + std::variant const& index) { + return std::visit( + [&self](auto&& value) { + if constexpr (std::is_same_v, + std::size_t>) { + return self.at(value); + } + else { + return self.get(value); + } + }, + index); + }, + py::return_value_policy::reference) + .def("__len__", &IExtensionList::size); + } + void add_ipluginlist_classes(py::module_ m) { py::enum_(m, "PluginState", py::arithmetic()) @@ -887,6 +919,7 @@ namespace mo2::python { }) .def("absoluteIniFilePath", &IProfile::absoluteIniFilePath, "inifile"_a); + add_iextensionlist_classes(m); add_ipluginlist_classes(m); add_imodlist_classes(m); add_idownload_manager_classes(m);