Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6297e88

Browse files
committed
Bump minimum QT5 version to 5.12
1 parent 788a43d commit 6297e88

File tree

7 files changed

+52
-191
lines changed

7 files changed

+52
-191
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.12 has been dropped
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... as there are no wheels or conda packages that support both Qt 5.11 (or
4+
older) and Python 3.9 (or newer).

‎lib/matplotlib/backends/backend_qt.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
from . import qt_compat
1515
from .qt_compat import (
1616
QtCore, QtGui, QtWidgets, __version__, QT_API,
17-
_enum, _to_int, _isdeleted, _maybe_allow_interrupt
17+
_to_int, _isdeleted, _maybe_allow_interrupt
1818
)
1919

2020

2121
# SPECIAL_KEYS are Qt::Key that do *not* return their Unicode name
2222
# instead they have manually specified names.
2323
SPECIAL_KEYS = {
24-
_to_int(getattr(_enum("QtCore.Qt.Key"), k)): v for k, v in [
24+
_to_int(getattr(QtCore.Qt.Key, k)): v for k, v in [
2525
("Key_Escape", "escape"),
2626
("Key_Tab", "tab"),
2727
("Key_Backspace", "backspace"),
@@ -66,8 +66,8 @@
6666
# Elements are (Qt::KeyboardModifiers, Qt::Key) tuples.
6767
# Order determines the modifier order (ctrl+alt+...) reported by Matplotlib.
6868
_MODIFIER_KEYS = [
69-
(_to_int(getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)),
70-
_to_int(getattr(_enum("QtCore.Qt.Key"), key)))
69+
(_to_int(getattr(QtCore.Qt.KeyboardModifier, mod)),
70+
_to_int(getattr(QtCore.Qt.Key, key)))
7171
for mod, key in [
7272
("ControlModifier", "Key_Control"),
7373
("AltModifier", "Key_Alt"),
@@ -76,7 +76,7 @@
7676
]
7777
]
7878
cursord = {
79-
k: getattr(_enum("QtCore.Qt.CursorShape"), v) for k, v in [
79+
k: getattr(QtCore.Qt.CursorShape, v) for k, v in [
8080
(cursors.MOVE, "SizeAllCursor"),
8181
(cursors.HAND, "PointingHandCursor"),
8282
(cursors.POINTER, "ArrowCursor"),
@@ -132,8 +132,8 @@ def _create_qApp():
132132
break
133133
try:
134134
QtWidgets.QApplication.setAttribute(
135-
QtCore.Qt.AA_EnableHighDpiScaling)
136-
except AttributeError:# Only for Qt>=5.6, <6.
135+
QtCore.Qt.ApplicationAttribute.AA_EnableHighDpiScaling)
136+
except AttributeError:
137137
pass
138138
try:
139139
QtWidgets.QApplication.setHighDpiScaleFactorRoundingPolicy(
@@ -147,9 +147,9 @@ def _create_qApp():
147147
app.setWindowIcon(icon)
148148
app.lastWindowClosed.connect(app.quit)
149149
cbook._setup_new_guiapp()
150-
151150
try:
152-
app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps) # Only for Qt<6.
151+
# Only for Qt<6.
152+
app.setAttribute(QtCore.Qt.ApplicationAttribute.AA_UseHighDpiPixmaps)
153153
except AttributeError:
154154
pass
155155

@@ -191,7 +191,7 @@ class FigureCanvasQT(FigureCanvasBase, QtWidgets.QWidget):
191191
manager_class = _api.classproperty(lambda cls: FigureManagerQT)
192192

193193
buttond = {
194-
getattr(_enum("QtCore.Qt.MouseButton"), k): v for k, v in [
194+
getattr(QtCore.Qt.MouseButton, k): v for k, v in [
195195
("LeftButton", MouseButton.LEFT),
196196
("RightButton", MouseButton.RIGHT),
197197
("MiddleButton", MouseButton.MIDDLE),
@@ -209,8 +209,7 @@ def __init__(self, figure=None):
209209
self._draw_rect_callback = lambda painter: None
210210
self._in_resize_event = False
211211

212-
self.setAttribute(
213-
_enum("QtCore.Qt.WidgetAttribute").WA_OpaquePaintEvent)
212+
self.setAttribute(QtCore.Qt.WidgetAttribute.WA_OpaquePaintEvent)
214213
self.setMouseTracking(True)
215214
self.resize(*self.get_width_height())
216215

@@ -564,7 +563,7 @@ def __init__(self, canvas, num):
564563
# StrongFocus accepts both tab and click to focus and will enable the
565564
# canvas to process event without clicking.
566565
# https://doc.qt.io/qt-5/qt.html#FocusPolicy-enum
567-
self.canvas.setFocusPolicy(_enum("QtCore.Qt.FocusPolicy").StrongFocus)
566+
self.canvas.setFocusPolicy(QtCore.Qt.FocusPolicy.StrongFocus)
568567
self.canvas.setFocus()
569568

570569
self.window.raise_()
@@ -642,9 +641,8 @@ def __init__(self, canvas, parent=None, coordinates=True):
642641
"""coordinates: should we show the coordinates on the right?"""
643642
QtWidgets.QToolBar.__init__(self, parent)
644643
self.setAllowedAreas(QtCore.Qt.ToolBarArea(
645-
_to_int(_enum("QtCore.Qt.ToolBarArea").TopToolBarArea) |
646-
_to_int(_enum("QtCore.Qt.ToolBarArea").BottomToolBarArea)))
647-
644+
_to_int(QtCore.Qt.ToolBarArea.TopToolBarArea) |
645+
_to_int(QtCore.Qt.ToolBarArea.BottomToolBarArea)))
648646
self.coordinates = coordinates
649647
self._actions = {} # mapping of toolitem method names to QActions.
650648
self._subplot_dialog = None
@@ -667,11 +665,12 @@ def __init__(self, canvas, parent=None, coordinates=True):
667665
if self.coordinates:
668666
self.locLabel = QtWidgets.QLabel("", self)
669667
self.locLabel.setAlignment(QtCore.Qt.AlignmentFlag(
670-
_to_int(_enum("QtCore.Qt.AlignmentFlag").AlignRight) |
671-
_to_int(_enum("QtCore.Qt.AlignmentFlag").AlignVCenter)))
668+
_to_int(QtCore.Qt.AlignmentFlag.AlignRight) |
669+
_to_int(QtCore.Qt.AlignmentFlag.AlignVCenter)))
670+
672671
self.locLabel.setSizePolicy(QtWidgets.QSizePolicy(
673-
_enum("QtWidgets.QSizePolicy.Policy").Expanding,
674-
_enum("QtWidgets.QSizePolicy.Policy").Ignored,
672+
QtWidgets.QSizePolicy.Policy.Expanding,
673+
QtWidgets.QSizePolicy.Policy.Ignored,
675674
))
676675
labelAction = self.addWidget(self.locLabel)
677676
labelAction.setVisible(True)
@@ -697,7 +696,7 @@ def _icon(self, name):
697696
icon_color = self.palette().color(self.foregroundRole())
698697
mask = pm.createMaskFromColor(
699698
QtGui.QColor('black'),
700-
_enum("QtCore.Qt.MaskMode").MaskOutColor)
699+
QtCore.Qt.MaskMode.MaskOutColor)
701700
pm.fill(icon_color)
702701
pm.setMask(mask)
703702
return QtGui.QIcon(pm)
@@ -801,8 +800,8 @@ def save_figure(self, *args):
801800
except Exception as e:
802801
QtWidgets.QMessageBox.critical(
803802
self, "Error saving file", str(e),
804-
_enum("QtWidgets.QMessageBox.StandardButton").Ok,
805-
_enum("QtWidgets.QMessageBox.StandardButton").NoButton)
803+
QtWidgets.QMessageBox.StandardButton.Ok,
804+
QtWidgets.QMessageBox.StandardButton.NoButton)
806805

807806
def set_history_buttons(self):
808807
can_backward = self._nav_stack._pos > 0
@@ -916,15 +915,15 @@ def __init__(self, toolmanager, parent=None):
916915
ToolContainerBase.__init__(self, toolmanager)
917916
QtWidgets.QToolBar.__init__(self, parent)
918917
self.setAllowedAreas(QtCore.Qt.ToolBarArea(
919-
_to_int(_enum("QtCore.Qt.ToolBarArea").TopToolBarArea) |
920-
_to_int(_enum("QtCore.Qt.ToolBarArea").BottomToolBarArea)))
918+
_to_int(QtCore.Qt.ToolBarArea.TopToolBarArea) |
919+
_to_int(QtCore.Qt.ToolBarArea.BottomToolBarArea)))
921920
message_label = QtWidgets.QLabel("")
922921
message_label.setAlignment(QtCore.Qt.AlignmentFlag(
923-
_to_int(_enum("QtCore.Qt.AlignmentFlag").AlignRight) |
924-
_to_int(_enum("QtCore.Qt.AlignmentFlag").AlignVCenter)))
922+
_to_int(QtCore.Qt.AlignmentFlag.AlignRight) |
923+
_to_int(QtCore.Qt.AlignmentFlag.AlignVCenter)))
925924
message_label.setSizePolicy(QtWidgets.QSizePolicy(
926-
_enum("QtWidgets.QSizePolicy.Policy").Expanding,
927-
_enum("QtWidgets.QSizePolicy.Policy").Ignored,
925+
QtWidgets.QSizePolicy.Policy.Expanding,
926+
QtWidgets.QSizePolicy.Policy.Ignored,
928927
))
929928
self._message_action = self.addWidget(message_label)
930929
self._toolitems = {}

