implement --iconmarkup argument

WARNING: highly experimental
This allows fine tuning of icons via raw Pango markup. Is backwards
compatible with icon foreground/background support in themes (if those
settings are present in the theme but are missing from the icon markup
template - they are merged in).
This commit is contained in:
me 2020-02-12 19:43:01 +02:00
parent f44d48e7bd
commit 89c6afb493
2 changed files with 33 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import sys
import json
import uuid
import logging
import xml.etree.ElementTree
import bumblebee.store
import bumblebee.util
@ -339,6 +340,7 @@ class WidgetDrawer(object):
self._prefix = None
self._prefix_fg = None
self._prefix_bg = None
self._iconmarkup = None
self._suffix = None
def add_separator(self, widget, separator):
@ -352,6 +354,19 @@ class WidgetDrawer(object):
"separator_block_width": self._theme.separator_block_width(widget),
})
def add_prefix_iconmarkup(self, widget):
"""add custom Pango markup for prefix"""
element = xml.etree.ElementTree.XML(self._iconmarkup)
# if the custom markup has neither 'foreground' or 'fgcolor'
# attributes, but theme has prefixfg, merge it
if 'foreground' not in element.keys() and 'fgcolor' not in element.keys() and self._prefix_fg is not None:
element.set("foreground", self._prefix_fg)
# if the custom markup has neither 'background' or 'bgcolor'
# attributes, but theme has prefixbg, merge it
if 'background' not in element.keys() and 'bgcolor' not in element.keys() and self._prefix_bg is not None:
element.set("background", self._prefix_bg)
self._prefix = xml.etree.ElementTree.tostring(element).decode("utf-8").format(self._prefix)
def add_prefix_colors(self, widget):
"""add custom theme colors for prefix"""
self._prefix = "<span {} {}>{}</span>".format(
@ -368,15 +383,27 @@ class WidgetDrawer(object):
# add prefix/suffix colors
self._prefix_fg = self._theme.prefix_fg(widget)
self._prefix_bg = self._theme.prefix_bg(widget)
self.add_prefix_colors(widget)
self._iconmarkup = self._config.iconmarkup()
if self._iconmarkup != "none":
self.add_prefix_iconmarkup(widget)
else:
self.add_prefix_colors(widget)
if self._prefix:
self._full_text = u"{}{}".format(self._prefix, self._full_text)
def add_suffix_iconmarkup(self, widget):
"""add custom Pango markup for suffix"""
self._suffix = self._iconmarkup.format(self._suffix)
def add_suffix(self, widget, padding):
"""add suffix to full_text"""
self._suffix = self._theme.suffix(widget, padding)
if self._markup == "pango":
if self._iconmarkup != "none":
self.add_suffix_iconmarkup(widget)
if self._suffix:
self._full_text = u"{}{}".format(self._full_text, self._suffix)