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