Skip to content

Commit

Permalink
Merge pull request #225 from jschueller/qt6
Browse files Browse the repository at this point in the history
PR: Add support for PySide6
  • Loading branch information
dalthviz authored Oct 12, 2021
2 parents da3bd76 + 3175a4a commit 2f2a25a
Show file tree
Hide file tree
Showing 34 changed files with 289 additions and 68 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ jobs:
- name: Install System Packages
run: |
sudo apt update
sudo apt install libpulse-dev
sudo apt install libegl1-mesa
sudo apt install libpulse-dev libegl1-mesa libopengl0
- name: Install Conda
uses: conda-incubator/setup-miniconda@v2
with:
Expand All @@ -44,6 +43,9 @@ jobs:
- name: Test PySide2
shell: bash -l {0}
run: xvfb-run --auto-servernum bash -l ./.github/workflows/test-pyside2.sh
- name: Test PySide6
shell: bash -l {0}
run: xvfb-run --auto-servernum bash -l ./.github/workflows/test-pyside6.sh
- name: Upload coverage
if: matrix.PYTHON_VERSION == '3.8'
shell: bash -l {0}
Expand Down Expand Up @@ -79,6 +81,9 @@ jobs:
- name: Test PySide2
shell: bash -l {0}
run: bash -l ./.github/workflows/test-pyside2.sh
- name: Test PySide6
shell: bash -l {0}
run: bash -l ./.github/workflows/test-pyside6.sh

windows:
name: Windows Py${{ matrix.PYTHON_VERSION }} conda=${{ matrix.USE_CONDA }}
Expand Down Expand Up @@ -107,3 +112,6 @@ jobs:
- name: Test PySide2
shell: bash -l {0}
run: bash -l ./.github/workflows/test-pyside2.sh
- name: Test PySide6
shell: bash -l {0}
run: bash -l ./.github/workflows/test-pyside6.sh
23 changes: 23 additions & 0 deletions .github/workflows/test-pyside6.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash -ex

# Create conda environment for this test
conda create -n test-pyside6
conda activate test-pyside6

if [ "$USE_CONDA" = "Yes" ]; then
# There are no conda packages for PySide6
exit 0
elif [ "$PYTHON_VERSION" == "2.7" ]; then
# There is no wheel for PySide6 on Python 2.7
exit 0
else
# Simple solution to avoid failures with the Qt3D modules
conda install coveralls mock pytest pytest-cov python="$PYTHON_VERSION" -c conda-forge -q
pip install -q pyside6==6.2.0
fi

# Install package
python -m pip install -e .

# Run tests
python qtpy/tests/runtests.py
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
**QtPy** is a small abstraction layer that lets you
write applications using a single API call to either PyQt or PySide.

It provides support for PyQt5, PyQt4, PySide2 and PySide using the Qt5 layout
It provides support for PyQt5, PyQt4, PySide6, PySide2 and PySide using the Qt5 layout
(where the QtGui module has been split into QtGui and QtWidgets).

Basically, you can write your code as if you were using PySide2
Expand Down Expand Up @@ -53,6 +53,7 @@ default unless you set the `QT_API` environment variable.

* `pyqt5` (to use PyQt5).
* `pyqt` or `pyqt4` (to use PyQt4).
* `pyside6` (to use PySide6)
* `pyside2` (to use PySide2)
* `pyside` (to use PySide).

Expand Down
21 changes: 19 additions & 2 deletions qtpy/QtCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
Provides QtCore classes and functions.
"""

from . import PYQT5, PYSIDE2, PYQT4, PYSIDE, PythonQtError
from . import PYQT6, PYQT5, PYSIDE2, PYSIDE6, PYQT4, PYSIDE, PythonQtError

if PYQT6:
from PyQt6.QtCore import *
from PyQt6.QtCore import pyqtSignal as Signal
from PyQt6.QtCore import QT_VERSION_STR as __version__

if PYQT5:
elif PYQT5:
from PyQt5.QtCore import *
from PyQt5.QtCore import pyqtSignal as Signal
from PyQt5.QtCore import pyqtBoundSignal as SignalInstance
Expand All @@ -27,6 +31,19 @@

# Those are imported from `import *`
del pyqtSignal, pyqtBoundSignal, pyqtSlot, pyqtProperty, QT_VERSION_STR

elif PYSIDE6:
from PySide6.QtCore import *
import PySide6.QtCore
__version__ = PySide6.QtCore.__version__

# obsolete in qt6
Qt.BackgroundColorRole = Qt.BackgroundRole
Qt.TextColorRole = Qt.ForegroundRole
Qt.BackgroundColorRole = Qt.BackgroundRole
Qt.TextColorRole = Qt.ForegroundRole
Qt.MidButton = Qt.MiddleButton

elif PYSIDE2:
from PySide2.QtCore import *

Expand Down
8 changes: 6 additions & 2 deletions qtpy/QtDataVisualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
"""Provides QtDataVisualization classes and functions."""

# Local imports
from . import PYQT5, PYSIDE2, PythonQtError
from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError

if PYQT5:
if PYQT6:
from PyQt6.QtDataVisualization import *
elif PYQT5:
from PyQt5.QtDataVisualization import *
elif PYSIDE6:
from PySide6.QtDataVisualization import *
elif PYSIDE2:
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026
import PySide2.QtDataVisualization as __temp
Expand Down
10 changes: 8 additions & 2 deletions qtpy/QtGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
"""
import warnings

