Skip to content

Commit

Permalink
Add basic support for PySide6
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed May 17, 2024
1 parent ffd6e95 commit 284d817
Show file tree
Hide file tree
Showing 33 changed files with 186 additions and 37 deletions.
31 changes: 16 additions & 15 deletions .github/workflows/test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
test-env: "PyQt5~=5.9.2"
qt-api: "PyQt5"

- os: ubuntu-18.04
- os: ubuntu-20.04
python-version: 3.7
test-env: "PyQt5~=5.12.0"
qt-api: "PyQt5"
Expand Down Expand Up @@ -52,20 +52,13 @@ jobs:
test-env: "PySide2~=5.15.0"
qt-api: "PySide2"

# macOS
- os: macos-10.15
python-version: 3.6
test-env: "PyQt5~=5.9.2"

- os: macos-10.15
python-version: 3.7
test-env: "PyQt5~=5.12.0"

- os: macos-10.15
python-version: 3.8
test-env: "PyQt5~=5.14.0"
- os: ubuntu-20.04
python-version: "3.12"
test-env: "PySide6~=6.6.0"
qt-api: "PySide6"

- os: macos-10.15
# macOS
- os: macos-11
python-version: 3.9
test-env: "PyQt5~=5.15.0"

Expand All @@ -81,6 +74,10 @@ jobs:
python-version: "3.10"
test-env: "PySide2~=5.15.0"

- os: macos-11
python-version: "3.12"
test-env: "PySide6~=6.6.0"

# Windows
- os: windows-2019
python-version: 3.6
Expand Down Expand Up @@ -110,6 +107,10 @@ jobs:
python-version: "3.10"
test-env: "PySide2~=5.15.0"

- os: windows-2019
python-version: "3.12"
test-env: "PySide6~=6.6.0"

steps:
- uses: actions/checkout@v2
- name: Setup Python
Expand All @@ -120,7 +121,7 @@ jobs:
- name: Install System Deps
if: ${{ startsWith(runner.os, 'Linux') }}
# https://www.riverbankcomputing.com/pipermail/pyqt/2020-June/042949.html
run: sudo apt-get install -y libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 libegl1-mesa libxcb-shape0
run: sudo apt-get install -y libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 libegl1-mesa libxcb-shape0 libxcb-cursor0

- name: Setup Pip Cache
uses: actions/cache@v2
Expand Down
20 changes: 15 additions & 5 deletions AnyQt/QtCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,13 @@
QT_VERSION = (_major << 16) + (_minor << 8) + _micro
QT_VERSION_STR = "{}.{}.{}".format(_major, _minor, _micro)
BoundSignal = Signal
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtCore import *
_major, _minor, _micro = tuple(map(int, qVersion().split(".")[:3]))
QT_VERSION = (_major << 16) + (_minor << 8) + _micro
QT_VERSION_STR = "{}.{}.{}".format(_major, _minor, _micro)
BoundSignal = Signal
PYQT_VERSION = 0x60000

# Missing in PyQt4 <= 4.11.3
if not hasattr(QEvent, "MacSizeChange"):
Expand Down Expand Up @@ -423,11 +430,14 @@ def value(self, key, defaultValue=None, type=None):
pyqtSlot = Slot
pyqtProperty = Property

if _api.USED_API == _api.QT_API_PYSIDE2:
try:
from PySide2 import shiboken2 as __shiboken2
except ImportError:
import shiboken2 as __shiboken2
if _api.USED_API in (_api.QT_API_PYSIDE2, _api.QT_API_PYSIDE6):
if _api.USED_API == _api.QT_API_PYSIDE2:
try:
from PySide2 import shiboken2 as __shiboken2
except ImportError:
import shiboken2 as __shiboken2
else:
import shiboken6 as __shiboken2

def cast(obj, type_):
addr = unwrapinstance(obj)
Expand Down
7 changes: 7 additions & 0 deletions AnyQt/QtDBus.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@
from PyQt4.QtDBus import *
elif _api.USED_API == _api.QT_API_PYSIDE:
from PySide.QtDBus import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtDBus import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtDBus import *
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

