Skip to content

Deprecate is_pyqt5. #16843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/api_changes_3.3/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
4 changes: 2 additions & 2 deletions examples/user_interfaces/embedding_in_qt_sgskip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 8 additions & 11 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -130,11 +130,10 @@ def _create_qApp():
else:
qApp = app

if is_pyqt5():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the check is redundant with the try... except AttributeError.

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__):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")