‎lib/matplotlib/backends/backend_qtagg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
from matplotlib.transforms import Bbox
88

9-
from .qt_compat import QT_API, _enum
9+
from .qt_compat import QT_API, QtCore, QtGui
1010
from .backend_agg import FigureCanvasAgg
11-
from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT
11+
from .backend_qt import _BackendQT, FigureCanvasQT
1212
from .backend_qt import ( # noqa: F401 # pylint: disable=W0611
1313
FigureManagerQT, NavigationToolbar2QT)
1414

@@ -57,7 +57,7 @@ def paintEvent(self, event):
5757

5858
painter.eraseRect(rect) # clear the widget canvas
5959
qimage = QtGui.QImage(ptr, buf.shape[1], buf.shape[0],
60-
_enum("QtGui.QImage.Format").Format_RGBA8888)
60+
QtGui.QImage.Format.Format_RGBA8888)
6161
qimage.setDevicePixelRatio(self.device_pixel_ratio)
6262
# set origin using original QT coordinates
6363
origin = QtCore.QPoint(rect.left(), rect.top())

‎lib/matplotlib/backends/backend_qtcairo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import ctypes
22

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

77

88
class FigureCanvasQTCairo(FigureCanvasCairo, FigureCanvasQT):
@@ -28,7 +28,7 @@ def paintEvent(self, event):
2828
ptr = buf
2929
qimage = QtGui.QImage(
3030
ptr, width, height,
31-
_enum("QtGui.QImage.Format").Format_ARGB32_Premultiplied)
31+
QtGui.QImage.Format.Format_ARGB32_Premultiplied)
3232
# Adjust the buf reference count to work around a memory leak bug in
3333
# QImage under PySide.
3434
if QT_API == "PySide2" and QtCore.__version_info__ < (5, 12):

