mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Merge branch 'qt6' into fix/qt-type-caster
This commit is contained in:
@@ -201,7 +201,7 @@ namespace mo2::python {
|
||||
.def("genFilePreview", &IPluginPreview::genFilePreview, "filename"_a,
|
||||
"max_size"_a);
|
||||
|
||||
py::class_<IPluginModPage, PyPluginModPage, IPluginModPage,
|
||||
py::class_<IPluginModPage, PyPluginModPage, IPlugin,
|
||||
std::unique_ptr<IPluginModPage, py::nodelete>>(
|
||||
m, "IPluginModPage", py::multiple_inheritance())
|
||||
.def(py::init<>())
|
||||
|
||||
+14
-14
@@ -4,70 +4,70 @@
|
||||
<context>
|
||||
<name>ProxyPython</name>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="121"/>
|
||||
<location filename="proxy/proxypython.cpp" line="88"/>
|
||||
<source>Python Initialization failed</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="122"/>
|
||||
<location filename="proxy/proxypython.cpp" line="89"/>
|
||||
<source>On a previous start the Python Plugin failed to initialize.
|
||||
Do you want to try initializing python again (at the risk of another crash)?
|
||||
Suggestion: Select "no", and click the warning sign for further help.Afterwards you have to re-enable the python plugin.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="173"/>
|
||||
<location filename="proxy/proxypython.cpp" line="162"/>
|
||||
<source>Python Proxy</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="183"/>
|
||||
<location filename="proxy/proxypython.cpp" line="172"/>
|
||||
<source>Proxy Plugin to allow plugins written in python to be loaded</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="255"/>
|
||||
<location filename="proxy/proxypython.cpp" line="244"/>
|
||||
<source>ModOrganizer path contains a semicolon</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="257"/>
|
||||
<location filename="proxy/proxypython.cpp" line="246"/>
|
||||
<source>Python DLL not found</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="259"/>
|
||||
<location filename="proxy/proxypython.cpp" line="248"/>
|
||||
<source>Invalid Python DLL</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="261"/>
|
||||
<location filename="proxy/proxypython.cpp" line="250"/>
|
||||
<source>Initializing Python failed</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="263"/>
|
||||
<location filename="proxy/proxypython.cpp" line="293"/>
|
||||
<location filename="proxy/proxypython.cpp" line="252"/>
|
||||
<location filename="proxy/proxypython.cpp" line="282"/>
|
||||
<source>invalid problem key %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="271"/>
|
||||
<location filename="proxy/proxypython.cpp" line="260"/>
|
||||
<source>The path to Mod Organizer (%1) contains a semicolon. <br>While this is legal on NTFS drives, many softwares do not handle it correctly.<br>Unfortunately MO depends on libraries that seem to fall into that group.<br>As a result the python plugin cannot be loaded, and the only solution we canoffer is to remove the semicolon or move MO to a path without a semicolon.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="282"/>
|
||||
<location filename="proxy/proxypython.cpp" line="271"/>
|
||||
<source>The Python plugin DLL was not found, maybe your antivirus deleted it. Re-installing MO2 might fix the problem.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="285"/>
|
||||
<location filename="proxy/proxypython.cpp" line="274"/>
|
||||
<source>The Python plugin DLL is invalid, maybe your antivirus is blocking it. Re-installing MO2 and adding exclusions for it to your AV might fix the problem.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxy/proxypython.cpp" line="290"/>
|
||||
<location filename="proxy/proxypython.cpp" line="279"/>
|
||||
<source>The initialization of the Python plugin DLL failed, unfortunately without any details.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
||||
@@ -48,8 +48,8 @@ install(FILES ${PYTHON_BUILD_PATH}/pythoncore/python${Python_VERSION_SHORT}.zip
|
||||
install(TARGETS mobase DESTINATION ${PYLIB_DIR})
|
||||
|
||||
# install PyQt6
|
||||
file(GLOB PYQT_DIR ${MO2_BUILD_PATH}/PyQt${QT_MAJOR_VERSION}*)
|
||||
set(PYQT_LIB_DIR ${PYQT_DIR}/Lib/site-packages/PyQt${QT_MAJOR_VERSION})
|
||||
#file(GLOB PYQT_DIR ${MO2_BUILD_PATH}/PyQt${QT_MAJOR_VERSION}*)
|
||||
set(PYQT_LIB_DIR ${PYTHON_ROOT}/Lib/site-packages/PyQt${QT_MAJOR_VERSION})
|
||||
set(PYQT_TARGET_DIR ${PYLIB_DIR}/PyQt${QT_MAJOR_VERSION})
|
||||
file(GLOB pyqt_files ${PYQT_LIB_DIR}/*.py ${PYQT_LIB_DIR}/*.pyd ${PYQT_LIB_DIR}/*.pyi)
|
||||
install(FILES ${pyqt_files} DESTINATION ${PYQT_TARGET_DIR})
|
||||
|
||||
@@ -129,9 +129,9 @@ bool ProxyPython::init(IOrganizer* moInfo)
|
||||
|
||||
if (m_Runner) {
|
||||
const auto libpath = pluginFolder / "libs";
|
||||
const QStringList paths{
|
||||
QFileInfo(libpath / "pythoncore.zip").absoluteFilePath(),
|
||||
QFileInfo(libpath).absoluteFilePath(), IOrganizer::getPluginDataPath()};
|
||||
const std::vector<fs::path> paths{
|
||||
libpath / "pythoncore.zip", libpath,
|
||||
std::filesystem::path{IOrganizer::getPluginDataPath().toStdWString()}};
|
||||
m_Runner->initialize(paths);
|
||||
}
|
||||
|
||||
@@ -139,12 +139,15 @@ bool ProxyPython::init(IOrganizer* moInfo)
|
||||
m_MOInfo->setPersistent(name(), "tryInit", false);
|
||||
}
|
||||
|
||||
// reset DLL directory
|
||||
SetDllDirectoryW(NULL);
|
||||
|
||||
if (!m_Runner || !m_Runner->isInitialized()) {
|
||||
m_LoadFailure = FailureType::INITIALIZATION;
|
||||
}
|
||||
|
||||
// reset DLL directory
|
||||
SetDllDirectoryW(NULL);
|
||||
else {
|
||||
m_Runner->addDllSearchPath(pluginFolder / "dlls");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
@@ -12,6 +14,7 @@
|
||||
#include "pybind11_qt/pybind11_qt.h"
|
||||
#include <pybind11/embed.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/stl/filesystem.h>
|
||||
|
||||
#include <log.h>
|
||||
#include <utility.h>
|
||||
@@ -36,7 +39,8 @@ namespace mo2::python {
|
||||
QList<QObject*> load(const QString& identifier) override;
|
||||
void unload(const QString& identifier) override;
|
||||
|
||||
bool initialize(QStringList const& paths) override;
|
||||
bool initialize(std::vector<std::filesystem::path> const& pythonPaths) override;
|
||||
void addDllSearchPath(std::filesystem::path const& dllPath) override;
|
||||
bool isInitialized() const override;
|
||||
|
||||
private:
|
||||
@@ -57,7 +61,7 @@ namespace mo2::python {
|
||||
return std::make_unique<PythonRunner>();
|
||||
}
|
||||
|
||||
bool PythonRunner::initialize(QStringList const& paths)
|
||||
bool PythonRunner::initialize(std::vector<std::filesystem::path> const& pythonPaths)
|
||||
{
|
||||
// we only initialize Python once for the whole lifetime of the program, even if
|
||||
// MO2 is restarted and the proxy or PythonRunner objects are deleted and
|
||||
@@ -81,7 +85,11 @@ namespace mo2::python {
|
||||
// initialize the core Path of Python, this must be done before
|
||||
// initialization
|
||||
//
|
||||
if (!paths.isEmpty()) {
|
||||
if (!pythonPaths.empty()) {
|
||||
QStringList paths;
|
||||
for (auto const& p : pythonPaths) {
|
||||
paths.append(QString::fromStdWString(absolute(p).native()));
|
||||
}
|
||||
Py_SetPath(paths.join(';').toStdWString().c_str());
|
||||
}
|
||||
|
||||
@@ -123,6 +131,12 @@ namespace mo2::python {
|
||||
}
|
||||
}
|
||||
|
||||
void PythonRunner::addDllSearchPath(std::filesystem::path const& dllPath)
|
||||
{
|
||||
py::gil_scoped_acquire lock;
|
||||
py::module_::import("os").attr("add_dll_directory")(absolute(dllPath));
|
||||
}
|
||||
|
||||
void PythonRunner::ensureFolderInPath(QString folder)
|
||||
{
|
||||
py::module_ sys = py::module_::import("sys");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef PYTHONRUNNER_H
|
||||
#define PYTHONRUNNER_H
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
|
||||
#include <QList>
|
||||
@@ -25,14 +26,19 @@ namespace mo2::python {
|
||||
|
||||
// initialize Python
|
||||
//
|
||||
// paths contains the list of built-in paths for the Python library
|
||||
// pythonPaths contains the list of built-in paths for the Python library
|
||||
// (pythonxxx.zip, etc.), an empty list uses the default Python paths (e.g., the
|
||||
// PYTHONPATH environment variable)
|
||||
//
|
||||
virtual bool initialize(QStringList const& paths = {}) = 0;
|
||||
virtual bool
|
||||
initialize(std::vector<std::filesystem::path> const& pythonPaths = {}) = 0;
|
||||
|
||||
// check if the runner has been initialized, i.e., initialize() has been called
|
||||
// and succeeded
|
||||
// add a DLL search path
|
||||
//
|
||||
virtual void addDllSearchPath(std::filesystem::path const& dllPath) = 0;
|
||||
|
||||
// check if the runner has been initialized, i.e., initialize() has been
|
||||
// called and succeeded
|
||||
virtual bool isInitialized() const = 0;
|
||||
|
||||
virtual ~IPythonRunner() {}
|
||||
|
||||
@@ -19,7 +19,8 @@ target_link_libraries(runner-tests PUBLIC runner)
|
||||
set(PYLIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/pylibs)
|
||||
mo2_python_pip_install(runner-tests
|
||||
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pylibs
|
||||
PACKAGES
|
||||
PACKAGES
|
||||
pytest
|
||||
PyQt${QT_MAJOR_VERSION}==${QT_VERSION}
|
||||
PyQt${QT_MAJOR_VERSION}-Qt${QT_MAJOR_VERSION}==${QT_VERSION})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user