Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/mobase/wrappers/basic_classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
#include <format>
#include <memory>

#include <pybind11_utils/generator.h>
#include <uibase/executableinfo.h>
#include <uibase/filemapping.h>
#include <uibase/game_features/igamefeatures.h>
#include <uibase/guessedvalue.h>
#include <uibase/idownloadmanager.h>
#include <uibase/iexecutable.h>
#include <uibase/iexecutableslist.h>
#include <uibase/iinstallationmanager.h>
#include <uibase/imodinterface.h>
#include <uibase/imodrepositorybridge.h>
Expand Down Expand Up @@ -198,6 +201,27 @@ namespace mo2::python {
.def("forced", &ExecutableForcedLoadSetting::forced)
.def("library", &ExecutableForcedLoadSetting::library)
.def("process", &ExecutableForcedLoadSetting::process);

py::class_<IExecutable>(m, "IExecutable")
.def("title", &IExecutable::title)
.def("binaryInfo", &IExecutable::binaryInfo)
.def("arguments", &IExecutable::arguments)
.def("steamAppID", &IExecutable::steamAppID)
.def("workingDirectory", &IExecutable::workingDirectory)
.def("isShownOnToolbar", &IExecutable::isShownOnToolbar)
.def("usesOwnIcon", &IExecutable::usesOwnIcon)
.def("minimizeToSystemTray", &IExecutable::minimizeToSystemTray)
.def("hide", &IExecutable::hide);

py::class_<IExecutablesList>(m, "IExecutablesList")
.def("executables",
[](IExecutablesList* executablesList) {
return make_generator(executablesList->executables(),
py::return_value_policy::reference);
})
.def("getByTitle", &IExecutablesList::getByTitle, "title"_a)
.def("getByBinary", &IExecutablesList::getByBinary, "info"_a)
.def("titleExists", &IExecutablesList::contains, "title"_a);
}

void add_modinterface_classes(py::module_ m)
Expand Down Expand Up @@ -625,6 +649,8 @@ namespace mo2::python {
.def("pluginList", &IOrganizer::pluginList,
py::return_value_policy::reference)
.def("modList", &IOrganizer::modList, py::return_value_policy::reference)
.def("executablesList", &IOrganizer::executablesList,
py::return_value_policy::reference)
.def("gameFeatures", &IOrganizer::gameFeatures,
py::return_value_policy::reference)
.def("profile", &IOrganizer::profile)
Expand Down
27 changes: 15 additions & 12 deletions src/pybind11-utils/include/pybind11_utils/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace mo2::python {

// create a Python generator from a C++ generator
//
template <typename T>
auto make_generator(std::generator<T> g)
template <typename T, typename... Args>
auto make_generator(std::generator<T> g, Args&&... args)
{
using state = detail::generator_state<T>;

Expand All @@ -34,16 +34,19 @@ namespace mo2::python {
[](state& s) -> state& {
return s;
})
.def("__next__", [](state& s) {
if (s.it != s.g.end()) {
const auto v = *s.it;
s.it++;
return v;
}
else {
throw py::stop_iteration();
}
});
.def(
"__next__",
[](state& s) -> T {
if (s.it != s.g.end()) {
T v = *s.it;
s.it++;
return v;
}
else {
throw py::stop_iteration();
}
},
std::forward<Args>(args)...);
}

return py::cast(state{std::move(g)});
Expand Down
1 change: 1 addition & 0 deletions tests/mocks/MockOrganizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MockOrganizer : public IOrganizer {
MOCK_METHOD(MOBase::IDownloadManager*, downloadManager, (), (const, override));
MOCK_METHOD(MOBase::IPluginList*, pluginList, (), (const, override));
MOCK_METHOD(MOBase::IModList*, modList, (), (const, override));
MOCK_METHOD(MOBase::IExecutablesList*, executablesList, (), (const, override));
MOCK_METHOD(std::shared_ptr<MOBase::IProfile>, profile, (), (const, override));
MOCK_METHOD(QStringList, profileNames, (), (const, override));
MOCK_METHOD(std::shared_ptr<const MOBase::IProfile>, getProfile, (const QString& name), (const, override));
Expand Down