mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Create template for wrapper functions and add helpful error message. Use this for plugin wrappers.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include <isavegameinfowidget.h>
|
||||
|
||||
#include "gilock.h"
|
||||
#include "pycatch.h"
|
||||
#include "pythonwrapperutilities.h"
|
||||
|
||||
/////////////////////////////
|
||||
/// BSAInvalidation Wrapper
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,9 @@ class IPluginWrapper : public MOBase::IPlugin, public boost::python::wrapper<MOB
|
||||
Q_INTERFACES(MOBase::IPlugin)
|
||||
|
||||
COMMON_I_PLUGIN_WRAPPER_DECLARATIONS
|
||||
public:
|
||||
static constexpr const char* className = "IPluginWrapper";
|
||||
using boost::python::wrapper<MOBase::IPlugin>::get_override;
|
||||
};
|
||||
|
||||
|
||||
@@ -42,6 +45,9 @@ class IPluginDiagnoseWrapper : public QObject, public MOBase::IPluginDiagnose, p
|
||||
Q_INTERFACES(MOBase::IPlugin MOBase::IPluginDiagnose)
|
||||
|
||||
public:
|
||||
static constexpr const char* className = "IPluginDiagnoseWrapper";
|
||||
using boost::python::wrapper<MOBase::IPluginDiagnose>::get_override;
|
||||
|
||||
virtual std::vector<unsigned int> activeProblems() const override;
|
||||
virtual QString shortDescription(unsigned int key) const override;
|
||||
virtual QString fullDescription(unsigned int key) const override;
|
||||
@@ -63,6 +69,9 @@ class IPluginFileMapperWrapper : public QObject, public MOBase::IPluginFileMappe
|
||||
Q_INTERFACES(MOBase::IPlugin MOBase::IPluginFileMapper)
|
||||
|
||||
public:
|
||||
static constexpr const char* className = "IPluginFileMapperWrapper";
|
||||
using boost::python::wrapper<MOBase::IPluginFileMapper>::get_override;
|
||||
|
||||
virtual MappingType mappings() const override;
|
||||
|
||||
COMMON_I_PLUGIN_WRAPPER_DECLARATIONS
|
||||
@@ -74,6 +83,9 @@ class IPluginGameWrapper : public MOBase::IPluginGame, public boost::python::wra
|
||||
Q_INTERFACES(MOBase::IPlugin MOBase::IPluginGame)
|
||||
|
||||
public:
|
||||
static constexpr const char* className = "IPluginGameWrapper";
|
||||
using boost::python::wrapper<MOBase::IPluginGame>::get_override;
|
||||
|
||||
virtual QString gameName() const override;
|
||||
virtual void initializeProfile(const QDir &directory, ProfileSettings settings) const override;
|
||||
virtual QString savegameExtension() const override;
|
||||
@@ -122,6 +134,9 @@ class IPluginInstallerCustomWrapper : public MOBase::IPluginInstallerCustom, pub
|
||||
|
||||
COMMON_I_PLUGIN_WRAPPER_DECLARATIONS
|
||||
public:
|
||||
static constexpr const char* className = "IPluginInstallerCustomWrapper";
|
||||
using boost::python::wrapper<MOBase::IPluginInstallerCustom>::get_override;
|
||||
|
||||
virtual unsigned int priority() const;
|
||||
virtual bool isManualInstaller() const;
|
||||
virtual bool isArchiveSupported(const MOBase::DirectoryTree &tree) const;
|
||||
@@ -141,6 +156,9 @@ class IPluginModPageWrapper : public MOBase::IPluginModPage, public boost::pytho
|
||||
|
||||
COMMON_I_PLUGIN_WRAPPER_DECLARATIONS
|
||||
public:
|
||||
static constexpr const char* className = "IPluginModPageWrapper";
|
||||
using boost::python::wrapper<MOBase::IPluginModPage>::get_override;
|
||||
|
||||
virtual QString displayName() const override;
|
||||
virtual QIcon icon() const override;
|
||||
virtual QUrl pageURL() const override;
|
||||
@@ -157,6 +175,9 @@ class IPluginPreviewWrapper : public MOBase::IPluginPreview, public boost::pytho
|
||||
|
||||
COMMON_I_PLUGIN_WRAPPER_DECLARATIONS
|
||||
public:
|
||||
static constexpr const char* className = "IPluginPreviewWrapper";
|
||||
using boost::python::wrapper<MOBase::IPluginPreview>::get_override;
|
||||
|
||||
virtual std::set<QString> supportedExtensions() const override;
|
||||
virtual QWidget *genFilePreview(const QString &fileName, const QSize &maxSize) const override;
|
||||
};
|
||||
@@ -169,6 +190,9 @@ class IPluginToolWrapper: public MOBase::IPluginTool, public boost::python::wrap
|
||||
|
||||
COMMON_I_PLUGIN_WRAPPER_DECLARATIONS
|
||||
public:
|
||||
static constexpr const char* className = "IPluginToolWrapper";
|
||||
using boost::python::wrapper<MOBase::IPluginTool>::get_override;
|
||||
|
||||
virtual QString displayName() const;
|
||||
virtual QString tooltip() const;
|
||||
virtual QIcon icon() const;
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef PYCATCH_H
|
||||
#define PYCATCH_H
|
||||
|
||||
#include <utility.h>
|
||||
|
||||
#include "error.h"
|
||||
|
||||
#define PYCATCH catch (const boost::python::error_already_set &) { reportPythonError(); throw MOBase::MyException("unhandled exception"); }\
|
||||
catch (...) { throw MOBase::MyException("An unknown exception was thrown in python code"); }
|
||||
|
||||
#endif // PYCATCH_H
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef PYTHONWRAPPERUTILITIES_H
|
||||
#define PYTHONWRAPPERUTILITIES_H
|
||||
|
||||
#include <utility.h>
|
||||
|
||||
#include "error.h"
|
||||
|
||||
class MissingImplementation : public MOBase::MyException {
|
||||
public:
|
||||
MissingImplementation(QString className, QString methodName) : MyException("Python class implementing \"" +
|
||||
className +
|
||||
"\" has no implementation of method \"" +
|
||||
methodName + "\"") {}
|
||||
};
|
||||
|
||||
#define PYCATCH catch (const boost::python::error_already_set &) { reportPythonError(); throw MOBase::MyException("unhandled exception"); }\
|
||||
catch (const MissingImplementation &missingImplementationException) { throw missingImplementationException; }\
|
||||
catch (...) { throw MOBase::MyException("An unknown exception was thrown in python code"); }
|
||||
|
||||
template <typename WrapperType, typename ReturnType, typename... Args>
|
||||
ReturnType basicWrapperFunctionImplementation(const WrapperType *wrapper, const char *methodName, Args... args)
|
||||
{
|
||||
try {
|
||||
GILock lock;
|
||||
boost::python::override implementation = wrapper->get_override(methodName);
|
||||
if (!implementation)
|
||||
throw MissingImplementation(wrapper->className, methodName);
|
||||
return implementation(args...).as<ReturnType>();
|
||||
} PYCATCH;
|
||||
}
|
||||
|
||||
#endif // PYTHONWRAPPERUTILITIES_H
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include "error.h"
|
||||
#include "gilock.h"
|
||||
#include "pycatch.h"
|
||||
#include "pythonwrapperutilities.h"
|
||||
|
||||
extern MOBase::IOrganizer *s_Organizer;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user