Skip to content

Commit

Permalink
use qtpy rather than pyside
Browse files Browse the repository at this point in the history
it will ease the transition to Qt5/PySide2
Suddegested by #256 (comment)
  • Loading branch information
devernay committed Jun 19, 2021
1 parent 4b62360 commit b700f56
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
5 changes: 2 additions & 3 deletions Documentation/source/devel/initGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
30 changes: 14 additions & 16 deletions Engine/AppManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions INSTALL_LINUX.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions tools/jenkins/build-Linux-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tools/jenkins/build-OSX-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tools/jenkins/build-Windows-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b700f56

Please sign in to comment.