_api.apply_global_fixes(globals())
7 changes: 7 additions & 0 deletions AnyQt/QtDesigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@
from PyQt4.QtDesigner import *
elif _api.USED_API == _api.QT_API_PYSIDE:
from PySide.QtDesigner import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtDesigner import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtDesigner import *
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

_api.apply_global_fixes(globals())
10 changes: 8 additions & 2 deletions AnyQt/QtGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ def __init__(self, *args):
from PySide2.QtGui import *
from PySide2.QtWidgets import QUndoCommand, QUndoStack, QUndoGroup
from PySide2.QtWidgets import QShortcut, QAction, QActionGroup
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtGui import *


if _api.USED_API in [_api.QT_API_PYQT4, _api.QT_API_PYSIDE]:
from AnyQt import QtCore as __QtCore
Expand Down Expand Up @@ -296,8 +299,11 @@ def __QWheelEvent_pixelDelta(self):
QWheelEvent.angleDelta = __QWheelEvent_angleDelta
QWheelEvent.pixelDelta = __QWheelEvent_pixelDelta

if _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtCore import QRectF as __QRectF
if _api.USED_API in (_api.QT_API_PYSIDE2, _api.QT_API_PYSIDE6):
if _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtCore import QRectF as __QRectF
else:
from PySide6.QtCore import QRectF as __QRectF
_QPainter_drawPixmapFragments_orig = QPainter.drawPixmapFragments
class __ArgsTypeError(TypeError): pass

Expand Down
5 changes: 5 additions & 0 deletions AnyQt/QtHelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
from PySide.QtHelp import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtHelp import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtHelp import *
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

_api.apply_global_fixes(globals())
7 changes: 7 additions & 0 deletions AnyQt/QtMacExtras.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@
from PyQt4.QtGui import QMacPasteboardMime
elif _api.USED_API == _api.QT_API_PYSIDE:
from PySide.QtGui import QMacPasteboardMime
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtMacExtras import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtMacExtras import *
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

_api.apply_global_fixes(globals())
5 changes: 5 additions & 0 deletions AnyQt/QtMultimedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
from PySide.QtMultimedia import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtMultimedia import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtMultimedia import *
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

_api.apply_global_fixes(globals())
7 changes: 4 additions & 3 deletions AnyQt/QtMultimediaWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from PyQt5.QtMultimediaWidgets import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtMultimediaWidgets import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtMultimediaWidgets import *
else:
raise ImportError("No module named 'QtMultimediaWidgets' in the selected"
"Qt api ({})".format(_api.USED_API))

raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")
_api.apply_global_fixes(globals())
5 changes: 5 additions & 0 deletions AnyQt/QtNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,10 @@
from PySide.QtNetwork import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtNetwork import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtNetwork import *
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

_api.apply_global_fixes(globals())
6 changes: 5 additions & 1 deletion AnyQt/QtOpenGL.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
from PySide.QtOpenGL import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtOpenGL import *

elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtOpenGL import *
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")
_api.apply_global_fixes(globals())
5 changes: 5 additions & 0 deletions AnyQt/QtPrintSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@
)
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtPrintSupport import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtPrintSupport import *
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

_api.apply_global_fixes(globals())
7 changes: 4 additions & 3 deletions AnyQt/QtQml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from PyQt5.QtQml import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtQml import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtQml import *
else:
raise ImportError("No module named 'QtQml' in the selected "
"Qt api ({})".format(_api.USED_API))

raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")
_api.apply_global_fixes(globals())
6 changes: 4 additions & 2 deletions AnyQt/QtQuick.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
from PyQt5.QtQuick import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtQuick import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtQuick import *
else:
raise ImportError("No module named 'QtQuick' in the selected "
"Qt api ({})".format(_api.USED_API))
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

_api.apply_global_fixes(globals())
5 changes: 5 additions & 0 deletions AnyQt/QtSql.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
from PySide.QtSql import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtSql import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtSql import *
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

