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 24, 2024
1 parent ea084e7 commit f541b9f
Show file tree
Hide file tree
Showing 41 changed files with 212 additions and 22 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ jobs:
qt-api: "PyQt6"
extra-system-packages: "glibc-tools"

- os: ubuntu-22.04
python-version: "3.12"
test-env: "PySide6~=6.6.0"
qt-api: "PySide6"
extra-system-packages: "glibc-tools"

# macOS
- os: macos-11
python-version: 3.7
Expand Down Expand Up @@ -101,6 +107,10 @@ jobs:
python-version: "3.12"
test-env: "PyQt6~=6.6.0 PyQt6-Qt6~=6.6.0"

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

# Windows
- os: windows-2019
python-version: 3.7
Expand Down Expand Up @@ -138,6 +148,10 @@ jobs:
python-version: "3.12"
test-env: "PyQt6~=6.6.0 PyQt6-Qt6~=6.6.0"

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

steps:
- uses: actions/checkout@v4
- name: Setup Python
Expand Down
3 changes: 3 additions & 0 deletions AnyQt/QtCharts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
from PySide2.QtCharts import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtCharts import *
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

_api.apply_global_fixes(globals())
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())
3 changes: 3 additions & 0 deletions AnyQt/QtDataVisualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
from PySide2.QtDataVisualization import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtDataVisualization 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())
3 changes: 3 additions & 0 deletions AnyQt/QtLocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
from PySide2.QtLocation import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtLocation 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())
3 changes: 3 additions & 0 deletions AnyQt/QtNetworkAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
from PySide2.QtNetworkAuth import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtNetworkAuth 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())
3 changes: 3 additions & 0 deletions AnyQt/QtPdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
from PySide2.QtPdf import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtPdf import *
else:
raise ImportError(f"No module named '{__name__}' in the selected "
f"Qt api ({_api.USED_API})")

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

_api.apply_global_fixes(globals())
3 changes: 3 additions & 0 deletions AnyQt/QtPositioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
from PySide2.QtPositioning import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtPositioning 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())
3 changes: 3 additions & 0 deletions AnyQt/QtRemoteObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
from PySide2.QtRemoteObjects import *
elif _api.USED_API == _api.QT_API_PYSIDE6:
from PySide6.QtRemoteObjects 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/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
Loading

0 comments on commit f541b9f

Please sign in to comment.