Skip to content

Remove fallback to nonexistent setDevicePixelRatioF. #18877

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
Nov 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
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from . import qt_compat
from .qt_compat import (
QtCore, QtGui, QtWidgets, __version__, QT_API,
_devicePixelRatioF, _isdeleted, _setDevicePixelRatioF,
_devicePixelRatioF, _isdeleted, _setDevicePixelRatio,
)

backend_version = __version__
Expand Down Expand Up @@ -707,7 +707,7 @@ def _icon(self, name):
if QtCore.qVersion() >= '5.':
name = name.replace('.png', '_large.png')
pm = QtGui.QPixmap(str(cbook._get_data_path('images', name)))
_setDevicePixelRatioF(pm, _devicePixelRatioF(self))
_setDevicePixelRatio(pm, _devicePixelRatioF(self))
if self.palette().color(self.backgroundRole()).value() < 128:
icon_color = self.palette().color(self.foregroundRole())
mask = pm.createMaskFromColor(QtGui.QColor('black'),
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_qt5agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .backend_qt5 import (
QtCore, QtGui, QtWidgets, _BackendQT5, FigureCanvasQT, FigureManagerQT,
NavigationToolbar2QT, backend_version)
from .qt_compat import QT_API, _setDevicePixelRatioF
from .qt_compat import QT_API, _setDevicePixelRatio


class FigureCanvasQTAgg(FigureCanvasAgg, FigureCanvasQT):
Expand Down Expand Up @@ -64,7 +64,7 @@ def paintEvent(self, event):

qimage = QtGui.QImage(buf, buf.shape[1], buf.shape[0],
QtGui.QImage.Format_ARGB32_Premultiplied)
_setDevicePixelRatioF(qimage, self._dpi_ratio)
_setDevicePixelRatio(qimage, self._dpi_ratio)
# set origin using original QT coordinates
origin = QtCore.QPoint(rect.left(), rect.top())
painter.drawImage(origin, qimage)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_qt5cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .backend_cairo import cairo, FigureCanvasCairo, RendererCairo
from .backend_qt5 import QtCore, QtGui, _BackendQT5, FigureCanvasQT
from .qt_compat import QT_API, _setDevicePixelRatioF
from .qt_compat import QT_API, _setDevicePixelRatio


class FigureCanvasQTCairo(FigureCanvasQT, FigureCanvasCairo):
Expand Down Expand Up @@ -33,7 +33,7 @@ def paintEvent(self, event):
# QImage under PySide on Python 3.
if QT_API == 'PySide':
ctypes.c_long.from_address(id(buf)).value = 1
_setDevicePixelRatioF(qimage, dpi_ratio)
_setDevicePixelRatio(qimage, dpi_ratio)
painter = QtGui.QPainter(self)
painter.eraseRect(event.rect())
painter.drawImage(0, 0, qimage)
Expand Down
9 changes: 3 additions & 6 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,12 @@ def _devicePixelRatioF(obj):
return 1


def _setDevicePixelRatioF(obj, val):
def _setDevicePixelRatio(obj, val):
"""
Call obj.setDevicePixelRatioF(val) with graceful fallback for older Qt.
Call obj.setDevicePixelRatio(val) with graceful fallback for older Qt.

This can be replaced by the direct call when we require Qt>=5.6.
"""
if hasattr(obj, 'setDevicePixelRatioF'):
# Not available on Qt<5.6
obj.setDevicePixelRatioF(val)
elif hasattr(obj, 'setDevicePixelRatio'):
if hasattr(obj, 'setDevicePixelRatio'):
# Not available on Qt4 or some older Qt5.
obj.setDevicePixelRatio(val)