Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf0b1c6

Browse files
authored
Merge pull request #24710 from anntzer/qt510
Drop support for Qt<5.10.
2 parents 3067dad + 3effb11 commit bf0b1c6

File tree

6 files changed

+30
-53
lines changed

6 files changed

+30
-53
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Support for Qt<5.10 has been dropped
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... as there are no wheels or conda packages that support both Qt 5.9 (or
4+
older) and Python 3.8 (or newer).

doc/devel/min_dep_policy.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ Ghostscript, FFmpeg) support as old as practical. These can be difficult to
7171
install for end-users and we want to be usable on as many systems as
7272
possible. We will bump these on a case-by-case basis.
7373

74+
In the case of GUI frameworks for which we rely on Python bindings being
75+
available, we will also drop support for bindings so old that they don't
76+
support any Python version that we support.
77+
7478
.. _list-of-dependency-min-versions:
7579

7680
List of dependency versions

lib/matplotlib/backends/backend_qt.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
from . import qt_compat
1515
from .qt_compat import (
1616
QtCore, QtGui, QtWidgets, __version__, QT_API,
17-
_enum, _to_int,
18-
_devicePixelRatioF, _isdeleted, _setDevicePixelRatio,
19-
_maybe_allow_interrupt
17+
_enum, _to_int, _isdeleted, _maybe_allow_interrupt
2018
)
2119

2220

@@ -220,7 +218,8 @@ def __init__(self, figure=None):
220218
self.setPalette(palette)
221219

222220
def _update_pixel_ratio(self):
223-
if self._set_device_pixel_ratio(_devicePixelRatioF(self)):
221+
if self._set_device_pixel_ratio(
222+
self.devicePixelRatioF() or 1): # rarely, devicePixelRatioF=0
224223
# The easiest way to resize the canvas is to emit a resizeEvent
225224
# since we implement all the logic for resizing the canvas for
226225
# that event.
@@ -677,7 +676,8 @@ def _icon(self, name):
677676
filename = str(path_large if path_large.exists() else path_regular)
678677