from . import PYQT5, PYQT4, PYSIDE, PYSIDE2, PythonQtError
from . import PYQT6, PYQT5, PYQT4, PYSIDE, PYSIDE2, PYSIDE6, PythonQtError


if PYQT5:
if PYQT6:
from PyQt6.QtGui import *
elif PYQT5:
from PyQt5.QtGui import *
elif PYSIDE2:
from PySide2.QtGui import *
elif PYSIDE6:
from PySide6.QtGui import *
QFontMetrics.width = QFontMetrics.horizontalAdvance

elif PYQT4:
try:
# Older versions of PyQt4 do not provide these
Expand Down
7 changes: 3 additions & 4 deletions qtpy/QtHelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@

import warnings

from . import PYQT5
from . import PYQT4
from . import PYSIDE
from . import PYSIDE2
from . import PYQT5, PYQT4, PYSIDE6, PYSIDE2, PYSIDE

if PYQT5:
from PyQt5.QtHelp import *
elif PYSIDE6:
from PySide6.QtHelp import *
elif PYSIDE2:
from PySide2.QtHelp import *
elif PYQT4:
Expand Down
3 changes: 3 additions & 0 deletions qtpy/QtMultimedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
from . import PYQT4
from . import PYSIDE
from . import PYSIDE2
from . import PYSIDE6

if PYQT5:
from PyQt5.QtMultimedia import *
elif PYSIDE6:
from PySide6.QtMultimedia import *
elif PYSIDE2:
from PySide2.QtMultimedia import *
elif PYQT4:
Expand Down
4 changes: 3 additions & 1 deletion qtpy/QtNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
Provides QtNetwork classes and functions.
"""

from . import PYQT5, PYSIDE2, PYQT4, PYSIDE, PythonQtError
from . import PYQT5, PYSIDE2, PYSIDE6, PYQT4, PYSIDE, PythonQtError


if PYQT5:
from PyQt5.QtNetwork import *
elif PYSIDE6:
from PySide6.QtNetwork import *
elif PYSIDE2:
from PySide2.QtNetwork import *
elif PYQT4:
Expand Down
2 changes: 2 additions & 0 deletions qtpy/QtOpenGL.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

if PYQT5:
from PyQt5.QtOpenGL import *
elif PYSIDE6:
from PySide6.QtOpenGL import *
elif PYSIDE2:
from PySide2.QtOpenGL import *
elif PYQT4:
Expand Down
4 changes: 3 additions & 1 deletion qtpy/QtPrintSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
Provides QtPrintSupport classes and functions.
"""

from . import PYQT5, PYQT4,PYSIDE2, PYSIDE, PythonQtError
from . import PYQT5, PYQT4, PYSIDE6, PYSIDE2, PYSIDE, PythonQtError


if PYQT5:
from PyQt5.QtPrintSupport import *
elif PYSIDE6:
from PySide6.QtPrintSupport import *
elif PYSIDE2:
from PySide2.QtPrintSupport import *
elif PYQT4:
Expand Down
4 changes: 3 additions & 1 deletion qtpy/QtQml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"""Provides QtQml classes and functions."""

# Local imports
from . import PYQT5, PYSIDE2, PythonQtError
from . import PYQT5, PYSIDE2, PYSIDE6, PythonQtError

if PYQT5:
from PyQt5.QtQml import *
elif PYSIDE6:
from PySide6.QtQml import *
elif PYSIDE2:
from PySide2.QtQml import *
else:
Expand Down
4 changes: 3 additions & 1 deletion qtpy/QtQuick.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"""Provides QtQuick classes and functions."""

# Local imports
from . import PYQT5, PYSIDE2, PythonQtError
from . import PYQT5, PYSIDE6, PYSIDE2, PythonQtError

if PYQT5:
from PyQt5.QtQuick import *
elif PYSIDE6:
from PySide6.QtQuick import *
elif PYSIDE2:
from PySide2.QtQuick import *
else:
Expand Down
4 changes: 3 additions & 1 deletion qtpy/QtQuickWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"""Provides QtQuickWidgets classes and functions."""

# Local imports
from . import PYQT5, PYSIDE2, PythonQtError
from . import PYQT5, PYSIDE6, PYSIDE2, PythonQtError

if PYQT5:
from PyQt5.QtQuickWidgets import *
elif PYSIDE6:
from PySide6.QtQuickWidgets import *
elif PYSIDE2:
from PySide2.QtQuickWidgets import *
else:
Expand Down
4 changes: 3 additions & 1 deletion qtpy/QtSql.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"""Provides QtSql classes and functions."""

