mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Add executables list to plugin API (#151)
This commit is contained in:
@@ -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>
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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)});
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user