Remove Qt 6.0 support

Simplify some PyQt6 code branches
This commit is contained in:
Ogi Moore 2021-06-05 18:22:10 -07:00
parent d455da9aec
commit 195a1a6fa3
8 changed files with 17 additions and 100 deletions

View File

@ -29,12 +29,12 @@ This project supports:
* All minor versions of Python released 42 months prior to the project, and at minimum the two latest minor versions.
* All minor versions of numpy released in the 24 months prior to the project, and at minimum the last three minor versions.
* All minor versions of Qt 5 and Qt 6 currently supported by upstream Qt
* All Qt5 versions from 5.12-5.15, and Qt6 6.1
Currently this means:
* Python 3.7+
* Qt 5.12-6.0
* Qt 5.12-5.15, 6.1
* Required
* PyQt5, PyQt6, PySide2 or PySide6
* `numpy` 1.17+
@ -58,8 +58,8 @@ The following table represents the python environments we test in our CI system.
| PyQt5-5.12 | :white_check_mark: | | :x: |
| PySide2-5.15 | | :white_check_mark: | |
| PyQt5-5.15 | | :white_check_mark: | |
| PySide6-6.0 | | | :white_check_mark: |
| PyQt6-6.0 | | | :white_check_mark: |
| PySide6-6.1 | | | :white_check_mark: |
| PyQt6-6.1 | | | :white_check_mark: |
* :x: - Not compatible
* :white_check_mark: - Tested

View File

@ -316,53 +316,12 @@ if QT_LIB in [PYQT5, PYQT6]:
loadUiType = uic.loadUiType
QtCore.Signal = QtCore.pyqtSignal
if QT_LIB == PYSIDE6:
# PySide6 6.0 has a missing binding
if not hasattr(QtGui.QGradient, 'setStops'):
def __setStops(self, stops):
for pos, color in stops:
self.setColorAt(pos, color)
QtGui.QGradient.setStops = __setStops
if QT_LIB == PYQT6:
# shim the old names for QPointF mouse coords
QtGui.QSinglePointEvent.localPos = lambda o : o.position()
QtGui.QSinglePointEvent.windowPos = lambda o : o.scenePosition()
QtGui.QSinglePointEvent.screenPos = lambda o : o.globalPosition()
QtWidgets.QApplication.exec_ = QtWidgets.QApplication.exec
# PyQt6 6.0.0 has a bug where it can't handle certain Type values returned
# by the Qt library.
if QtCore.PYQT_VERSION == 0x60000:
def new_method(self, old_method=QtCore.QEvent.type):
try:
typ = old_method(self)
except ValueError:
typ = QtCore.QEvent.Type.None_
return typ
QtCore.QEvent.type = new_method
del new_method
# PyQt6 6.1 renames some enums and flags to be in line with the other bindings.
# "Alignment" and "Orientations" are PyQt6 6.0 and are used in the generated
# ui files. Pending a regeneration of the template files, which would mean a
# drop in support for PyQt6 6.0, provide the old names for PyQt6 6.1.
# This is strictly a temporary private shim. Do not depend on it in your code.
if hasattr(QtCore.Qt, 'AlignmentFlag') and not hasattr(QtCore.Qt, 'Alignment'):
QtCore.Qt.Alignment = QtCore.Qt.AlignmentFlag
if hasattr(QtCore.Qt, 'Orientation') and not hasattr(QtCore.Qt, 'Orientations'):
QtCore.Qt.Orientations = QtCore.Qt.Orientation
# USE_XXX variables are deprecated
USE_PYSIDE = QT_LIB == PYSIDE
USE_PYQT4 = QT_LIB == PYQT4
USE_PYQT5 = QT_LIB == PYQT5
## Make sure we have Qt >= 5.12
versionReq = [5, 12]
m = re.match(r'(\d+)\.(\d+).*', QtVersion)

View File

@ -1559,15 +1559,9 @@ def ndarray_to_qimage(arr, fmt):
# will trigger the COW mechanism, i.e. a copy is made under the hood.
if QT_LIB.startswith('PyQt'):
if QtCore.PYQT_VERSION == 0x60000:
# PyQt5 -> const
# PyQt6 >= 6.0.1 -> const
# PyQt6 == 6.0.0 -> non-const
img_ptr = Qt.sip.voidptr(arr)
else:
# PyQt5 -> non-const
# PyQt6 >= 6.0.1 -> non-const
img_ptr = int(Qt.sip.voidptr(arr)) # or arr.ctypes.data
# PyQt5 -> non-const
# PyQt6 >= 6.0.1 -> non-const
img_ptr = int(Qt.sip.voidptr(arr)) # or arr.ctypes.data
else:
# bindings that support ndarray
# PyQt5 -> const

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from ..Qt import QtGui, QtCore, QT_LIB
from ..Qt import QtGui, QtCore
from ..python2_3 import asUnicode
import numpy as np
from ..Point import Point
@ -1130,14 +1130,7 @@ class AxisItem(GraphicsWidget):
alignFlags = QtCore.Qt.AlignmentFlag.AlignHCenter|QtCore.Qt.AlignmentFlag.AlignTop
rect = QtCore.QRectF(x-width/2., tickStop+offset, width, height)
if QT_LIB == 'PyQt6':
# PyQt6 doesn't allow or-ing of different enum types
# so we need to take its value property
textFlags = alignFlags.value | QtCore.Qt.TextFlag.TextDontClip.value
else:
# for PyQt5, the following expression is not commutative!
textFlags = alignFlags | QtCore.Qt.TextFlag.TextDontClip
textFlags = alignFlags | QtCore.Qt.TextFlag.TextDontClip
#p.setPen(self.pen())
#p.drawText(rect, textFlags, vstr)
textSpecs.append((rect, textFlags, vstr))

