Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ba2b40

Browse filesBrowse files
authored
Merge pull request #17070 from anntzer/qtclean
Cleanups to Qt backend.
2 parents 065769b + b506f8d commit 0ba2b40
Copy full SHA for 0ba2b40

File tree

Expand file treeCollapse file tree

3 files changed

+30
-29
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+30
-29
lines changed

‎doc/api/api_changes_3.3/deprecations.rst

Copy file name to clipboardExpand all lines: doc/api/api_changes_3.3/deprecations.rst
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,12 @@ The ``Fil``, ``Fill``, ``Filll``, ``NegFil``, ``NegFill``, ``NegFilll``, and
366366
``SsGlue`` classes in the :mod:`matplotlib.mathtext` module are deprecated.
367367
As an alternative, directly construct glue instances with ``Glue("fil")``, etc.
368368

369-
NavigationToolbar2QT.parent
370-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
371-
This attribute is deprecated. In order to access the parent window, use
369+
NavigationToolbar2QT.parent and .basedir
370+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
371+
These attributes are deprecated. In order to access the parent window, use
372372
``toolbar.canvas.parent()``. Once the deprecation period is elapsed, it will
373-
also be accessible as ``toolbar.parent()``.
373+
also be accessible as ``toolbar.parent()``. The base directory to the icons
374+
is ``os.path.join(mpl.get_data_path(), "images")``.
374375

375376
Path helpers in :mod:`.bezier`
376377
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

‎lib/matplotlib/backends/backend_qt5.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_qt5.py
+16-23Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
import matplotlib.backends.qt_editor.figureoptions as figureoptions
1717
from matplotlib.backends.qt_editor.formsubplottool import UiSubplotTool
1818
from matplotlib.backend_managers import ToolManager
19-
19+
from . import qt_compat
2020
from .qt_compat import (
21-
QtCore, QtGui, QtWidgets, _isdeleted, _getSaveFileName,
22-
is_pyqt5, __version__, QT_API)
21+
QtCore, QtGui, QtWidgets, _isdeleted, is_pyqt5, __version__, QT_API)
2322

2423
backend_version = __version__
2524

@@ -255,12 +254,7 @@ def _update_figure_dpi(self):
255254

256255
@property
257256
def _dpi_ratio(self):
258-
# Not available on Qt4 or some older Qt5.
259-
try:
260-
# self.devicePixelRatio() returns 0 in rare cases
261-
return self.devicePixelRatio() or 1
262-
except AttributeError:
263-
return 1
257+
return qt_compat._devicePixelRatio(self)
264258

265259
def _update_dpi(self):
266260
# As described in __init__ above, we need to be careful in cases with
@@ -662,12 +656,9 @@ class NavigationToolbar2QT(NavigationToolbar2, QtWidgets.QToolBar):
662656

663657
def __init__(self, canvas, parent, coordinates=True):
664658
"""coordinates: should we show the coordinates on the right?"""
665-
self.canvas = canvas
666659
self._parent = parent
667660
self.coordinates = coordinates
668-
self._actions = {}
669-
"""A mapping of toolitem method names to their QActions"""
670-
661+
self._actions = {} # mapping of toolitem method names to QActions.
671662
QtWidgets.QToolBar.__init__(self, parent)
672663
NavigationToolbar2.__init__(self, canvas)
673664

@@ -676,12 +667,17 @@ def __init__(self, canvas, parent, coordinates=True):
676667
def parent(self):
677668
return self._parent
678669

670+
@cbook.deprecated(
671+
"3.3", alternative="os.path.join(mpl.get_data_path(), 'images')")
672+
@property
673+
def basedir(self):
674+
return str(cbook._get_data_path('images'))
675+
679676
def _icon(self, name, color=None):
680677
if is_pyqt5():
681678
name = name.replace('.png', '_large.png')
682-
pm = QtGui.QPixmap(os.path.join(self.basedir, name))
683-
if hasattr(pm, 'setDevicePixelRatio'):
684-
pm.setDevicePixelRatio(self.canvas._dpi_ratio)
679+
pm = QtGui.QPixmap(str(cbook._get_data_path('images', name)))
680+
qt_compat._setDevicePixelRatio(pm, self.canvas._dpi_ratio)
685681
if color is not None:
686682
mask = pm.createMaskFromColor(QtGui.QColor('black'),
687683
QtCore.Qt.MaskOutColor)
@@ -690,8 +686,6 @@ def _icon(self, name, color=None):
690686
return QtGui.QIcon(pm)
691687

692688
def _init_toolbar(self):
693-
self.basedir = str(cbook._get_data_path('images'))
694-
695689
background_color = self.palette().color(self.backgroundRole())
696690
foreground_color = self.palette().color(self.foregroundRole())
697691
icon_color = (foreground_color
@@ -807,9 +801,9 @@ def save_figure(self, *args):
807801
filters.append(filter)
808802
filters = ';;'.join(filters)
809803

810-
fname, filter = _getSaveFileName(self.canvas.parent(),
811-
"Choose a filename to save to",
812-
start, filters, selectedFilter)
804+
fname, filter = qt_compat._getSaveFileName(
805+
self.canvas.parent(), "Choose a filename to save to", start,
806+
filters, selectedFilter)
813807
if fname:
814808
# Save dir for next time, unless empty str (i.e., use cwd).
815809
if startpath != "":
@@ -945,8 +939,7 @@ def _add_to_group(self, group, name, button, position):
945939

946940
def _icon(self, name):
947941
pm = QtGui.QPixmap(name)
948-
if hasattr(pm, 'setDevicePixelRatio'):
949-
pm.setDevicePixelRatio(self.toolmanager.canvas._dpi_ratio)
942+
qt_compat._setDevicePixelRatio(pm, self.toolmanager.canvas._dpi_ratio)
950943
return QtGui.QIcon(pm)
951944

952945
def toggle_toolitem(self, name, toggled):

‎lib/matplotlib/backends/qt_compat.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_compat.py
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
def _setup_pyqt5():
6969
global QtCore, QtGui, QtWidgets, __version__, is_pyqt5, \
70-
_isdeleted, _getSaveFileName
70+
_isdeleted, _devicePixelRatio, _setDevicePixelRatio, _getSaveFileName
7171

7272
if QT_API == QT_API_PYQT5:
7373
from PyQt5 import QtCore, QtGui, QtWidgets
@@ -88,10 +88,14 @@ def _isdeleted(obj): return not shiboken2.isValid(obj)
8888
def is_pyqt5():
8989
return True
9090

91+
# self.devicePixelRatio() returns 0 in rare cases
92+
def _devicePixelRatio(obj): return obj.devicePixelRatio() or 1
93+
def _setDevicePixelRatio(obj, factor): obj.setDevicePixelRatio(factor)
94+
9195

9296
def _setup_pyqt4():
9397
global QtCore, QtGui, QtWidgets, __version__, is_pyqt5, \
94-
_isdeleted, _getSaveFileName
98+
_isdeleted, _devicePixelRatio, _setDevicePixelRatio, _getSaveFileName
9599

96100
def _setup_pyqt4_internal(api):
97101
global QtCore, QtGui, QtWidgets, \
@@ -143,6 +147,9 @@ def _isdeleted(obj): return not shiboken.isValid(obj)
143147
def is_pyqt5():
144148
return False
145149

150+
def _devicePixelRatio(obj): return 1
151+
def _setDevicePixelRatio(obj, factor): pass
152+
146153

147154
if QT_API in [QT_API_PYQT5, QT_API_PYSIDE2]:
148155
_setup_pyqt5()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.