diff --git a/src/proxy/proxyPython.pro b/src/proxy/proxyPython.pro index ec0a6da..ca35ad4 100644 --- a/src/proxy/proxyPython.pro +++ b/src/proxy/proxyPython.pro @@ -10,6 +10,7 @@ TEMPLATE = lib CONFIG += plugins CONFIG += dll +CONFIG += warn_on DEFINES += PROXYPYTHON_LIBRARY diff --git a/src/proxy/proxypluginwrappers.cpp b/src/proxy/proxypluginwrappers.cpp index 5848f13..1f18d21 100644 --- a/src/proxy/proxypluginwrappers.cpp +++ b/src/proxy/proxypluginwrappers.cpp @@ -1,27 +1,13 @@ #include "proxypluginwrappers.h" #include #include +#include "error.h" +#include "gilock.h" namespace bpy = boost::python; using namespace MOBase; -static void reportPythonError() -{ - if (PyErr_Occurred()) { - // prints to s_ErrIO buffer - PyErr_Print(); - // extract data from python buffer - bpy::object mainModule = bpy::import("__main__"); - bpy::object mainNamespace = mainModule.attr("__dict__"); - bpy::object errMsgObj = bpy::eval("s_ErrIO.getvalue()", mainNamespace); - QString errMsg = bpy::extract(errMsgObj.ptr()); - bpy::eval("s_ErrIO.truncate(0)", mainNamespace); - throw MyException(errMsg); - } else { - throw MyException("An unexpected C++ exception was thrown in python code"); - } -} #define PYCATCH catch (const bpy::error_already_set &) { reportPythonError(); throw MyException("unhandled exception"); }\ catch (...) { throw MyException("An unknown exception was thrown in python code"); } @@ -111,6 +97,8 @@ void IPluginToolWrapper::setParentWidget(QWidget *parent) void IPluginToolWrapper::display() const { try { + GILock lock; + this->get_override("display")(); } PYCATCH; } @@ -205,10 +193,11 @@ std::set IPluginInstallerCustomWrapper::supportedExtensions() const } -IPluginInstaller::EInstallResult IPluginInstallerCustomWrapper::install(GuessedValue &modName, const QString &archiveName) +IPluginInstaller::EInstallResult IPluginInstallerCustomWrapper::install(GuessedValue &modName, const QString &archiveName, + const QString &version, int modID) { try { - return this->get_override("install")(modName, archiveName); + return this->get_override("install")(modName, archiveName, version, modID); } PYCATCH; } diff --git a/src/proxy/proxypluginwrappers.h b/src/proxy/proxypluginwrappers.h index 741feb4..49e87df 100644 --- a/src/proxy/proxypluginwrappers.h +++ b/src/proxy/proxypluginwrappers.h @@ -68,7 +68,8 @@ public: virtual bool isArchiveSupported(const MOBase::DirectoryTree &tree) const; virtual bool isArchiveSupported(const QString &archiveName) const; virtual std::set supportedExtensions() const; - virtual EInstallResult install(MOBase::GuessedValue &modName, const QString &archiveName); + virtual EInstallResult install(MOBase::GuessedValue &modName, const QString &archiveName, + const QString &version, int modID); virtual void setParentWidget(QWidget *parent); }; diff --git a/src/proxy/proxypython.cpp b/src/proxy/proxypython.cpp index c909d84..9109751 100644 --- a/src/proxy/proxypython.cpp +++ b/src/proxy/proxypython.cpp @@ -19,7 +19,6 @@ // sip and qt slots seems to conflict #include - using namespace MOBase; namespace bpy = boost::python; @@ -137,7 +136,6 @@ struct QVariant_to_python_obj case QVariant::Bool: return PyBool_FromLong(var.toBool()); case QVariant::String: return bpy::incref(bpy::object(var.toString().toUtf8().constData()).ptr()); case QVariant::List: { - qDebug("to list convert"); QVariantList list = var.toList(); PyObject *result = PyList_New(list.count()); foreach (QVariant var, list) { @@ -321,7 +319,6 @@ template <> struct MetaData { static const char *className() { return " template <> struct MetaData { static const char *className() { return "QWidget"; } }; template <> struct MetaData { static const char *className() { return "QIcon"; } }; template <> struct MetaData { static const char *className() { return "QVariant"; } }; -//template <> struct MetaData > { static const char *className() { return "QList"; } }; template @@ -347,7 +344,6 @@ PyObject *toPyQt(T *objPtr) return bpy::incref(sipObj); } - template struct QClass_converters { @@ -402,7 +398,6 @@ struct QClass_converters sipSimpleWrapper *wrapper = reinterpret_cast(objPtr); return wrapper->data; } - QClass_converters() { bpy::converter::registry::insert(&QClass_from_PyQt, bpy::type_id()); @@ -579,13 +574,6 @@ BOOST_PYTHON_MODULE(mobase) bpy::class_("IPluginInstallerCustom") .def("setParentWidget", bpy::pure_virtual(&MOBase::IPluginInstallerCustom::setParentWidget)); -/* bpy::class_("ModRepositoryFileInfo") - .def_readonly("name", &ModRepositoryFileInfo::name) - .def_readonly("uri", &ModRepositoryFileInfo::uri) - .def_readonly("version", &ModRepositoryFileInfo::version) - .def_readonly("categoryID", &ModRepositoryFileInfo::categoryID); - int fileID;*/ - GuessedValue_converters(); bpy::to_python_converter(); @@ -598,6 +586,8 @@ BOOST_PYTHON_MODULE(mobase) } +static char* argv0 = "ModOrganizer.exe"; + ProxyPython::ProxyPython() : m_MOInfo(NULL) { @@ -606,7 +596,6 @@ ProxyPython::ProxyPython() Py_Initialize(); qDebug("Python: %s", Py_GetVersion()); - static char* argv0 = "Banana?"; PySys_SetArgv(0, &argv0); bpy::object main_module = bpy::import("__main__"); @@ -700,12 +689,12 @@ QObject *ProxyPython::instantiate(const QString &pluginName) bpy::object main_namespace = main_module.attr("__dict__"); bpy::object mobase_module((bpy::handle<>(PyImport_ImportModule("mobase")))); + main_namespace["sys"] = bpy::import("sys"); main_namespace["mobase"] = mobase_module; QString appendDataPath = QString("sys.path.append(\"%1\")").arg(m_MOInfo->pluginDataPath()); bpy::eval(appendDataPath.toUtf8().constData(), main_namespace); - main_namespace["interfaces"] = bpy::import("interfaces"); std::string temp = ToString(pluginName); @@ -718,8 +707,6 @@ QObject *ProxyPython::instantiate(const QString &pluginName) bpy::object pluginObj = m_PythonObjects[pluginName]; TRY_PLUGIN_TYPE(IPluginInstallerCustom, pluginObj); TRY_PLUGIN_TYPE(IPluginTool, pluginObj); - } catch (const std::exception &e) { - qWarning("failed to run python script \"%s\": %s", qPrintable(pluginName), e.what()); } catch (const bpy::error_already_set&) { qWarning("failed to run python script \"%s\"", qPrintable(pluginName)); reportPythonError(); diff --git a/src/proxy/uibasewrappers.h b/src/proxy/uibasewrappers.h index 636fd45..ac589af 100644 --- a/src/proxy/uibasewrappers.h +++ b/src/proxy/uibasewrappers.h @@ -131,7 +131,7 @@ struct IOrganizerWrapper: MOBase::IOrganizer, boost::python::wrapperget_override("downloadsPath")(); } virtual MOBase::VersionInfo appVersion() const { return this->get_override("appVersion")(); } virtual MOBase::IModInterface *getMod(const QString &name) { return this->get_override("getMod")(name); } - virtual MOBase::IModInterface *createMod(const QString &name) { return this->get_override("createMod")(name); } + virtual MOBase::IModInterface *createMod(MOBase::GuessedValue &name) { return this->get_override("createMod")(name); } virtual bool removeMod(MOBase::IModInterface *mod) { return this->get_override("removeMod")(mod); } virtual void modDataChanged(MOBase::IModInterface *mod) { this->get_override("modDataChanged")(mod); } virtual QVariant pluginSetting(const QString &pluginName, const QString &key) const { return this->get_override("pluginSetting")(pluginName, key); }