# Local imports
from . import PYQT5, PYSIDE2, PYQT4, PYSIDE, PythonQtError
from . import PYQT5, PYSIDE6, PYSIDE2, PYQT4, PYSIDE, PythonQtError

if PYQT5:
from PyQt5.QtSql import *
elif PYSIDE6:
from PySide6.QtSql import *
elif PYSIDE2:
from PySide2.QtSql import *
elif PYQT4:
Expand Down
8 changes: 6 additions & 2 deletions qtpy/QtSvg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
"""Provides QtSvg classes and functions."""

# Local imports
from . import PYQT4, PYSIDE2, PYQT5, PYSIDE, PythonQtError
from . import PYQT4, PYSIDE6, PYSIDE2, PYQT5, PYQT6, PYSIDE, PythonQtError

if PYQT5:
if PYQT6:
from PyQt6.QtSvg import *
elif PYQT5:
from PyQt5.QtSvg import *
elif PYSIDE6:
from PySide6.QtSvg import *
elif PYSIDE2:
from PySide2.QtSvg import *
elif PYQT4:
Expand Down
9 changes: 6 additions & 3 deletions qtpy/QtTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
Provides QtTest and functions
"""

from . import PYQT5,PYSIDE2, PYQT4, PYSIDE, PythonQtError
from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, PYQT4, PYSIDE, PythonQtError


if PYQT5:
if PYQT6:
from PyQt6.QtTest import QTest
elif PYQT5:
from PyQt5.QtTest import QTest
elif PYSIDE6:
from PySide6.QtTest import QTest
elif PYSIDE2:
from PySide2.QtTest import QTest
elif PYQT4:
Expand Down
4 changes: 3 additions & 1 deletion qtpy/QtWebChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"""Provides QtWebChannel classes and functions."""

# Local imports
from . import PYSIDE2, PYQT5, PythonQtError
from . import PYSIDE2, PYSIDE6, PYQT5, PythonQtError

if PYQT5:
from PyQt5.QtWebChannel import *
elif PYSIDE6:
from PySide6.QtWebChannel import *
elif PYSIDE2:
from PySide2.QtWebChannel import *
else:
Expand Down
20 changes: 20 additions & 0 deletions qtpy/QtWebEngine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2014-2015 Colin Duquesnoy
# Copyright © 2009- The Spyder development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)

"""
Provides QtWebEngine classes and functions.
"""

from . import PYQT5, PYSIDE6

if PYQT5:
from PyQt5.QtWebEngine import *
elif PYSIDE6:
from PySide6.QtWebEngine import *
else:
raise PythonQtError('No Qt bindings could be found')
7 changes: 6 additions & 1 deletion qtpy/QtWebEngineWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Provides QtWebEngineWidgets classes and functions.
"""

from . import PYQT5,PYSIDE2, PYQT4, PYSIDE, PythonQtError
from . import PYQT5,PYSIDE2, PYSIDE6, PYQT4, PYSIDE, PythonQtError


# To test if we are using WebEngine or WebKit
Expand All @@ -29,6 +29,11 @@
from PyQt5.QtWebKitWidgets import QWebView as QWebEngineView
from PyQt5.QtWebKit import QWebSettings as QWebEngineSettings
WEBENGINE = False
elif PYSIDE6:
from PySide6.QtWebEngineWidgets import *
from PySide6.QtWebEngineCore import QWebEnginePage
from PySide6.QtWebEngineCore import QWebEngineSettings
from PySide6.QtWebEngineCore import QWebEngineProfile
elif PYSIDE2:
from PySide2.QtWebEngineWidgets import QWebEnginePage
from PySide2.QtWebEngineWidgets import QWebEngineView
Expand Down
16 changes: 13 additions & 3 deletions qtpy/QtWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@
were the ``PyQt5.QtWidgets`` module.
"""

from . import PYQT5, PYSIDE2, PYQT4, PYSIDE, PythonQtError
from . import PYQT5, PYQT6, PYSIDE2, PYQT4, PYSIDE, PYSIDE6, PythonQtError
from ._patch.qcombobox import patch_qcombobox
from ._patch.qheaderview import introduce_renamed_methods_qheaderview


if PYQT5:
if PYQT6:
from PyQt6.QtWidgets import *
from PyQt6.QtGui import QAction, QActionGroup
elif PYQT5:
from PyQt5.QtWidgets import *
elif PYSIDE6:
from PySide6.QtWidgets import *
from PySide6.QtGui import QAction, QActionGroup
from PySide6.QtOpenGLWidgets import QOpenGLWidget
QTextEdit.setTabStopWidth = QTextEdit.setTabStopDistance
QTextEdit.tabStopWidth = QTextEdit.tabStopDistance
QPlainTextEdit.setTabStopWidth = QPlainTextEdit.setTabStopDistance
QPlainTextEdit.tabStopWidth = QPlainTextEdit.tabStopDistance
elif PYSIDE2:
from PySide2.QtWidgets import *
elif PYQT4:
Expand Down
Loading

0 comments on commit 2f2a25a

Please sign in to comment.