blob: 492d88ce103875d04cc64b7f27abde746f53b4be (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import os
import wx
from .paths import get_resource_dir
def is_dark_theme():
return wx.SystemSettings().GetAppearance().IsDark()
def load_icon(icon_name, window=None, width=None, height=None):
if window is None and not (width and height):
raise ValueError("load_icon(): must pass a window or width and height")
icon = wx.Image(os.path.join(get_resource_dir("icons"), f"{icon_name}.png"))
if not (width and height):
render = wx.RendererNative.Get()
width = height = render.GetHeaderButtonHeight(window)
icon.Rescale(width, height, wx.IMAGE_QUALITY_HIGH)
if is_dark_theme():
# only way I've found to get a negative image
data = icon.GetDataBuffer()
for i in range(len(data)):
data[i] = 255 - data[i]
return icon.ConvertToBitmap()
|