mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Return a plugin as multiple (differently-typed) instances to work around multiple inheritance issues
This commit is contained in:
@@ -225,13 +225,13 @@ QStringList ProxyPython::pluginList(const QString &pluginPath) const
|
||||
}
|
||||
|
||||
|
||||
QObject *ProxyPython::instantiate(const QString &pluginName)
|
||||
QList<QObject*> ProxyPython::instantiate(const QString &pluginName)
|
||||
{
|
||||
if (m_Runner != nullptr) {
|
||||
QObject *result = m_Runner->instantiate(pluginName);
|
||||
QList<QObject*> result = m_Runner->instantiate(pluginName);
|
||||
return result;
|
||||
} else {
|
||||
return nullptr;
|
||||
return QList<QObject*>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
virtual QList<MOBase::PluginSetting> settings() const;
|
||||
|
||||
QStringList pluginList(const QString &pluginPath) const;
|
||||
QObject *instantiate(const QString &pluginName);
|
||||
QList<QObject*> instantiate(const QString &pluginName);
|
||||
|
||||
/**
|
||||
* @return the parent widget for newly created dialogs
|
||||
|
||||
@@ -37,7 +37,7 @@ class PythonRunner : public IPythonRunner
|
||||
public:
|
||||
PythonRunner(const MOBase::IOrganizer *moInfo);
|
||||
bool initPython(const QString &pythonDir);
|
||||
QObject *instantiate(const QString &pluginName);
|
||||
QList<QObject*> instantiate(const QString &pluginName);
|
||||
bool isPythonInstalled() const;
|
||||
bool isPythonVersionSupported() const;
|
||||
|
||||
@@ -1266,7 +1266,7 @@ bool handled_exec_file(bpy::str filename, bpy::object globals = bpy::object(), b
|
||||
bpy::extract<type *> extr(var); \
|
||||
if (extr.check()) { \
|
||||
QObject *res = extr; \
|
||||
return res; \
|
||||
interfaceList.append(res); \
|
||||
}\
|
||||
} while (false)
|
||||
|
||||
@@ -1289,7 +1289,7 @@ void PythonRunner::initPath(bpy::object &moduleNamespace)
|
||||
}
|
||||
|
||||
|
||||
QObject *PythonRunner::instantiate(const QString &pluginName)
|
||||
QList<QObject*> PythonRunner::instantiate(const QString &pluginName)
|
||||
{
|
||||
try {
|
||||
GILock lock;
|
||||
@@ -1303,11 +1303,12 @@ QObject *PythonRunner::instantiate(const QString &pluginName)
|
||||
std::string temp = ToString(pluginName);
|
||||
if (handled_exec_file(temp.c_str(), moduleNamespace)) {
|
||||
reportPythonError();
|
||||
return nullptr;
|
||||
return QList<QObject*>();
|
||||
}
|
||||
m_PythonObjects[pluginName] = moduleNamespace["createPlugin"]();
|
||||
|
||||
bpy::object pluginObj = m_PythonObjects[pluginName];
|
||||
QList<QObject *> interfaceList;
|
||||
TRY_PLUGIN_TYPE(IPluginGame, pluginObj);
|
||||
// Must try the wrapper because it's only a plugin extension interface in C++, so doesn't extend QObject
|
||||
TRY_PLUGIN_TYPE(IPluginDiagnoseWrapper, pluginObj);
|
||||
@@ -1317,11 +1318,13 @@ QObject *PythonRunner::instantiate(const QString &pluginName)
|
||||
TRY_PLUGIN_TYPE(IPluginModPage, pluginObj);
|
||||
TRY_PLUGIN_TYPE(IPluginPreview, pluginObj);
|
||||
TRY_PLUGIN_TYPE(IPluginTool, pluginObj);
|
||||
|
||||
return interfaceList;
|
||||
} catch (const bpy::error_already_set&) {
|
||||
qWarning("failed to run python script \"%s\"", qPrintable(pluginName));
|
||||
reportPythonError();
|
||||
}
|
||||
return nullptr;
|
||||
return QList<QObject*>();
|
||||
}
|
||||
|
||||
bool PythonRunner::isPythonInstalled() const
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
class IPythonRunner {
|
||||
public:
|
||||
virtual QObject *instantiate(const QString &pluginName) = 0;
|
||||
virtual QList<QObject*> instantiate(const QString &pluginName) = 0;
|
||||
virtual bool isPythonInstalled() const = 0;
|
||||
virtual bool isPythonVersionSupported() const = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user