@@ -656,16 +656,11 @@ def __init__(self, canvas, parent, coordinates=True):
656656 self .coordinates = coordinates
657657 self ._actions = {} # mapping of toolitem method names to QActions.
658658
659- background_color = self .palette ().color (self .backgroundRole ())
660- foreground_color = self .palette ().color (self .foregroundRole ())
661- icon_color = (foreground_color
662- if background_color .value () < 128 else None )
663-
664659 for text , tooltip_text , image_file , callback in self .toolitems :
665660 if text is None :
666661 self .addSeparator ()
667662 else :
668- a = self .addAction (self ._icon (image_file + '.png' , icon_color ),
663+ a = self .addAction (self ._icon (image_file + '.png' ),
669664 text , getattr (self , callback ))
670665 self ._actions [callback ] = a
671666 if callback in ['zoom' , 'pan' ]:
@@ -697,15 +692,16 @@ def __init__(self, canvas, parent, coordinates=True):
697692 def basedir (self ):
698693 return str (cbook ._get_data_path ('images' ))
699694
700- def _icon (self , name , color = None ):
695+ def _icon (self , name ):
701696 if QtCore .QT_VERSION_STR >= '5.' :
702697 name = name .replace ('.png' , '_large.png' )
703698 pm = QtGui .QPixmap (str (cbook ._get_data_path ('images' , name )))
704699 qt_compat ._setDevicePixelRatio (pm , qt_compat ._devicePixelRatio (self ))
705- if color is not None :
700+ if self .palette ().color (self .backgroundRole ()).value () < 128 :
701+ icon_color = self .palette ().color (self .foregroundRole ())
706702 mask = pm .createMaskFromColor (QtGui .QColor ('black' ),
707703 QtCore .Qt .MaskOutColor )
708- pm .fill (color )
704+ pm .fill (icon_color )
709705 pm .setMask (mask )
710706 return QtGui .QIcon (pm )
711707
@@ -895,15 +891,11 @@ def __init__(self, toolmanager, parent):
895891 self ._toolitems = {}
896892 self ._groups = {}
897893
898- @property
899- def _icon_extension (self ):
900- return '_large.png' if QtCore .QT_VERSION_STR >= '5.' else '.png'
901-
902894 def add_toolitem (
903895 self , name , group , position , image_file , description , toggle ):
904896
905897 button = QtWidgets .QToolButton (self )
906- button .setIcon (self ._icon (image_file ))
898+ button .setIcon (NavigationToolbar2QT ._icon (self , image_file ))
907899 button .setText (name )
908900 if description :
909901 button .setToolTip (description )
@@ -930,11 +922,6 @@ def _add_to_group(self, group, name, button, position):
930922 gr .insert (position , widget )
931923 self ._groups [group ] = gr
932924
933- def _icon (self , name ):
934- pm = QtGui .QPixmap (name )
935- qt_compat ._setDevicePixelRatio (pm , self .toolmanager .canvas ._dpi_ratio )
936- return QtGui .QIcon (pm )
937-
938925 def toggle_toolitem (self , name , toggled ):
939926 if name not in self ._toolitems :
940927 return
0 commit comments