1616import matplotlib .backends .qt_editor .figureoptions as figureoptions
1717from matplotlib .backends .qt_editor .formsubplottool import UiSubplotTool
1818from matplotlib .backend_managers import ToolManager
19-
19+ from . import qt_compat
2020from .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
2423backend_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 ):
0 commit comments