View File

@ -842,13 +842,7 @@ class ROI(GraphicsObject):
## called by Handles when they are moved.
## pos is the new position of the handle in scene coords, as requested by the handle.
if modifiers is None:
try:
# this works for PyQt6 6.1 and other bindings
modifiers = QtCore.Qt.KeyboardModifier.NoModifier
except AttributeError:
# this works for PyQt6 6.0 and other bindings
modifiers = QtCore.Qt.KeyboardModifiers(0)
modifiers = QtCore.Qt.KeyboardModifier.NoModifier
newState = self.stateCopy()
index = self.indexOfHandle(handle)
h = self.handles[index]
@ -1486,12 +1480,7 @@ class Handle(UIGraphicsItem):
def movePoint(self, pos, modifiers=None, finish=True):
if modifiers is None:
try:
# this works for PyQt6 6.1 and other bindings
modifiers = QtCore.Qt.KeyboardModifier.NoModifier
except AttributeError:
# this works for PyQt6 6.0 and other bindings
modifiers = QtCore.Qt.KeyboardModifiers(0)
modifiers = QtCore.Qt.KeyboardModifier.NoModifier
for r in self.rois:
if not r.checkPointMove(self, pos, modifiers):
return

View File

@ -1,4 +1,4 @@
from ..Qt import QtGui, QtCore, QT_LIB
from ..Qt import QtGui, QtCore
from ..python2_3 import asUnicode
import os, weakref, re
@ -162,13 +162,7 @@ class ParameterItem(QtGui.QTreeWidgetItem):
# called when the user-visble title has changed (either opts['title'], or name if title is None)
self.setText(0, self.param.title())
fm = QtGui.QFontMetrics(self.font(0))
if QT_LIB == 'PyQt6':
# PyQt6 doesn't allow or-ing of different enum types
# so we need to take its value property
textFlags = QtCore.Qt.TextFlag.TextSingleLine.value
else:
textFlags = QtCore.Qt.TextFlag.TextSingleLine
textFlags = QtCore.Qt.TextFlag.TextSingleLine
size = fm.size(textFlags, self.text(0))
size.setHeight(int(size.height() * 1.35))
size.setWidth(int(size.width() * 1.15))

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from ..Qt import QtGui, QtCore, QtWidgets, QT_LIB
from ..Qt import QtGui, QtCore, QtWidgets
from .GraphicsView import GraphicsView
from ..graphicsItems.GradientEditorItem import GradientEditorItem
import weakref
@ -40,16 +40,7 @@ class GradientWidget(GraphicsView):
self.setOrientation(orientation)
self.setCacheMode(self.CacheModeFlag.CacheNone)
self.setRenderHints(QtGui.QPainter.RenderHint.Antialiasing | QtGui.QPainter.RenderHint.TextAntialiasing)
if QT_LIB == 'PyQt6':
# PyQt6 doesn't allow or-ing of different enum types
# so we need to take its value property
NoFrame = QtWidgets.QFrame.Shape.NoFrame.value
Plain = QtWidgets.QFrame.Shadow.Plain.value
else:
NoFrame = QtWidgets.QFrame.Shape.NoFrame
Plain = QtWidgets.QFrame.Shadow.Plain
frame_style = NoFrame | Plain
frame_style = QtWidgets.QFrame.Shape.NoFrame | QtWidgets.QFrame.Shadow.Plain
self.setFrameStyle(frame_style)
#self.setBackgroundRole(QtGui.QPalette.ColorRole.NoRole)

View File

@ -236,11 +236,8 @@ class Renderer(GraphicsView):
# see functions.py::makeQImage() for rationale
if QT_LIB.startswith('PyQt'):
if QtCore.PYQT_VERSION == 0x60000:
img_ptr = sip.voidptr(self.shm)
else:
# PyQt5, PyQt6 >= 6.0.1
img_ptr = int(sip.voidptr(self.shm))
# PyQt5, PyQt6 >= 6.0.1
img_ptr = int(sip.voidptr(self.shm))
else:
# PySide2, PySide6
img_ptr = self.shm