‎lib/matplotlib/backends/qt_compat.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
- otherwise, use whatever the rcParams indicate.
1010
"""
1111

12-
import functools
1312
import operator
1413
import os
1514
import platform
@@ -139,11 +138,11 @@ def _isdeleted(obj):
139138
_version_info = tuple(QtCore.QLibraryInfo.version().segments())
140139

141140

142-
if _version_info < (5, 10):
141+
if _version_info < (5, 12):
143142
raise ImportError(
144143
f"The Qt version imported is "
145144
f"{QtCore.QLibraryInfo.version().toString()} but Matplotlib requires "
146-
f"Qt>=5.10")
145+
f"Qt>=5.12")
147146

148147

149148
# Fixes issues with Big Sur
@@ -154,17 +153,6 @@ def _isdeleted(obj):
154153
os.environ.setdefault("QT_MAC_WANTS_LAYER", "1")
155154

156155

157-
# PyQt6 enum compat helpers.
158-
159-
160-
@functools.cache
161-
def _enum(name):
162-
# foo.bar.Enum.Entry (PyQt6) <=> foo.bar.Entry (non-PyQt6).
163-
return operator.attrgetter(
164-
name if QT_API == 'PyQt6' else name.rpartition(".")[0]
165-
)(sys.modules[QtCore.__package__])
166-
167-
168156
# Backports.
169157

170158

@@ -207,7 +195,7 @@ def _maybe_allow_interrupt(qapp):
207195
wsock.setblocking(False)
208196
old_wakeup_fd = signal.set_wakeup_fd(wsock.fileno())
209197
sn = QtCore.QSocketNotifier(
210-
rsock.fileno(), _enum('QtCore.QSocketNotifier.Type').Read
198+
rsock.fileno(), QtCore.QSocketNotifier.Type.Read
211199
)
212200

213201
# We do not actually care about this value other than running some

‎lib/matplotlib/backends/qt_editor/_formlayout.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
from numbers import Integral, Real
4848

4949
from matplotlib import _api, colors as mcolors
50-
from matplotlib.backends.qt_compat import (
51-
QtGui, QtWidgets, QtCore, _enum, _to_int)
50+
from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
5251

5352
_log = logging.getLogger(__name__)
5453

@@ -71,7 +70,7 @@ def __init__(self, parent=None):
7170
def choose_color(self):
7271
color = QtWidgets.QColorDialog.getColor(
7372
self._color, self.parentWidget(), "",
74-
_enum("QtWidgets.QColorDialog.ColorDialogOption").ShowAlphaChannel)
73+
QtWidgets.QColorDialog.ColorDialogOption.ShowAlphaChannel)
7574
if color.isValid():
7675
self.set_color(color)
7776

@@ -204,7 +203,7 @@ def get_font(self):
204203
def is_edit_valid(edit):
205204
text = edit.text()
206205
state = edit.validator().validate(text, 0)[0]
207-
return state == _enum("QtGui.QDoubleValidator.State").Acceptable
206+
return state == QtGui.QDoubleValidator.State.Acceptable
208207

209208

210209
class FormWidget(QtWidgets.QWidget):
@@ -442,15 +441,13 @@ def __init__(self, data, title="", comment="",
442441
# Button box
443442
self.bbox = bbox = QtWidgets.QDialogButtonBox(
444443
QtWidgets.QDialogButtonBox.StandardButton(
445-
_to_int(
446-
_enum("QtWidgets.QDialogButtonBox.StandardButton").Ok) |
447-
_to_int(
448-
_enum("QtWidgets.QDialogButtonBox.StandardButton").Cancel)
444+
QtWidgets.QDialogButtonBox.StandardButton.Ok |
445+
QtWidgets.QDialogButtonBox.StandardButton.Cancel
449446
))
450447
self.formwidget.update_buttons.connect(self.update_buttons)
451448
if self.apply_callback is not None:
452449
apply_btn = bbox.addButton(
453-
_enum("QtWidgets.QDialogButtonBox.StandardButton").Apply)
450+
QtWidgets.QDialogButtonBox.StandardButton.Apply)
454451
apply_btn.clicked.connect(self.apply)
455452

456453
bbox.accepted.connect(self.accept)
@@ -475,7 +472,7 @@ def update_buttons(self):
475472
valid = False
476473
for btn_type in ["Ok", "Apply"]:
477474
btn = self.bbox.button(
478-
getattr(_enum("QtWidgets.QDialogButtonBox.StandardButton"),
475+
getattr(QtWidgets.QDialogButtonBox.StandardButton,
479476
btn_type))
480477
if btn is not None:
481478
btn.setEnabled(valid)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /