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

Skip to content

Commit a45c399

Browse files
authored
Merge pull request #16843 from anntzer/is_pyqt5
Deprecate is_pyqt5.
2 parents 8cd780f + 38e2c4c commit a45c399

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

doc/api/api_changes_3.3/deprecations.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,3 +540,8 @@ These are unused and can be easily reproduced by other date tools.
540540
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
541541
The ``cbid`` and ``locator`` attribute are deprecated. Use
542542
``mappable.colorbar_cid`` and ``colorbar.locator``, as for standard colorbars.
543+
544+
``qt_compat.is_pyqt5``
545+
~~~~~~~~~~~~~~~~~~~~~~
546+
This function is deprecated in prevision of the future release of PyQt6. The
547+
Qt version can be checked using ``QtCore.QT_VERSION_STR``.

examples/user_interfaces/embedding_in_qt_sgskip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import numpy as np
1616

17-
from matplotlib.backends.qt_compat import QtCore, QtWidgets, is_pyqt5
18-
if is_pyqt5():
17+
from matplotlib.backends.qt_compat import QtCore, QtWidgets
18+
if QtCore.QT_VERSION_STR >= "5.":
1919
from matplotlib.backends.backend_qt5agg import (
2020
FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
2121
else:

lib/matplotlib/backends/backend_qt5.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _create_qApp():
105105
app = QtWidgets.QApplication.instance()
106106
if app is None:
107107
# check for DISPLAY env variable on X11 build of Qt
108-
if is_pyqt5():
108+
if QtCore.QT_VERSION_STR >= "5.":
109109
try:
110110
importlib.import_module(
111111
# i.e. PyQt5.QtX11Extras or PySide2.QtX11Extras.
@@ -130,11 +130,10 @@ def _create_qApp():
130130
else:
131131
qApp = app
132132

133-
if is_pyqt5():
134-
try:
135-
qApp.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
136-
except AttributeError:
137-
pass
133+
try:
134+
qApp.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
135+
except AttributeError:
136+
pass
138137

139138

140139
def _allow_super_init(__init__):
@@ -332,7 +331,7 @@ def mouseReleaseEvent(self, event):
332331
FigureCanvasBase.button_release_event(self, x, y, button,
333332
guiEvent=event)
334333

335-
if is_pyqt5():
334+
if QtCore.QT_VERSION_STR >= "5.":
336335
def wheelEvent(self, event):
337336
x, y = self.mouseEventCoords(event)
338337
# from QWheelEvent::delta doc
@@ -699,7 +698,7 @@ def basedir(self):
699698
return str(cbook._get_data_path('images'))
700699

701700
def _icon(self, name, color=None):
702-
if is_pyqt5():
701+
if QtCore.QT_VERSION_STR >= '5.':
703702
name = name.replace('.png', '_large.png')
704703
pm = QtGui.QPixmap(str(cbook._get_data_path('images', name)))
705704
qt_compat._setDevicePixelRatio(pm, qt_compat._devicePixelRatio(self))
@@ -896,9 +895,7 @@ def __init__(self, toolmanager, parent):
896895

897896
@property
898897
def _icon_extension(self):
899-
if is_pyqt5():
900-
return '_large.png'
901-
return '.png'
898+
return '_large.png' if QtCore.QT_VERSION_STR >= '5.' else '.png'
902899

903900
def add_toolitem(
904901
self, name, group, position, image_file, description, toggle):

lib/matplotlib/backends/qt_compat.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def _isdeleted(obj): return not shiboken2.isValid(obj)
8585
raise ValueError("Unexpected value for the 'backend.qt5' rcparam")
8686
_getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
8787

88+
@mpl.cbook.deprecated("3.3", alternative="QtCore.QT_VERSION_STR")
8889
def is_pyqt5():
8990
return True
9091

@@ -144,6 +145,7 @@ def _isdeleted(obj): return not shiboken.isValid(obj)
144145
raise ValueError("Unexpected value for the 'backend.qt4' rcparam")
145146
QtWidgets = QtGui
146147

148+
@mpl.cbook.deprecated("3.3", alternative="QtCore.QT_VERSION_STR")
147149
def is_pyqt5():
148150
return False
149151

@@ -183,7 +185,7 @@ def _setDevicePixelRatio(obj, factor): pass
183185
# These globals are only defined for backcompatibility purposes.
184186
ETS = dict(pyqt=(QT_API_PYQTv2, 4), pyside=(QT_API_PYSIDE, 4),
185187
pyqt5=(QT_API_PYQT5, 5), pyside2=(QT_API_PYSIDE2, 5))
186-
QT_RC_MAJOR_VERSION = 5 if is_pyqt5() else 4
188+
QT_RC_MAJOR_VERSION = int(QtCore.qVersion().split(".")[0])
187189

188-
if not is_pyqt5():
190+
if QT_RC_MAJOR_VERSION == 4:
189191
mpl.cbook.warn_deprecated("3.3", name="support for Qt4")

0 commit comments

Comments
 (0)