_api.apply_global_fixes(globals())
6 changes: 6 additions & 0 deletions AnyQt/QtSvg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@
from PySide.QtSvg import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtSvg import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtSvg import *
from PySide6.QtSvgWidgets import QSvgWidget, QGraphicsSvgItem
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

_api.apply_global_fixes(globals())
5 changes: 5 additions & 0 deletions AnyQt/QtSvgWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
from PySide.QtSvg import QSvgWidget, QGraphicsSvgItem
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtSvg import QSvgWidget, QGraphicsSvgItem
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtSvgWidgets import *
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

_api.apply_global_fixes(globals())
7 changes: 5 additions & 2 deletions AnyQt/QtTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from PySide.QtTest import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtTest import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtTest import *


def _QTest_qSleep(ms: int):
Expand Down Expand Up @@ -84,7 +86,8 @@ def _QTest_qWaitForWindowActive(widget, timeout=1000):
QTest.qWaitForWindowActive = _QTest_qWaitForWindowActive


if _api.USED_API in {_api.QT_API_PYQT4, _api.QT_API_PYSIDE, _api.QT_API_PYSIDE2}:
if _api.USED_API in {_api.QT_API_PYQT4, _api.QT_API_PYSIDE,
_api.QT_API_PYSIDE2, _api.QT_API_PYSIDE6}:
from AnyQt.QtCore import QObject, QByteArray as _QByteArray

# not exposed in PyQt4 or PySide. Going by PyQt5 interface
Expand Down Expand Up @@ -124,7 +127,7 @@ def wait(self, timeout=5000):
self.__timer.stop()
self.__timer.setInterval(timeout)
self.__timer.start()
self.__loop.exec_()
self.__loop.exec()
self.__timer.stop()
return len(self) != count

Expand Down
2 changes: 2 additions & 0 deletions AnyQt/QtWebChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from PyQt5.QtWebChannel import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtWebChannel import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtWebChannel import *
else:
raise ImportError("No module named 'QtWebChannel' in the selected "
"Qt api ({})".format(_api.USED_API))
Expand Down
18 changes: 16 additions & 2 deletions AnyQt/QtWebEngineCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,22 @@
)
except ImportError:
pass


elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtWebEngineCore import *
try:
from PySide2.QtWebEngineWidgets import (
QWebEngineHistory,
QWebEngineProfile,
QWebEngineScript,
QWebEngineScriptCollection,
# QWebEngineClientCertificateSelection,
QWebEngineSettings,
QWebEngineFullScreenRequest,
)
except ImportError:
pass
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtWebEngineCore import *
else:
raise ImportError("No module named 'QtWebEngineCore' in the selected "
"Qt api ({})".format(_api.USED_API))
Expand Down
11 changes: 11 additions & 0 deletions AnyQt/QtWebEngineWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
from PyQt5.QtWebEngineWidgets import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtWebEngineWidgets import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtWebEngineWidgets import *
from PySide6.QtWebEngineCore import (
QWebEngineHistory,
QWebEngineProfile,
QWebEngineScript,
QWebEngineScriptCollection,
# QWebEngineClientCertificateSelection,
QWebEngineSettings,
QWebEngineFullScreenRequest,
)
else:
raise ImportError("No module named 'QtWebEngineWidgets' in the selected "
"Qt api ({})".format(_api.USED_API))
Expand Down
2 changes: 2 additions & 0 deletions AnyQt/QtWebKit.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@
pass
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtWebKit import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtWebKit import *
4 changes: 4 additions & 0 deletions AnyQt/QtWebKitWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@
QWebPage,
QWebView,
)
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtWebKitWidgets import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtWebKitWidgets import *

_api.apply_global_fixes(globals())
2 changes: 2 additions & 0 deletions AnyQt/QtWebSockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from PyQt5.QtWebSockets import *
elif _api.USED_API == _api.QT_API_PYSIDE2:
from PySide2.QtWebSockets import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtWebSockets import *
else:
raise ImportError("No module named 'QtWebSockets' in the selected "
"Qt api ({})".format(_api.USED_API))
Expand Down
Loading

0 comments on commit 284d817

Please sign in to comment.