Skip to content

Commit 63f4c2b

Browse files
committed
Restore dark theme support in wx backend
1 parent 0a79593 commit 63f4c2b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/matplotlib/backends/backend_wx.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,21 @@ def _icon(name):
10581058
*name*, including the extension and relative to Matplotlib's "images"
10591059
data directory.
10601060
"""
1061-
return wx.BitmapBundle.FromSVGFile(str(cbook._get_data_path("images", name)),
1062-
wx.ArtProvider().GetDIPSizeHint(wx.ART_TOOLBAR))
1061+
svg = cbook._get_data_path("images", name).read_bytes()
1062+
try:
1063+
dark = wx.SystemSettings.GetAppearance().IsDark()
1064+
except AttributeError: # wxpython < 4.1
1065+
# copied from wx's IsUsingDarkBackground / GetLuminance.
1066+
bg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
1067+
fg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
1068+
# See wx.Colour.GetLuminance.
1069+
bg_lum = (.299 * bg.red + .587 * bg.green + .114 * bg.blue) / 255
1070+
fg_lum = (.299 * fg.red + .587 * fg.green + .114 * fg.blue) / 255
1071+
dark = fg_lum - bg_lum > .2
1072+
if dark:
1073+
svg = svg.replace(b'style="fill:black;"', b'style="fill:white;"')
1074+
toolbarIconSize = wx.ArtProvider().GetDIPSizeHint(wx.ART_TOOLBAR)
1075+
return wx.BitmapBundle.FromSVG(svg, toolbarIconSize)
10631076

10641077
def _update_buttons_checked(self):
10651078
if "Pan" in self.wx_ids:

0 commit comments

Comments
 (0)