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,26 +656,27 @@ class NavigationToolbar2QT(NavigationToolbar2, QtWidgets.QToolBar):
662
656
663
657
def __init__ (self , canvas , parent , coordinates
8000
= True ):
664
658
"""coordinates: should we show the coordinates on the right?"""
665
- self .canvas = canvas
666
- self ._parent = parent
667
659
self .coordinates = coordinates
668
- self ._actions = {}
669
- """A mapping of toolitem method names to their QActions"""
670
-
660
+ self ._actions = {} # mapping of toolitem method names to QActions.
671
661
QtWidgets .QToolBar .__init__ (self , parent )
672
662
NavigationToolbar2 .__init__ (self , canvas )
673
663
674
664
@cbook .deprecated ("3.3" , alternative = "self.canvas.parent()" )
675
665
@property
676
666
def parent (self ):
677
- return self ._parent
667
+ return self .canvas .parent ()
668
+
669
+ @cbook .deprecated (
670
+ "3.3" , alternative = "os.path.join(mpl.get_data_path(), 'images')" )
671
+ @property
672
+ def basedir (self ):
673
+ return str (cbook ._get_data_path ('images' ))
678
<
8000
code>674
679
675
def _icon (self , name , color = None ):
680
676
if is_pyqt5 ():
681
677
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 )
678
+ pm = QtGui .QPixmap (str (cbook ._get_data_path ('images' , name )))
679
+ qt_compat ._setDevicePixelRatio (pm , self .canvas ._dpi_ratio )
685
680
if color is not None :
686
681
mask = pm .createMaskFromColor (QtGui .QColor ('black' ),
687
682
QtCore .Qt .MaskOutColor )
@@ -690,8 +685,6 @@ def _icon(self, name, color=None):
690
685
return QtGui .QIcon (pm )
691
686
692
687
def _init_toolbar (self ):
693
- self .basedir = str (cbook ._get_data_path ('images' ))
694
-
695
688
background_color = self .palette ().color (self .backgroundRole ())
696
689
foreground_color = self .palette ().color (self .foregroundRole ())
697
690
icon_color = (foreground_color
@@ -807,9 +800,9 @@ def save_figure(self, *args):
57DF
807
800
filters .append (filter )
808
801
filters = ';;' .join (filters )
809
802
810
- fname , filter = _getSaveFileName (self . canvas . parent (),
811
- "Choose a filename to save to" ,
812
- start , filters , selectedFilter )
803
+ fname , filter = qt_compat . _getSaveFileName (
804
+ self . canvas . parent (), "Choose a filename to save to" , start ,
805
+ filters , selectedFilter )
813
806
if fname :
814
807
# Save dir for next time, unless empty str (i.e., use cwd).
815
808
if startpath != "" :
@@ -945,8 +938,7 @@ def _add_to_group(self, group, name, button, position):
945
938
946
939
def _icon (self , name ):
947
940
pm = QtGui .QPixmap (name )
948
- if hasattr (pm , 'setDevicePixelRatio' ):
949
- pm .setDevicePixelRatio (self .toolmanager .canvas ._dpi_ratio )
941
+ qt_compat ._setDevicePixelRatio (pm , self .toolmanager .canvas ._dpi_ratio )
950
942
return QtGui .QIcon (pm )
951
943
952
944
def toggle_toolitem (self , name , toggled ):
0 commit comments