From f7c5635fc0bd865d585f30d50cd0d2845b3962dd Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 8 May 2020 20:39:47 +0200 Subject: [PATCH] Also use light color tool buttons in qt+toolmanager+dark theme. ... by reusing the logic of NavigationToolbar2QT. --- lib/matplotlib/backends/backend_qt5.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index c2a7cadf220e..df8c653aeddc 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -654,16 +654,11 @@ def __init__(self, canvas, parent, coordinates=True): self.coordinates = coordinates self._actions = {} # mapping of toolitem method names to QActions. - background_color = self.palette().color(self.backgroundRole()) - foreground_color = self.palette().color(self.foregroundRole()) - icon_color = (foreground_color - if background_color.value() < 128 else None) - for text, tooltip_text, image_file, callback in self.toolitems: if text is None: self.addSeparator() else: - a = self.addAction(self._icon(image_file + '.png', icon_color), + a = self.addAction(self._icon(image_file + '.png'), text, getattr(self, callback)) self._actions[callback] = a if callback in ['zoom', 'pan']: @@ -695,15 +690,16 @@ def __init__(self, canvas, parent, coordinates=True): def basedir(self): return str(cbook._get_data_path('images')) - def _icon(self, name, color=None): + def _icon(self, name): if QtCore.QT_VERSION_STR >= '5.': name = name.replace('.png', '_large.png') pm = QtGui.QPixmap(str(cbook._get_data_path('images', name))) qt_compat._setDevicePixelRatio(pm, qt_compat._devicePixelRatio(self)) - if color is not None: + if self.palette().color(self.backgroundRole()).value() < 128: + icon_color = self.palette().color(self.foregroundRole()) mask = pm.createMaskFromColor(QtGui.QColor('black'), QtCore.Qt.MaskOutColor) - pm.fill(color) + pm.fill(icon_color) pm.setMask(mask) return QtGui.QIcon(pm) @@ -891,15 +887,11 @@ def __init__(self, toolmanager, parent): self._toolitems = {} self._groups = {} - @property - def _icon_extension(self): - return '_large.png' if QtCore.QT_VERSION_STR >= '5.' else '.png' - def add_toolitem( self, name, group, position, image_file, description, toggle): button = QtWidgets.QToolButton(self) - button.setIcon(self._icon(image_file)) + button.setIcon(NavigationToolbar2QT._icon(self, image_file)) button.setText(name) if description: button.setToolTip(description) @@ -926,11 +918,6 @@ def _add_to_group(self, group, name, button, position): gr.insert(position, widget) self._groups[group] = gr - def _icon(self, name): - pm = QtGui.QPixmap(name) - qt_compat._setDevicePixelRatio(pm, self.toolmanager.canvas._dpi_ratio) - return QtGui.QIcon(pm) - def toggle_toolitem(self, name, toggled): if name not in self._toolitems: return