From 3be8a94a69af89475dda1be8a45de58b9df2fd39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Devernay?= Date: Fri, 29 Oct 2021 16:27:07 -0700 Subject: [PATCH] RB-2.5: use qtpy rather than pyside (#687) * use qtpy rather than pyside it will ease the transition to Qt5/PySide2 Suggested by https://github.com/NatronGitHub/Natron/issues/256#issuecomment-864160634 --- Documentation/source/devel/initGui.py | 5 ++-- Engine/AppManager.cpp | 30 +++++++++++------------- INSTALL_LINUX.md | 16 +++++++++---- tools/jenkins/build-Linux-installer.sh | 21 +++++++++++------ tools/jenkins/build-OSX-installer.sh | 21 +++++++++++------ tools/jenkins/build-Windows-installer.sh | 22 ++++++++++------- 6 files changed, 70 insertions(+), 45 deletions(-) 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 32fde4165f..fa09ae1f66 100644 --- a/Engine/AppManager.cpp +++ b/Engine/AppManager.cpp @@ -1959,37 +1959,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); } } @@ -3407,6 +3398,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 05a965672d..eb18352e01 100644 --- a/INSTALL_LINUX.md +++ b/INSTALL_LINUX.md @@ -5,7 +5,7 @@ This file is supposed to guide you step by step to have working (compiling) vers * It's recommended to use Docker for the easiest hands-off installation method - see [here](#using-docker) for more details * If you are on Arch Linux or Manjaro, see [this](#arch-linux) for relevant details -* If you are on Centos, Fedora or RHEL, see [here](#centos7) for specific instructions +* If you are on Centos, Fedora or RHEL, see [here](#centos7) for specific instructions * If you are on a Debian-based Linux (such as Ubuntu, KDE Plasma, ElementaryOS etc.) see [here](#debian-based) for details * If you are willing to try the complete installation process, the instructions are below @@ -20,6 +20,7 @@ This file is supposed to guide you step by step to have working (compiling) vers - [Cairo](#cairo) - [Pyside](#pyside) - [Shiboken](#shiboken) + - [QtPy](#qtpy) 2. [Configuration](#configuration) - [OpenFX](#openfx) - [OpenColorIO-Configs](#download-opencolorio-configs) @@ -52,7 +53,7 @@ The Natron SDK is used for building the official Natron binaries. The script tha cd tools/jenkins include/scripts/build-Linux-sdk.sh - + It puts build logs and the list of files installed by each package in the directory `/opt/Natron-sdk/var/log/Natron-Linux-x86_64-SDK` or `/opt/Natron-sdk/var/log/Natron-Linux-i686-SDK`. Some packages, especially Qt 4.8.7, have Natron-specific patches. Take a look at the SDK script to see which patches are applied to each packages, and what configuration options are used. @@ -121,6 +122,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 @@ -332,11 +340,11 @@ any Debian-based distribution (e.g. Ubuntu). If your version of Ubuntu does not provide cairo 1.12 (required for rotoscoping), use the xorg-edger PPA: ``` -sudo add-apt-repository -y ppa:xorg-edgers/ppa +sudo add-apt-repository -y ppa:xorg-edgers/ppa ``` If your version of Ubuntu does not provide boost 1.49, the irie PPA can be used: ``` -sudo add-apt-repository -y ppa:irie/boost +sudo add-apt-repository -y ppa:irie/boost ``` Install the required packages: ``` diff --git a/tools/jenkins/build-Linux-installer.sh b/tools/jenkins/build-Linux-installer.sh index 80c2c58daf..f572b52687 100755 --- a/tools/jenkins/build-Linux-installer.sh +++ b/tools/jenkins/build-Linux-installer.sh @@ -577,20 +577,27 @@ export PY_BIN="${SDK_HOME}/bin/python${PYVER:-}" export PYDIR="$PYDIR" . "$CWD"/zip-python.sh +NATRON_PYTHON="${TMP_PORTABLE_DIR}/bin/natron-python" # Install pip -if [ -x "${TMP_PORTABLE_DIR}"/bin/natron-python ]; then +if [ -x "${NATRON_PYTHON}" ]; then if [ "$PYV" = "2" ]; then $CURL --remote-name --insecure https://bootstrap.pypa.io/pip/${PYVER}/get-pip.py else $CURL --remote-name --insecure https://bootstrap.pypa.io/get-pip.py fi - "${TMP_PORTABLE_DIR}"/bin/natron-python get-pip.py + "${NATRON_PYTHON}" get-pip.py rm get-pip.py -fi - -# 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 + # Install qtpy + if [ "${USE_QT5:-}" != 1 ]; then + # Qt4 support was dropped after QtPy 1.11.2 + "${NATRON_PYTHON}" -m pip install qtpy==1.11.2 + else + "${NATRON_PYTHON}"" -m pip install qtpy + fi + # Run extra user provided pip install scripts + if [ -f "${EXTRA_PYTHON_MODULES_SCRIPT:-}" ]; then + "${NATRON_PYTHON}"" "$EXTRA_PYTHON_MODULES_SCRIPT" || true + fi fi diff --git a/tools/jenkins/build-OSX-installer.sh b/tools/jenkins/build-OSX-installer.sh index b219280431..40c4493e73 100755 --- a/tools/jenkins/build-OSX-installer.sh +++ b/tools/jenkins/build-OSX-installer.sh @@ -901,20 +901,27 @@ export PY_BIN="${MACPORTS}/bin/python${PYVER:-}" export PYDIR="$pkglib/Python.framework/Versions/${PYVER}/lib/python${PYVER}" . "$CWD/zip-python.sh" +NATRON_PYTHON="${TMP_PORTABLE_DIR}.app/Contents/MacOS/natron-python" # Install pip -if [ -x "${TMP_PORTABLE_DIR}.app/Contents/MacOS"/natron-python ]; then +if [ -x "${NATRON_PYTHON}" ]; then if [ "$PYV" = "2" ]; then $CURL --remote-name --insecure https://bootstrap.pypa.io/pip/${PYVER}/get-pip.py else $CURL --remote-name --insecure https://bootstrap.pypa.io/get-pip.py fi - "${TMP_PORTABLE_DIR}.app/Contents/MacOS"/natron-python get-pip.py + "${NATRON_PYTHON}" get-pip.py rm get-pip.py -fi - -# 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 + # Install qtpy + if [ "${USE_QT5:-}" != 1 ]; then + # Qt4 support was dropped after QtPy 1.11.2 + "${NATRON_PYTHON}" -m pip install qtpy==1.11.2 + else + "${NATRON_PYTHON}"" -m pip install qtpy + fi + # Run extra user provided pip install scripts + if [ -f "${EXTRA_PYTHON_MODULES_SCRIPT:-}" ]; then + "${NATRON_PYTHON}"" "$EXTRA_PYTHON_MODULES_SCRIPT" || true + fi fi diff --git a/tools/jenkins/build-Windows-installer.sh b/tools/jenkins/build-Windows-installer.sh index 0032a33b18..792633d306 100755 --- a/tools/jenkins/build-Windows-installer.sh +++ b/tools/jenkins/build-Windows-installer.sh @@ -428,23 +428,29 @@ export PY_BIN="$SDK_HOME/bin/python.exe" export PYDIR="$PYDIR" . "$CWD"/zip-python.sh +NATRON_PYTHON="${TMP_PORTABLE_DIR}/bin/natron-python" # Install pip -if [ -x "${TMP_PORTABLE_DIR}"/bin/natron-python ]; then +if [ -x "${NATRON_PYTHON}" ]; then if [ "$PYV" = "2" ]; then $CURL --remote-name --insecure https://bootstrap.pypa.io/pip/${PYVER}/get-pip.py else $CURL --remote-name --insecure https://bootstrap.pypa.io/get-pip.py fi - "${TMP_PORTABLE_DIR}"/bin/natron-python get-pip.py + "${NATRON_PYTHON}" get-pip.py rm get-pip.py + # Install qtpy + if [ "${USE_QT5:-}" != 1 ]; then + # Qt4 support was dropped after QtPy 1.11.2 + "${NATRON_PYTHON}" -m pip install qtpy==1.11.2 + else + "${NATRON_PYTHON}"" -m pip install qtpy + fi + # Run extra user provided pip install scripts + if [ -f "${EXTRA_PYTHON_MODULES_SCRIPT:-}" ]; then + "${NATRON_PYTHON}"" "$EXTRA_PYTHON_MODULES_SCRIPT" || true + fi fi -# 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 -fi - - # Copy Python distrib to installer package cp -r "$PYDIR" "$DLLS_PACKAGE_PATH/data/lib/"