Skip to content

Commit 6317e20

Browse files
committed
Start adding bindings for extensions.
1 parent 4c6ed4a commit 6317e20

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/mobase/mobase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ PYBIND11_MODULE(mobase, m)
2929

3030
// exceptions
3131
//
32-
py::register_exception<Exception>(m, "Exception");
32+
py::register_exception<Exception>(m, "MO2Exception");
3333
py::register_exception<InvalidNXMLinkException>(m, "InvalidNXMLinkException");
3434
py::register_exception<IncompatibilityException>(m, "IncompatibilityException");
3535
py::register_exception<InvalidVersionException>(m, "InvalidVersionException");

src/mobase/wrappers/basic_classes.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,38 @@ namespace mo2::python {
360360
py::implicitly_convertible<QString, GuessedValue<QString>>();
361361
}
362362

363+
void add_iextensionlist_classes(py::module_ m)
364+
{
365+
// TODO: add all bindings here
366+
367+
py::class_<IExtension>(m, "Extension");
368+
369+
py::class_<IExtensionList>(m, "IExtensionList")
370+
.def("installed", &IExtensionList::installed, "identifier"_a)
371+
.def(
372+
"enabled",
373+
py::overload_cast<const QString&>(&IExtensionList::enabled, py::const_),
374+
"identifier"_a)
375+
.def(
376+
"__getitem__",
377+
[](IExtensionList const& self,
378+
std::variant<std::size_t, QString> const& index) {
379+
return std::visit(
380+
[&self](auto&& value) {
381+
if constexpr (std::is_same_v<std::decay_t<decltype(value)>,
382+
std::size_t>) {
383+
return self.at(value);
384+
}
385+
else {
386+
return self.get(value);
387+
}
388+
},
389+
index);
390+
},
391+
py::return_value_policy::reference)
392+
.def("__len__", &IExtensionList::size);
393+
}
394+
363395
void add_ipluginlist_classes(py::module_ m)
364396
{
365397
py::enum_<IPluginList::PluginState>(m, "PluginState", py::arithmetic())
@@ -887,6 +919,7 @@ namespace mo2::python {
887919
})
888920
.def("absoluteIniFilePath", &IProfile::absoluteIniFilePath, "inifile"_a);
889921

922+
add_iextensionlist_classes(m);
890923
add_ipluginlist_classes(m);
891924
add_imodlist_classes(m);
892925
add_idownload_manager_classes(m);

0 commit comments

Comments
 (0)