16
16
import matplotlib .backends .qt_editor .figureoptions as figureoptions
17
17
from matplotlib .backends .qt_editor .formsubplottool import UiSubplotTool
18
18
from matplotlib .backend_managers import ToolManager
19
-
19
+ from . import qt_compat
20
20
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 )
23
22
24
23
backend_version = __version__
25
24
@@ -255,12 +254,7 @@ def _update_figure_dpi(self):
255
254
256
255
@property
257
256
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 )
264
258
265
259
def _update_dpi (self ):
266
260
# As described in __init__ above, we need to be careful in cases with
@@ -662,12 +656,9 @@ class NavigationToolbar2QT(NavigationToolbar2, QtWidgets.QToolBar):
662
656
663
657
def __init__ (self , canvas , parent , coordinates = True ):
664
658
"""coordinates: should we show the coordinates on the right?"""
665
- self .canvas = canvas
666
659
self ._parent = parent
667
660
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.
671
662
QtWidgets .QToolBar .__init__ (self , parent )
672
663
NavigationToolbar2 .__init__ (self , canvas )
673
664
@@ -676,12 +667,17 @@ def __init__(self, canvas, parent, coordinates=True):
676
667
def parent (self ):
677
668
return self ._parent
678
669
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
+
679
676
def _icon (self , name , color = None ):
680
677
if is_pyqt5 ():
681
678
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 )
685
681
if color is not None :
686
682
mask = pm .createMaskFromColor (QtGui .QColor ('black' ),
687
683
QtCore .Qt .MaskOutColor )
@@ -690,8 +686,6 @@ def _icon(self, name, color=None):
690
686
return QtGui .QIcon (pm )
691
687
692
688
def _init_toolbar (self ):
693
- self .basedir = str (cbook ._get_data_path ('images' ))
694
-
695
689
background_color = self .palette ().color (self .backgroundRole ())
696
690
foreground_color = self .palette ().color (self .foregroundRole ())
697
691
icon_color = (foreground_color
@@ -807,9 +801,9 @@ def save_figure(self, *args):
807
801
filters .append (filter )
808
802
filters = ';;' .join (filters )
809
803
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 )
813
807
if fname :
814
808
# Save dir for next time, unless empty str (i.e., use cwd).
815
809
if startpath != "" :
@@ -945,8 +939,7 @@ def _add_to_group(self, group, name, button, position):
945
939
946
940
def _icon (self , name ):
947
941
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 )
950
943
return QtGui .QIcon (pm )
951
944
952
945
def toggle_toolitem (self , name , toggled ):
0 commit comments