def get_icon(self, text):
"""
Return a wx icon from a file like object containing the image
with text.
TODO: transparency support
"""
background = self.conf.get_color('Look', 'background')
foreground = self.conf.get_color('Look', 'color')
font = ImageFont.truetype(
self.conf.get_font_path(),
self.conf.get_int('Look', 'size'),
)
if font is None:
logger.critical("Font could not be looked up. Try setting "
"font_path in the configuration file to the full "
"path to a truetype font.")
mask = Image.new('RGB', (WIDTH, HEIGHT), background)
draw = ImageDraw.Draw(mask)
draw.text(
background,
text,
font=font,
fill=foreground,
)
mask = self.trim(mask)
buf = io.StringIO()
mask.save(buf, 'png')
buf.seek(0)
icon = wx.IconFromBitmap(
wx.BitmapFromImage(
wx.ImageFromStream(
buf,
wx.BITMAP_TYPE_PNG
)
)
)
return icon
评论列表
文章目录