mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
allow for game plugins to be written in python
This commit is contained in:
@@ -13,6 +13,57 @@ using namespace MOBase;
|
||||
catch (...) { throw MyException("An unknown exception was thrown in python code"); }
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
/// IPlugin Wrapper
|
||||
bool IPluginWrapper::init(MOBase::IOrganizer *moInfo)
|
||||
{
|
||||
try {
|
||||
return this->get_override("init")(bpy::ptr(moInfo));
|
||||
} PYCATCH;
|
||||
}
|
||||
|
||||
QString IPluginWrapper::name() const
|
||||
{
|
||||
try {
|
||||
return this->get_override("name")().as<QString>();
|
||||
} PYCATCH;
|
||||
}
|
||||
|
||||
QString IPluginWrapper::author() const
|
||||
{
|
||||
try {
|
||||
return this->get_override("author")().as<QString>();
|
||||
} PYCATCH;
|
||||
}
|
||||
|
||||
QString IPluginWrapper::description() const
|
||||
{
|
||||
try {
|
||||
return this->get_override("description")().as<QString>();
|
||||
} PYCATCH;
|
||||
}
|
||||
|
||||
MOBase::VersionInfo IPluginWrapper::version() const
|
||||
{
|
||||
try {
|
||||
return this->get_override("version")().as<MOBase::VersionInfo>();
|
||||
} PYCATCH;
|
||||
}
|
||||
|
||||
bool IPluginWrapper::isActive() const
|
||||
{
|
||||
try {
|
||||
return this->get_override("isActive")().as<bool>();
|
||||
} PYCATCH;
|
||||
}
|
||||
|
||||
QList<MOBase::PluginSetting> IPluginWrapper::settings() const
|
||||
{
|
||||
try {
|
||||
return this->get_override("settings")().as<QList<MOBase::PluginSetting>>();
|
||||
} PYCATCH;
|
||||
}
|
||||
/// end IPlugin Wrapper
|
||||
/////////////////////////////
|
||||
/// IPluginTool Wrapper
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@
|
||||
#endif
|
||||
|
||||
|
||||
class IPluginWrapper : public boost::python::wrapper<MOBase::IPlugin>
|
||||
class IPluginWrapper : public MOBase::IPlugin, public boost::python::wrapper<MOBase::IPlugin>
|
||||
{
|
||||
Q_INTERFACES(MOBase::IPlugin)
|
||||
|
||||
public:
|
||||
virtual bool init(MOBase::IOrganizer *moInfo);
|
||||
virtual QString name() const;
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
|
||||
#include "iplugingame.h"
|
||||
#include <iplugininstaller.h>
|
||||
#include <iplugintool.h>
|
||||
#include <iplugingame.h>
|
||||
#include <iplugin.h>
|
||||
#include "uibasewrappers.h"
|
||||
#include "pythonpluginwrapper.h"
|
||||
#include "proxypluginwrappers.h"
|
||||
@@ -757,8 +760,7 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
|
||||
bpy::class_<IDownloadManagerWrapper, boost::noncopyable>("IDownloadManager")
|
||||
.def("startDownloadURLs", bpy::pure_virtual(&IDownloadManager::startDownloadURLs))
|
||||
//not used?
|
||||
//.def("startDownloadNexusFile", bpy::pure_virtual(&IDownloadManager::startDownloadNexusFile))
|
||||
.def("startDownloadNexusFile", bpy::pure_virtual(&IDownloadManager::startDownloadNexusFile))
|
||||
.def("downloadPath", bpy::pure_virtual(&IDownloadManager::downloadPath))
|
||||
;
|
||||
|
||||
@@ -800,9 +802,12 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.def("variants", &MOBase::GuessedValue<QString>::variants, bpy::return_value_policy<bpy::copy_const_reference>())
|
||||
;
|
||||
|
||||
bpy::class_<IPluginToolWrapper, boost::noncopyable>("IPluginTool")
|
||||
bpy::class_<IPluginWrapper, boost::noncopyable>("IPlugin");
|
||||
|
||||
bpy::class_<IPluginToolWrapper, bpy::bases<IPlugin>, boost::noncopyable>("IPluginTool")
|
||||
.def("setParentWidget", bpy::pure_virtual(&MOBase::IPluginTool::setParentWidget))
|
||||
;
|
||||
|
||||
bpy::class_<IPluginInstallerCustomWrapper, boost::noncopyable>("IPluginInstallerCustom")
|
||||
.def("setParentWidget", bpy::pure_virtual(&MOBase::IPluginInstallerCustom::setParentWidget))
|
||||
;
|
||||
@@ -846,7 +851,6 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.value("preferDefaults", MOBase::IPluginGame::PREFER_DEFAULTS)
|
||||
;
|
||||
|
||||
|
||||
bpy::class_<IPluginGameWrapper, boost::noncopyable>("IPluginGame")
|
||||
.def("gameName", bpy::pure_virtual(&MOBase::IPluginGame::gameName))
|
||||
.def("initializeProfile", bpy::pure_virtual(&MOBase::IPluginGame::initializeProfile))
|
||||
@@ -1008,6 +1012,7 @@ QObject *PythonRunner::instantiate(const QString &pluginName)
|
||||
bpy::object pluginObj = m_PythonObjects[pluginName];
|
||||
TRY_PLUGIN_TYPE(IPluginInstallerCustom, pluginObj);
|
||||
TRY_PLUGIN_TYPE(IPluginTool, pluginObj);
|
||||
TRY_PLUGIN_TYPE(IPluginGame, pluginObj);
|
||||
} catch (const bpy::error_already_set&) {
|
||||
qWarning("failed to run python script \"%s\"", qPrintable(pluginName));
|
||||
reportPythonError();
|
||||
|
||||
@@ -241,9 +241,8 @@ struct IProfileWrapper: MOBase::IProfile, boost::python::wrapper<MOBase::IProfil
|
||||
|
||||
struct IDownloadManagerWrapper: MOBase::IDownloadManager, boost::python::wrapper<MOBase::IDownloadManager>
|
||||
{
|
||||
virtual int startDownloadURLs(const QStringList &urls) { return this->get_override("downloadURLs")(urls); }
|
||||
//not used
|
||||
//virtual int startDownloadNexusFile(int modID, int fileID) { return this->get_override("downloadNexusFile")(modID, fileID); }
|
||||
virtual int startDownloadURLs(const QStringList &urls) { return this->get_override("startDownloadURLs")(urls); }
|
||||
virtual int startDownloadNexusFile(int modID, int fileID) { return this->get_override("startDownloadNexusFile")(modID, fileID); }
|
||||
virtual QString downloadPath(int id) { return this->get_override("downloadPath")(id); }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user