@@ -656,16 +656,11 @@ def __init__(self, canvas, parent, coordinates=True):
656
656
self .coordinates = coordinates
657
657
self ._actions = {} # mapping of toolitem method names to QActions.
658
658
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
-
664
659
for text , tooltip_text , image_file , callback in self .toolitems :
665
660
if text is None :
666
661
self .addSeparator ()
667
662
else :
668
- a = self .addAction (self ._icon (image_file + '.png' , icon_color ),
663
+ a = self .addAction (self ._icon (image_file + '.png' ),
669
664
text , getattr (self , callback ))
670
665
self ._actions [callback ] = a
671
666
if callback in ['zoom' , 'pan' ]:
@@ -697,15 +692,16 @@ def __init__(self, canvas, parent, coordinates=True):
697
692
def basedir (self ):
698
693
return str (cbook ._get_data_path ('images' ))
699
694
700
- def _icon (self , name , color = None ):
695
+ def _icon (self , name ):
701
696
if QtCore .QT_VERSION_STR >= '5.' :
702
697
name = name .replace ('.png' , '_large.png' )
703
698
pm = QtGui .QPixmap (str (cbook ._get_data_path ('images' , name )))
704
699
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 ())
706
702
mask = pm .createMaskFromColor (QtGui .QColor ('black' ),
707
703
QtCore .Qt .MaskOutColor )
708
- pm .fill (color )
704
+ pm .fill (icon_color )
709
705
pm .setMask (mask )
710
706
return QtGui .QIcon (pm )
711
707
@@ -895,15 +891,11 @@ def __init__(self, toolmanager, parent):
895
891
self ._toolitems = {}
896
892
self ._groups = {}
897
893
898
- @property
899
- def _icon_extension (self ):
900
- return '_large.png' if QtCore .QT_VERSION_STR >= '5.' else '.png'
901
-
902
894
def add_toolitem (
903
895
self , name , group , position , image_file , description , toggle ):
904
896
905
897
button = QtWidgets .QToolButton (self )
906
- button .setIcon (self ._icon (image_file ))
898
+ button .setIcon (NavigationToolbar2QT ._icon (self , image_file ))
907
899
button .setText (name )
908
900
if description :
909
901
button .setToolTip (description )
@@ -930,11 +922,6 @@ def _add_to_group(self, group, name, button, position):
930
922
gr .insert (position , widget )
931
923
self ._groups [group ] = gr
932
924
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
-
938
925
def toggle_toolitem (self , name , toggled ):
939
926
if name not in self ._toolitems :
940
927
return
0 commit comments