679678
pm = QtGui.QPixmap(filename)
680-
_setDevicePixelRatio(pm, _devicePixelRatioF(self))
679+
pm.setDevicePixelRatio(
680+
self.devicePixelRatioF() or 1) # rarely, devicePixelRatioF=0
681681
if self.palette().color(self.backgroundRole()).value() < 128:
682682
icon_color = self.palette().color(self.foregroundRole())
683683
mask = pm.createMaskFromColor(

lib/matplotlib/backends/backend_qtagg.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
from matplotlib.transforms import Bbox
88

9-
from .qt_compat import QT_API, _enum, _setDevicePixelRatio
10-
from .. import cbook
9+
from .qt_compat import QT_API, _enum
1110
from .backend_agg import FigureCanvasAgg
1211
from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT
1312
from .backend_qt import ( # noqa: F401 # pylint: disable=W0611
@@ -50,22 +49,16 @@ def paintEvent(self, event):
5049
bbox = Bbox([[left, bottom], [right, top]])
5150
buf = memoryview(self.copy_from_bbox(bbox))
5251

53-
fmts = _enum("QtGui.QImage.Format")
54-
if hasattr(fmts, "Format_RGBA8888"):
55-
fmt = fmts.Format_RGBA8888
56-
else: # Qt<=5.1 support.
57-
fmt = fmts.Format_ARGB32_Premultiplied
58-
buf = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(buf)
59-
6052
if QT_API == "PyQt6":
6153
from PyQt6 import sip
6254
ptr = int(sip.voidptr(buf))
6355
else:
6456
ptr = buf
6557

6658
painter.eraseRect(rect) # clear the widget canvas
67-
qimage = QtGui.QImage(ptr, buf.shape[1], buf.shape[0], fmt)
68-
_setDevicePixelRatio(qimage, self.device_pixel_ratio)
59+
qimage = QtGui.QImage(ptr, buf.shape[1], buf.shape[0],
60+
_enum("QtGui.QImage.Format").Format_RGBA8888)
61+
qimage.setDevicePixelRatio(self.device_pixel_ratio)
6962
# set origin using original QT coordinates
7063
origin = QtCore.QPoint(rect.left(), rect.top())
7164
painter.drawImage(origin, qimage)

lib/matplotlib/backends/backend_qtcairo.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .backend_cairo import cairo, FigureCanvasCairo
44
from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT
5-
from .qt_compat import QT_API, _enum, _setDevicePixelRatio
5+
from .qt_compat import QT_API, _enum
66

77

88
class FigureCanvasQTCairo(FigureCanvasCairo, FigureCanvasQT):
@@ -31,10 +31,9 @@ def paintEvent(self, event):
3131
_enum("QtGui.QImage.Format").Format_ARGB32_Premultiplied)
3232
# Adjust the buf reference count to work around a memory leak bug in
3333
# QImage under PySide.
34-
if QT_API in ('PySide', 'PySide2'):
35-
if QtCore.__version_info__ < (5, 12):
36-
ctypes.c_long.from_address(id(buf)).value = 1
37-
_setDevicePixelRatio(qimage, self.device_pixel_ratio)
34+
if QT_API == "PySide2" and QtCore.__version_info__ < (5, 12):
35+
ctypes.c_long.from_address(id(buf)).value = 1
36+
qimage.setDevicePixelRatio(self.device_pixel_ratio)
3837
painter = QtGui.QPainter(self)
3938
painter.eraseRect(event.rect())
4039
painter.drawImage(0, 0, qimage)

lib/matplotlib/backends/qt_compat.py

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ def _isdeleted(obj):
125125
(_setup_pyqt5plus, QT_API_PYQT5),
126126
(_setup_pyqt5plus, QT_API_PYSIDE2),
127127
]
128-
129128
for _setup, QT_API in _candidates:
130129
try:
131130
_setup()
@@ -138,13 +137,21 @@ def _isdeleted(obj):
138137
.format(", ".join(_ETS.values())))
139138
else: # We should not get there.
140139
raise AssertionError(f"Unexpected QT_API: {QT_API}")
140+
_version_info = tuple(QtCore.QLibraryInfo.version().segments())
141+
142+
143+
if _version_info < (5, 10):
144+
raise ImportError(
145+
f"The Qt version imported is "
146+
f"{QtCore.QLibraryInfo.version().toString()} but Matplotlib requires "
147+
f"Qt>=5.10")
141148

142149

143150
# Fixes issues with Big Sur
144151
# https://bugreports.qt.io/browse/QTBUG-87014, fixed in qt 5.15.2
145152
if (sys.platform == 'darwin' and
146153
parse_version(platform.mac_ver()[0]) >= parse_version("10.16") and
147-
QtCore.QLibraryInfo.version().segments() <= [5, 15, 2]):
154+
_version_info < (5, 15, 2)):
148155
os.environ.setdefault("QT_MAC_WANTS_LAYER", "1")
149156

150157

@@ -167,36 +174,6 @@ def _exec(obj):
167174
obj.exec() if hasattr(obj, "exec") else obj.exec_()
168175

169176

170-
def _devicePixelRatioF(obj):
171-
"""
172-
Return obj.devicePixelRatioF() with graceful fallback for older Qt.
173-
174-
This can be replaced by the direct call when we require Qt>=5.6.
175-
"""
176-
try:
177-
# Not available on Qt<5.6
178-
return obj.devicePixelRatioF() or 1
179-
except AttributeError:
180-
pass
181-
try:
182-
# Not available on older Qt5.
183-
# self.devicePixelRatio() returns 0 in rare cases
184-
return obj.devicePixelRatio() or 1
185-
except AttributeError:
186-
return 1
187-
188-
189-
def _setDevicePixelRatio(obj, val):
190-
"""
191-
Call obj.setDevicePixelRatio(val) with graceful fallback for older Qt.
192-
193-
This can be replaced by the direct call when we require Qt>=5.6.
194-
"""
195-
if hasattr(obj, 'setDevicePixelRatio'):
196-
# Not available on older Qt5.
197-
obj.setDevicePixelRatio(val)
198-
199-
200177
@contextlib.contextmanager
201178
def _maybe_allow_interrupt(qapp):
202179
"""

0 commit comments

Comments
 (0)