mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9cbf374166 | ||
|
|
f71bfff0e6 | ||
|
|
8aa2ab4eac | ||
|
|
46a0ce9e38 | ||
|
|
15e635741c |
@@ -178,7 +178,7 @@ QString ProxyPython::description() const
|
||||
|
||||
VersionInfo ProxyPython::version() const
|
||||
{
|
||||
return VersionInfo(1, 3, 0, VersionInfo::RELEASE_FINAL);
|
||||
return VersionInfo(1, 3, 1, VersionInfo::RELEASE_FINAL);
|
||||
}
|
||||
|
||||
bool ProxyPython::isActive() const
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#define HAVE_ROUND
|
||||
#include "proxypluginwrappers.h"
|
||||
#include <utility.h>
|
||||
#include "error.h"
|
||||
|
||||
+72
-25
@@ -1,3 +1,5 @@
|
||||
#define HAVE_ROUND
|
||||
|
||||
#include "pythonrunner.h"
|
||||
|
||||
#pragma warning( disable : 4100 )
|
||||
@@ -177,6 +179,7 @@ struct QVariant_to_python_obj
|
||||
static PyObject *convert(const QVariant &var) {
|
||||
switch (var.type()) {
|
||||
case QVariant::Int: return PyLong_FromLong(var.toInt());
|
||||
case QVariant::UInt: return PyLong_FromUnsignedLong(var.toUInt());
|
||||
case QVariant::Bool: return PyBool_FromLong(var.toBool());
|
||||
case QVariant::String: return bpy::incref(bpy::object(var.toString().toUtf8().constData()).ptr());
|
||||
case QVariant::List: {
|
||||
@@ -187,8 +190,18 @@ struct QVariant_to_python_obj
|
||||
}
|
||||
return result;
|
||||
} break;
|
||||
case QVariant::Map: {
|
||||
QVariantMap map = var.toMap();
|
||||
PyObject *result = PyDict_New();
|
||||
QMapIterator<QString, QVariant> iter(map);
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
PyDict_SetItem(result, convert(iter.key()), convert(iter.value()));
|
||||
}
|
||||
return result;
|
||||
} break;
|
||||
default: {
|
||||
PyErr_SetString(PyExc_TypeError, "type unsupported");
|
||||
PyErr_Format(PyExc_TypeError, "type unsupported: %d", var.type());
|
||||
throw bpy::error_already_set();
|
||||
} break;
|
||||
}
|
||||
@@ -356,9 +369,21 @@ static const sipAPIDef *sipAPI()
|
||||
}
|
||||
|
||||
|
||||
struct IModRepositoryBridge_to_python
|
||||
{
|
||||
static PyObject *convert(IModRepositoryBridge *bridge)
|
||||
{
|
||||
ModRepositoryBridgeWrapper wrapper(bridge);
|
||||
|
||||
return bpy::incref(bpy::object(wrapper).ptr());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename T> struct MetaData;
|
||||
|
||||
template <> struct MetaData<IModRepositoryBridge> { static const char *className() { return "MOBase::INexusBridge"; } };
|
||||
template <> struct MetaData<IModRepositoryBridge> { static const char *className() { return "QObject"; } };
|
||||
template <> struct MetaData<IDownloadManager> { static const char *className() { return "QObject"; } };
|
||||
template <> struct MetaData<QObject> { static const char *className() { return "QObject"; } };
|
||||
template <> struct MetaData<QWidget> { static const char *className() { return "QWidget"; } };
|
||||
@@ -373,7 +398,6 @@ PyObject *toPyQt(T *objPtr)
|
||||
qDebug("no input object");
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
|
||||
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
||||
|
||||
if (type == NULL) {
|
||||
@@ -624,13 +648,12 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
bpy::to_python_converter<QString, QString_to_python_str>();
|
||||
QString_from_python_str();
|
||||
|
||||
QClass_converters<QObject>();
|
||||
//QClass_converters<QObject>();
|
||||
QClass_converters<QWidget>();
|
||||
//QClass_converters<QVariant>();
|
||||
QClass_converters<QIcon>();
|
||||
QInterface_converters<IModRepositoryBridge>();
|
||||
QInterface_converters<IDownloadManager>();
|
||||
|
||||
|
||||
bpy::def("toPyQt", &toPyQt<IModRepositoryBridge>);
|
||||
bpy::def("toPyQt", &toPyQt<IDownloadManager>);
|
||||
|
||||
@@ -642,6 +665,14 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.value("prealpha", MOBase::VersionInfo::RELEASE_PREALPHA)
|
||||
;
|
||||
|
||||
bpy::enum_<MOBase::VersionInfo::VersionScheme>("VersionScheme")
|
||||
.value("discover", MOBase::VersionInfo::SCHEME_DISCOVER)
|
||||
.value("regular", MOBase::VersionInfo::SCHEME_REGULAR)
|
||||
.value("decimalmark", MOBase::VersionInfo::SCHEME_DECIMALMARK)
|
||||
.value("numbersandletters", MOBase::VersionInfo::SCHEME_NUMBERSANDLETTERS)
|
||||
.value("date", MOBase::VersionInfo::SCHEME_DATE)
|
||||
;
|
||||
|
||||
bpy::enum_<MOBase::IPluginInstaller::EInstallResult>("InstallResult")
|
||||
.value("success", MOBase::IPluginInstaller::RESULT_SUCCESS)
|
||||
.value("failed", MOBase::IPluginInstaller::RESULT_FAILED)
|
||||
@@ -657,31 +688,34 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.value("skyrim", MOBase::IGameInfo::TYPE_SKYRIM)
|
||||
;
|
||||
|
||||
bpy::class_<MOBase::VersionInfo>("VersionInfo")
|
||||
.def(bpy::init<int, int, int, MOBase::VersionInfo::ReleaseType>())
|
||||
.def("parse", &MOBase::VersionInfo::parse)
|
||||
.def("canonicalString", &MOBase::VersionInfo::canonicalString)
|
||||
bpy::class_<VersionInfo>("VersionInfo")
|
||||
.def(bpy::init<QString>())
|
||||
.def(bpy::init<QString, VersionInfo::VersionScheme>())
|
||||
.def(bpy::init<int, int, int>())
|
||||
.def(bpy::init<int, int, int, VersionInfo::ReleaseType>())
|
||||
.def("parse", &VersionInfo::parse)
|
||||
.def("canonicalString", &VersionInfo::canonicalString)
|
||||
;
|
||||
|
||||
bpy::class_<MOBase::PluginSetting>("PluginSetting", bpy::init<const QString&, const QString&, const QVariant&>());
|
||||
bpy::class_<PluginSetting>("PluginSetting", bpy::init<const QString&, const QString&, const QVariant&>());
|
||||
|
||||
bpy::class_<IGameInfoWrapper, boost::noncopyable>("GameInfo")
|
||||
.def("type", bpy::pure_virtual(&MOBase::IGameInfo::type))
|
||||
.def("path", bpy::pure_virtual(&MOBase::IGameInfo::path))
|
||||
.def("binaryName", bpy::pure_virtual(&MOBase::IGameInfo::binaryName))
|
||||
.def("type", bpy::pure_virtual(&IGameInfo::type))
|
||||
.def("path", bpy::pure_virtual(&IGameInfo::path))
|
||||
.def("binaryName", bpy::pure_virtual(&IGameInfo::binaryName))
|
||||
;
|
||||
|
||||
bpy::class_<IOrganizerWrapper, boost::noncopyable>("IOrganizer")
|
||||
.def("gameInfo", bpy::pure_virtual(&MOBase::IOrganizer::gameInfo), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
//.def("createNexusBridge", bpy::pure_virtual(&MOBase::IOrganizer::createNexusBridge), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("profileName", bpy::pure_virtual(&MOBase::IOrganizer::profileName))
|
||||
.def("profilePath", bpy::pure_virtual(&MOBase::IOrganizer::profilePath))
|
||||
.def("downloadsPath", bpy::pure_virtual(&MOBase::IOrganizer::downloadsPath))
|
||||
.def("appVersion", bpy::pure_virtual(&MOBase::IOrganizer::appVersion))
|
||||
.def("getMod", bpy::pure_virtual(&MOBase::IOrganizer::getMod), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("createMod", bpy::pure_virtual(&MOBase::IOrganizer::createMod), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("removeMod", bpy::pure_virtual(&MOBase::IOrganizer::removeMod))
|
||||
.def("modDataChanged", bpy::pure_virtual(&MOBase::IOrganizer::modDataChanged))
|
||||
.def("gameInfo", bpy::pure_virtual(&IOrganizer::gameInfo), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("createNexusBridge", bpy::pure_virtual(&IOrganizer::createNexusBridge), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("profileName", bpy::pure_virtual(&IOrganizer::profileName))
|
||||
.def("profilePath", bpy::pure_virtual(&IOrganizer::profilePath))
|
||||
.def("downloadsPath", bpy::pure_virtual(&IOrganizer::downloadsPath))
|
||||
.def("appVersion", bpy::pure_virtual(&IOrganizer::appVersion))
|
||||
.def("getMod", bpy::pure_virtual(&IOrganizer::getMod), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("createMod", bpy::pure_virtual(&IOrganizer::createMod), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("removeMod", bpy::pure_virtual(&IOrganizer::removeMod))
|
||||
.def("modDataChanged", bpy::pure_virtual(&IOrganizer::modDataChanged))
|
||||
.def("pluginSetting", bpy::pure_virtual(&IOrganizer::pluginSetting))
|
||||
.def("setPluginSetting", bpy::pure_virtual(&IOrganizer::pluginSetting))
|
||||
.def("persistent", bpy::pure_virtual(&IOrganizer::persistent))
|
||||
@@ -693,19 +727,31 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.def("modList", bpy::pure_virtual(&IOrganizer::modList), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("startApplication", bpy::pure_virtual(&IOrganizer::startApplication), bpy::return_value_policy<bpy::return_by_value>())
|
||||
.def("onAboutToRun", bpy::pure_virtual(&IOrganizer::onAboutToRun))
|
||||
.def("onModInstalled", bpy::pure_virtual(&IOrganizer::onModInstalled))
|
||||
.def("refreshModList", bpy::pure_virtual(&IOrganizer::refreshModList))
|
||||
;
|
||||
|
||||
bpy::class_<ModRepositoryBridgeWrapper, boost::noncopyable>("ModRepositoryBridge")
|
||||
.def(bpy::init<IModRepositoryBridge*>())
|
||||
.def("requestDescription", &ModRepositoryBridgeWrapper::requestDescription)
|
||||
.def("requestFiles", &ModRepositoryBridgeWrapper::requestFiles)
|
||||
.def("requestFileInfo", &ModRepositoryBridgeWrapper::requestFileInfo)
|
||||
.def("requestDownloadURL", &ModRepositoryBridgeWrapper::requestDownloadURL)
|
||||
.def("requestToggleEndorsement", &ModRepositoryBridgeWrapper::requestToggleEndorsement)
|
||||
.def("onFilesAvailable", &ModRepositoryBridgeWrapper::onFilesAvailable)
|
||||
.def("onFileInfoAvailable", &ModRepositoryBridgeWrapper::onFileInfoAvailable)
|
||||
.def("onDescriptionAvailable", &ModRepositoryBridgeWrapper::onDescriptionAvailable)
|
||||
.def("onEndorsementToggled", &ModRepositoryBridgeWrapper::onEndorsementToggled)
|
||||
.def("onRequestFailed", &ModRepositoryBridgeWrapper::onRequestFailed)
|
||||
;
|
||||
|
||||
bpy::class_<IModRepositoryBridgeWrapper, boost::noncopyable>("IModRepositoryBridge")
|
||||
.def("requestDescription", bpy::pure_virtual(&IModRepositoryBridge::requestDescription))
|
||||
.def("requestFiles", bpy::pure_virtual(&IModRepositoryBridge::requestFiles))
|
||||
.def("requestFileInfo", bpy::pure_virtual(&IModRepositoryBridge::requestFileInfo))
|
||||
.def("requestDownloadURL", bpy::pure_virtual(&IModRepositoryBridge::requestDownloadURL))
|
||||
.def("requestToggleEndorsement", bpy::pure_virtual(&IModRepositoryBridge::requestToggleEndorsement))
|
||||
;
|
||||
|
||||
bpy::class_<IDownloadManagerWrapper, boost::noncopyable>("IDownloadManager")
|
||||
.def("startDownloadURLs", bpy::pure_virtual(&IDownloadManager::startDownloadURLs))
|
||||
.def("startDownloadNexusFile", bpy::pure_virtual(&IDownloadManager::startDownloadNexusFile))
|
||||
@@ -770,6 +816,7 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.def("priority", bpy::pure_virtual(&MOBase::IModList::priority))
|
||||
.def("setPriority", bpy::pure_virtual(&MOBase::IModList::setPriority))
|
||||
.def("onModStateChanged", bpy::pure_virtual(&MOBase::IModList::onModStateChanged))
|
||||
.def("onModMoved", bpy::pure_virtual(&MOBase::IModList::onModMoved))
|
||||
;
|
||||
|
||||
GuessedValue_converters<QString>();
|
||||
|
||||
+96
-11
@@ -55,8 +55,6 @@ public:
|
||||
{ m_Wrapped->requestFiles(modID, userData); }
|
||||
void requestFileInfo(int modID, int fileID, QVariant userData)
|
||||
{ m_Wrapped->requestFileInfo(modID, fileID, userData); }
|
||||
void requestDownloadURL(int modID, int fileID, QVariant userData)
|
||||
{ m_Wrapped->requestDownloadURL(modID, fileID, userData); }
|
||||
void requestToggleEndorsement(int modID, bool endorse, QVariant userData)
|
||||
{ m_Wrapped->requestToggleEndorsement(modID, endorse, userData); }
|
||||
|
||||
@@ -67,6 +65,27 @@ public:
|
||||
Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
void onDescriptionAvailable(boost::python::object callback) {
|
||||
m_DescriptionAvailableHandler = callback;
|
||||
connect(m_Wrapped, SIGNAL(descriptionAvailable(int,QVariant,QVariant)),
|
||||
this, SLOT(descriptionAvailable(int,QVariant,QVariant)),
|
||||
Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
void onFileInfoAvailable(boost::python::object callback) {
|
||||
m_FileInfoHandler = callback;
|
||||
connect(m_Wrapped, SIGNAL(fileInfoAvailable(int,int,QVariant,QVariant)),
|
||||
this, SLOT(fileInfoAvailable(int,int,QVariant,QVariant)),
|
||||
Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
void onEndorsementToggled(boost::python::object callback) {
|
||||
m_EndorsementToggledHandler = callback;
|
||||
connect(m_Wrapped, SIGNAL(endorsementToggled(int,QVariant,QVariant)),
|
||||
this, SLOT(endorsementToggled(int,QVariant,QVariant)),
|
||||
Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
void onRequestFailed(boost::python::object callback) {
|
||||
m_FailedHandler = callback;
|
||||
connect(m_Wrapped, SIGNAL(requestFailed(int,int,QVariant,QString)),
|
||||
@@ -90,11 +109,69 @@ private slots:
|
||||
GILock lock;
|
||||
m_FilesAvailableHandler(modID, userData, resultData);
|
||||
} catch (const boost::python::error_already_set&) {
|
||||
// qDebug("error");
|
||||
reportPythonError();
|
||||
}
|
||||
}
|
||||
|
||||
void descriptionAvailable(int modID, QVariant userData, const QVariant resultData)
|
||||
{
|
||||
try {
|
||||
if (m_DescriptionAvailableHandler.is_none()) {
|
||||
qCritical("no handler connected");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
GILock lock;
|
||||
m_DescriptionAvailableHandler(modID, userData, resultData);
|
||||
} catch (const boost::python::error_already_set&) {
|
||||
reportPythonError();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
qCritical("failed to report event: %s", e.what());
|
||||
} catch (...) {
|
||||
qCritical("failed to report event");
|
||||
}
|
||||
}
|
||||
|
||||
void fileInfoAvailable(int modID, int fileID, QVariant userData, const QVariant resultData) {
|
||||
try {
|
||||
if (m_FileInfoHandler.is_none()) {
|
||||
qCritical("no handler connected");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
GILock lock;
|
||||
m_FileInfoHandler(modID, fileID, userData, resultData);
|
||||
} catch (const boost::python::error_already_set&) {
|
||||
reportPythonError();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
qCritical("failed to report event: %s", e.what());
|
||||
} catch (...) {
|
||||
qCritical("failed to report event");
|
||||
}
|
||||
}
|
||||
|
||||
void endorsementToggled(int modID, QVariant userData, const QVariant resultData)
|
||||
{
|
||||
try {
|
||||
if (m_EndorsementToggledHandler.is_none()) {
|
||||
qCritical("no handler connected");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
GILock lock;
|
||||
m_EndorsementToggledHandler(modID, userData, resultData);
|
||||
} catch (const boost::python::error_already_set&) {
|
||||
reportPythonError();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
qCritical("failed to report event: %s", e.what());
|
||||
} catch (...) {
|
||||
qCritical("failed to report event");
|
||||
}
|
||||
}
|
||||
|
||||
void requestFailed(int modID, int fileID, QVariant userData, const QString &errorMessage)
|
||||
{
|
||||
try {
|
||||
@@ -109,21 +186,20 @@ private:
|
||||
|
||||
MOBase::IModRepositoryBridge *m_Wrapped;
|
||||
boost::python::object m_FilesAvailableHandler;
|
||||
boost::python::object m_DescriptionAvailableHandler;
|
||||
boost::python::object m_FileInfoHandler;
|
||||
boost::python::object m_EndorsementToggledHandler;
|
||||
boost::python::object m_FailedHandler;
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct IOrganizerWrapper: MOBase::IOrganizer, boost::python::wrapper<MOBase::IOrganizer>
|
||||
{
|
||||
virtual MOBase::IGameInfo &gameInfo() const {
|
||||
MOBase::IGameInfo *result = this->get_override("gameInfo")();
|
||||
return *result;
|
||||
}
|
||||
virtual MOBase::IModRepositoryBridge *createNexusBridge() const {
|
||||
return this->get_override("createNexusBridge")();
|
||||
}
|
||||
|
||||
virtual MOBase::IModRepositoryBridge *createNexusBridge() const { return this->get_override("createNexusBridge")(); }
|
||||
virtual QString profileName() const { return this->get_override("profileName")(); }
|
||||
virtual QString profilePath() const { return this->get_override("profilePath")(); }
|
||||
virtual QString downloadsPath() const { return this->get_override("downloadsPath")(); }
|
||||
@@ -146,8 +222,9 @@ struct IOrganizerWrapper: MOBase::IOrganizer, boost::python::wrapper<MOBase::IOr
|
||||
virtual QStringList findFiles(const QString &path, const std::function<bool(const QString&)> &filter) const { return this->get_override("findFiles")(path, filter); }
|
||||
virtual QList<FileInfo> findFileInfos(const QString &path, const std::function<bool(const FileInfo&)> &filter) const { return this->get_override("findFileInfos")(path, filter); }
|
||||
virtual HANDLE startApplication(const QString &executable, const QStringList &args = QStringList(), const QString &cwd = "", const QString &profile = "") { return this->get_override("startApplication")(executable, args, cwd, profile); }
|
||||
virtual bool onAboutToRun(const std::function<bool(const QString&)> &func) { return this->get_override("onAboutToRun")(func); }
|
||||
virtual void refreshModList(bool saveChanges = true) { this->get_override("refreshModList")(saveChanges); }
|
||||
virtual bool onAboutToRun(const std::function<bool(const QString&)> &func) { return this->get_override("onAboutToRun")(func); }
|
||||
virtual bool onModInstalled(const std::function<void(const QString&)> &func) { return this->get_override("onModInstalled")(func); }
|
||||
};
|
||||
|
||||
struct IDownloadManagerWrapper: MOBase::IDownloadManager, boost::python::wrapper<MOBase::IDownloadManager>
|
||||
@@ -155,8 +232,15 @@ struct IDownloadManagerWrapper: MOBase::IDownloadManager, boost::python::wrapper
|
||||
virtual int startDownloadURLs(const QStringList &urls) { return this->get_override("downloadURLs")(urls); }
|
||||
virtual int startDownloadNexusFile(int modID, int fileID) { return this->get_override("downloadNexusFile")(modID, fileID); }
|
||||
virtual QString downloadPath(int id) { return this->get_override("downloadPath")(id); }
|
||||
private:
|
||||
boost::python::object m_DownloadCompleteHandler;
|
||||
};
|
||||
|
||||
struct IModRepositoryBridgeWrapper: MOBase::IModRepositoryBridge, boost::python::wrapper<MOBase::IModRepositoryBridge>
|
||||
{
|
||||
virtual void requestDescription(int modID, QVariant userData) { this->get_override("requestDescription")(modID, userData); }
|
||||
virtual void requestFiles(int modID, QVariant userData) { this->get_override("requestFiles")(modID, userData); }
|
||||
virtual void requestFileInfo(int modID, int fileID, QVariant userData) { this->get_override("requestFileInfo")(modID, fileID, userData); }
|
||||
virtual void requestDownloadURL(int modID, int fileID, QVariant userData) { this->get_override("requestDownloadURL")(modID, fileID, userData); }
|
||||
virtual void requestToggleEndorsement(int modID, bool endorse, QVariant userData) { this->get_override("requestToggleEndorsement")(modID, endorse, userData); }
|
||||
};
|
||||
|
||||
struct IInstallationManagerWrapper: MOBase::IInstallationManager, boost::python::wrapper<MOBase::IInstallationManager>
|
||||
@@ -202,6 +286,7 @@ struct IModListWrapper: MOBase::IModList, boost::python::wrapper<MOBase::IModLis
|
||||
virtual int priority(const QString &name) const{ return this->get_override("priority")(name); }
|
||||
virtual bool setPriority(const QString &name, int newPriority){ return this->get_override("setPriority")(name, newPriority); }
|
||||
virtual bool onModStateChanged(const std::function<void (const QString &, ModStates)> &func) { return this->get_override("onModStateChanged")(func); }
|
||||
virtual bool onModMoved(const std::function<void (const QString &, int, int)> &func) { return this->get_override("onModMoved")(func); }
|
||||
};
|
||||
|
||||
#endif // UIBASEWRAPPERS_H
|
||||
|
||||
Reference in New Issue
Block a user