@@ -654,16 +654,11 @@ def __init__(self, canvas, parent, coordinates=True):
654654 self .coordinates = coordinates
655655 self ._actions = {} # mapping of toolitem method names to QActions.
656656
657- background_color = self .palette ().color (self .backgroundRole ())
658- foreground_color = self .palette ().color (self .foregroundRole ())
659- icon_color = (foreground_color
660- if background_color .value () < 128 else None )
661-
662657 for text , tooltip_text , image_file , callback in self .toolitems :
663658 if text is None :
664659 self .addSeparator ()
665660 else :
666- a = self .addAction (self ._icon (image_file + '.png' , icon_color ),
661+ a = self .addAction (self ._icon (image_file + '.png' ),
667662 text , getattr (self , callback ))
668663 self ._actions [callback ] = a
669664 if callback in ['zoom' , 'pan' ]:
@@ -695,15 +690,16 @@ def __init__(self, canvas, parent, coordinates=True):
695690 def basedir (self ):
696691 return str (cbook ._get_data_path ('images' ))
697692
698- def _icon (self , name , color = None ):
693+ def _icon (self , name ):
699694 if QtCore .QT_VERSION_STR >= '5.' :
700695 name = name .replace ('.png' , '_large.png' )
701696 pm = QtGui .QPixmap (str (cbook ._get_data_path ('images' , name )))
702697 qt_compat ._setDevicePixelRatio (pm , qt_compat ._devicePixelRatio (self ))
703- if color is not None :
698+ if self .palette ().color (self .backgroundRole ()).value () < 128 :
699+ icon_color = self .palette ().color (self .foregroundRole ())
704700 mask = pm .createMaskFromColor (QtGui .QColor ('black' ),
705701 QtCore .Qt .MaskOutColor )
706- pm .fill (color )
702+ pm .fill (icon_color )
707703 pm .setMask (mask )
708704 return QtGui .QIcon (pm )
709705
@@ -891,15 +887,11 @@ def __init__(self, toolmanager, parent):
891887 self ._toolitems = {}
892888 self ._groups = {}
893889
894- @property
895- def _icon_extension (self ):
896- return '_large.png' if QtCore .QT_VERSION_STR >= '5.' else '.png'
897-
898890 def add_toolitem (
899891 self , name , group , position , image_file , description , toggle ):
900892
901893 button = QtWidgets .QToolButton (self )
902- button .setIcon (self ._icon (image_file ))
894+ button .setIcon (NavigationToolbar2QT ._icon (self , image_file ))
903895 button .setText (name )
904896 if description :
905897 button .setToolTip (description )
@@ -926,11 +918,6 @@ def _add_to_group(self, group, name, button, position):
926918 gr .insert (position , widget )
927919 self ._groups [group ] = gr
928920
929- def _icon (self , name ):
930- pm = QtGui .QPixmap (name )
931- qt_compat ._setDevicePixelRatio (pm , self .toolmanager .canvas ._dpi_ratio )
932- return QtGui .QIcon (pm )
933-
934921 def toggle_toolitem (self , name , toggled ):
935922 if name not in self ._toolitems :
936923 return
0 commit comments