|
15 | 15 | import matplotlib.backends.qt_editor.figureoptions as figureoptions
|
16 | 16 | from matplotlib.backends.qt_editor.formsubplottool import UiSubplotTool
|
17 | 17 | from matplotlib.backend_managers import ToolManager
|
18 |
| - |
| 18 | +from . import qt_compat |
19 | 19 | from .qt_compat import (
|
20 | 20 | QtCore, QtGui, QtWidgets, _isdeleted, _getSaveFileName,
|
21 |
| - is_pyqt5, __version__, QT_API) |
| 21 | + is_pyqt5, __version__, QT_API, _setDevicePixelRatioF, |
| 22 | + _devicePixelRatioF) |
| 23 | + |
22 | 24 |
|
23 | 25 | backend_version = __version__
|
24 | 26 |
|
@@ -267,12 +269,7 @@ def _update_figure_dpi(self):
|
267 | 269 |
|
268 | 270 | @property
|
269 | 271 | def _dpi_ratio(self):
|
270 |
| - # Not available on Qt4 or some older Qt5. |
271 |
| - try: |
272 |
| - # self.devicePixelRatio() returns 0 in rare cases |
273 |
| - return self.devicePixelRatio() or 1 |
274 |
| - except AttributeError: |
275 |
| - return 1 |
| 272 | + return _devicePixelRatioF(self) |
276 | 273 |
|
277 | 274 | def _update_dpi(self):
|
278 | 275 | # As described in __init__ above, we need to be careful in cases with
|
@@ -454,8 +451,9 @@ def start_event_loop(self, timeout=0):
|
454 | 451 | if hasattr(self, "_event_loop") and self._event_loop.isRunning():
|
455 | 452 | raise RuntimeError("Event loop already running")
|
456 | 453 | self._event_loop = event_loop = QtCore.QEventLoop()
|
457 |
| - if timeout: |
458 |
| - timer = QtCore.QTimer.singleShot(timeout * 1000, event_loop.quit) |
| 454 | + if timeout > 0: |
| 455 | + timer = QtCore.QTimer.singleShot(int(timeout * 1000), |
| 456 | + event_loop.quit) |
459 | 457 | event_loop.exec_()
|
460 | 458 |
|
461 | 459 | def stop_event_loop(self, event=None):
|
@@ -683,8 +681,7 @@ def _icon(self, name, color=None):
|
683 | 681 | if is_pyqt5():
|
684 | 682 | name = name.replace('.png', '_large.png')
|
685 | 683 | pm = QtGui.QPixmap(os.path.join(self.basedir, name))
|
686 |
| - if hasattr(pm, 'setDevicePixelRatio'): |
687 |
| - pm.setDevicePixelRatio(self.canvas._dpi_ratio) |
| 684 | + _setDevicePixelRatioF(pm, _devicePixelRatioF(self)) |
688 | 685 | if color is not None:
|
689 | 686 | mask = pm.createMaskFromColor(QtGui.QColor('black'),
|
690 | 687 | QtCore.Qt.MaskOutColor)
|
|
0 commit comments