From 38e2c4c76cc285fe1e6efb51a0eb8adb1477243a Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 19 Mar 2020 18:09:27 +0100 Subject: [PATCH] Deprecate is_pyqt5. The function won't really make sense anymore after the release of PyQt6. --- doc/api/api_changes_3.3/deprecations.rst | 5 +++++ .../user_interfaces/embedding_in_qt_sgskip.py | 4 ++-- lib/matplotlib/backends/backend_qt5.py | 19 ++++++++----------- lib/matplotlib/backends/qt_compat.py | 6 ++++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/doc/api/api_changes_3.3/deprecations.rst b/doc/api/api_changes_3.3/deprecations.rst index 52351888d377..c04ab65d05e5 100644 --- a/doc/api/api_changes_3.3/deprecations.rst +++ b/doc/api/api_changes_3.3/deprecations.rst @@ -535,3 +535,8 @@ These are unused and can be easily reproduced by other date tools. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The ``cbid`` and ``locator`` attribute are deprecated. Use ``mappable.colorbar_cid`` and ``colorbar.locator``, as for standard colorbars. + +``qt_compat.is_pyqt5`` +~~~~~~~~~~~~~~~~~~~~~~ +This function is deprecated in prevision of the future release of PyQt6. The +Qt version can be checked using ``QtCore.QT_VERSION_STR``. diff --git a/examples/user_interfaces/embedding_in_qt_sgskip.py b/examples/user_interfaces/embedding_in_qt_sgskip.py index 1188ee28583e..15b84103eaea 100644 --- a/examples/user_interfaces/embedding_in_qt_sgskip.py +++ b/examples/user_interfaces/embedding_in_qt_sgskip.py @@ -14,8 +14,8 @@ import numpy as np -from matplotlib.backends.qt_compat import QtCore, QtWidgets, is_pyqt5 -if is_pyqt5(): +from matplotlib.backends.qt_compat import QtCore, QtWidgets +if QtCore.QT_VERSION_STR >= "5.": from matplotlib.backends.backend_qt5agg import ( FigureCanvas, NavigationToolbar2QT as NavigationToolbar) else: diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index 26e01ff52308..be18180f8839 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -105,7 +105,7 @@ def _create_qApp(): app = QtWidgets.QApplication.instance() if app is None: # check for DISPLAY env variable on X11 build of Qt - if is_pyqt5(): + if QtCore.QT_VERSION_STR >= "5.": try: importlib.import_module( # i.e. PyQt5.QtX11Extras or PySide2.QtX11Extras. @@ -130,11 +130,10 @@ def _create_qApp(): else: qApp = app - if is_pyqt5(): - try: - qApp.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps) - except AttributeError: - pass + try: + qApp.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps) + except AttributeError: + pass def _allow_super_init(__init__): @@ -332,7 +331,7 @@ def mouseReleaseEvent(self, event): FigureCanvasBase.button_release_event(self, x, y, button, guiEvent=event) - if is_pyqt5(): + if QtCore.QT_VERSION_STR >= "5.": def wheelEvent(self, event): x, y = self.mouseEventCoords(event) # from QWheelEvent::delta doc @@ -699,7 +698,7 @@ def basedir(self): return str(cbook._get_data_path('images')) def _icon(self, name, color=None): - if is_pyqt5(): + if QtCore.QT_VERSION_STR >= '5.': name = name.replace('.png', '_large.png') pm = QtGui.QPixmap(str(cbook._get_data_path('images', name))) qt_compat._setDevicePixelRatio(pm, qt_compat._devicePixelRatio(self)) @@ -896,9 +895,7 @@ def __init__(self, toolmanager, parent): @property def _icon_extension(self): - if is_pyqt5(): - return '_large.png' - return '.png' + return '_large.png' if QtCore.QT_VERSION_STR >= '5.' else '.png' def add_toolitem( self, name, group, position, image_file, description, toggle): diff --git a/lib/matplotlib/backends/qt_compat.py b/lib/matplotlib/backends/qt_compat.py index d2c93f2b2502..42dd55d944c0 100644 --- a/lib/matplotlib/backends/qt_compat.py +++ b/lib/matplotlib/backends/qt_compat.py @@ -85,6 +85,7 @@ def _isdeleted(obj): return not shiboken2.isValid(obj) raise ValueError("Unexpected value for the 'backend.qt5' rcparam") _getSaveFileName = QtWidgets.QFileDialog.getSaveFileName + @mpl.cbook.deprecated("3.3", alternative="QtCore.QT_VERSION_STR") def is_pyqt5(): return True @@ -144,6 +145,7 @@ def _isdeleted(obj): return not shiboken.isValid(obj) raise ValueError("Unexpected value for the 'backend.qt4' rcparam") QtWidgets = QtGui + @mpl.cbook.deprecated("3.3", alternative="QtCore.QT_VERSION_STR") def is_pyqt5(): return False @@ -183,7 +185,7 @@ def _setDevicePixelRatio(obj, factor): pass # These globals are only defined for backcompatibility purposes. ETS = dict(pyqt=(QT_API_PYQTv2, 4), pyside=(QT_API_PYSIDE, 4), pyqt5=(QT_API_PYQT5, 5), pyside2=(QT_API_PYSIDE2, 5)) -QT_RC_MAJOR_VERSION = 5 if is_pyqt5() else 4 +QT_RC_MAJOR_VERSION = int(QtCore.qVersion().split(".")[0]) -if not is_pyqt5(): +if QT_RC_MAJOR_VERSION == 4: mpl.cbook.warn_deprecated("3.3", name="support for Qt4")