diff --git a/Documentation/source/devel/initGui.py b/Documentation/source/devel/initGui.py index a9d7510656..4fb910243c 100644 --- a/Documentation/source/devel/initGui.py +++ b/Documentation/source/devel/initGui.py @@ -3,9 +3,8 @@ #file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #Created by Alexandre GAUTHIER-FOICHAT on 01/27/2015. -#PySide is already imported by Natron, but we remove the cumbersome PySide.QtGui and PySide.QtCore prefix -from PySide.QtGui import * -from PySide.QtCore import * +from qtpy.QtGui import * +from qtpy.QtCore import * #To import the variable "natron" from NatronGui import * diff --git a/Engine/AppManager.cpp b/Engine/AppManager.cpp index 4e8b45cb3d..974ea47bb1 100644 --- a/Engine/AppManager.cpp +++ b/Engine/AppManager.cpp @@ -1954,37 +1954,28 @@ AppManager::loadPythonGroups() operateOnPathRecursive(&addToPythonPathFunctor, d); } - ///Also import Pyside.QtCore and Pyside.QtGui (the later only in non background mode) + ///Also import qtpy.QtCore and qtpy.QtGui (the later only in non background mode) { std::string s; -# if (SHIBOKEN_MAJOR_VERSION == 2) - s = "import PySide2\nimport PySide2.QtCore as QtCore"; -# else - s = "import PySide\nimport PySide.QtCore as QtCore"; -# endif + s = "import qtpy\nfrom qtpy import QtCore"; bool ok = NATRON_PYTHON_NAMESPACE::interpretPythonScript(s, &err, 0); if (!ok) { - QString message = tr("Failed to import PySide.QtCore, make sure it is bundled with your Natron installation " + QString message = tr("Failed to import qtpy.QtCore, make sure it is bundled with your Natron installation " "or reachable through the Python path. " "Note that Natron disables usage " "of site-packages)."); std::cerr << message.toStdString() << std::endl; - appPTR->writeToErrorLog_mt_safe(QLatin1String("PySide.QtCore"), QDateTime::currentDateTime(), message); + appPTR->writeToErrorLog_mt_safe(QLatin1String("qtpy.QtCore"), QDateTime::currentDateTime(), message); } } if ( !isBackground() ) { - std::string s; -# if (SHIBOKEN_MAJOR_VERSION == 2) - s = "import PySide2.QtGui as QtGui"; -# else - s = "import PySide.QtGui as QtGui"; -# endif + std::string s = "from qtpy import QtGui"; bool ok = NATRON_PYTHON_NAMESPACE::interpretPythonScript(s, &err, 0); if (!ok) { - QString message = tr("Failed to import PySide.QtGui"); + QString message = tr("Failed to import qtpy.QtGui"); std::cerr << message.toStdString() << std::endl; - appPTR->writeToErrorLog_mt_safe(QLatin1String("PySide.QtGui"), QDateTime::currentDateTime(), message); + appPTR->writeToErrorLog_mt_safe(QLatin1String("qtpy.QtGui"), QDateTime::currentDateTime(), message); } } @@ -3402,6 +3393,13 @@ AppManager::initPython() throw std::runtime_error( tr("Error while loading StreamCatcher: %1").arg( QString::fromUtf8( err.c_str() ) ).toStdString() ); } } + // Set QT_API for QtPy + // https://github.com/spyder-ide/qtpy +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + qputenv("QT_API", "pyside"); +#else + qputenv("QT_API", "pyside2"); +#endif } // AppManager::initPython void diff --git a/INSTALL_LINUX.md b/INSTALL_LINUX.md index 798329e5f5..9cb1823fde 100644 --- a/INSTALL_LINUX.md +++ b/INSTALL_LINUX.md @@ -14,6 +14,7 @@ Natron on GNU/Linux. - [Cairo](#cairo) - [Pyside](#pyside) - [Shiboken](#shiboken) + - [QtPy](#qtpy) 2. [Configuration](#configuration) - [OpenFX](#openfx) - [OpenColorIO-Configs](#download-opencolorio-configs) @@ -106,6 +107,13 @@ Natron uses pyside for python 2 Natron uses shiboken for python 2 +### QtPy + +Abstraction layer for PyQt5/PyQt4/PySide2/PySide. + +``` +pip install qtpy +``` # Configuration diff --git a/tools/jenkins/build-Linux-installer.sh b/tools/jenkins/build-Linux-installer.sh index 7380b12cd5..5262ef0927 100755 --- a/tools/jenkins/build-Linux-installer.sh +++ b/tools/jenkins/build-Linux-installer.sh @@ -584,6 +584,9 @@ if [ -x "${TMP_PORTABLE_DIR}"/bin/natron-python ]; then rm get-pip.py fi +# Install qtpy +"${TMP_PORTABLE_DIR}"/bin/natron-python -m pip install qtpy + # Run extra user provided pip install scripts if [ -f "${EXTRA_PYTHON_MODULES_SCRIPT:-}" ]; then "${TMP_PORTABLE_DIR}"/bin/natron-python "$EXTRA_PYTHON_MODULES_SCRIPT" || true diff --git a/tools/jenkins/build-OSX-installer.sh b/tools/jenkins/build-OSX-installer.sh index 75fc7510c3..abf2a2c150 100755 --- a/tools/jenkins/build-OSX-installer.sh +++ b/tools/jenkins/build-OSX-installer.sh @@ -908,6 +908,9 @@ if [ -x "${TMP_PORTABLE_DIR}.app/Contents/MacOS"/natron-python ]; then rm get-pip.py fi +# Install qtpy +"${TMP_PORTABLE_DIR}"/bin/natron-python -m pip install qtpy + # Run extra user provided pip install scripts if [ -f "${EXTRA_PYTHON_MODULES_SCRIPT:-}" ]; then "${TMP_PORTABLE_DIR}.app/Contents/MacOS"/natron-python "$EXTRA_PYTHON_MODULES_SCRIPT" || true diff --git a/tools/jenkins/build-Windows-installer.sh b/tools/jenkins/build-Windows-installer.sh index 60791793b0..6a80a49030 100755 --- a/tools/jenkins/build-Windows-installer.sh +++ b/tools/jenkins/build-Windows-installer.sh @@ -435,6 +435,9 @@ if [ -x "${TMP_PORTABLE_DIR}"/bin/natron-python ]; then rm get-pip.py fi +# Install qtpy +"${TMP_PORTABLE_DIR}"/bin/natron-python -m pip install qtpy + # Run extra user provided pip install scripts if [ -f "${EXTRA_PYTHON_MODULES_SCRIPT:-}" ]; then "${TMP_PORTABLE_DIR}"/bin/natron-python "$EXTRA_PYTHON_MODULES_SCRIPT" || true