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:
parent
f44d48e7bd
commit
89c6afb493
2 changed files with 33 additions and 1 deletions
|
@ -17,6 +17,7 @@ THEME_HELP = "Specify the theme to use for drawing modules"
|
|||
PARAMETER_HELP = "Provide configuration parameters in the form of <module>.<key>=<value>"
|
||||
LIST_HELP = "Display a list of either available themes or available modules along with their parameters."
|
||||
DEBUG_HELP = "Enable debug log, This will create '~/bumblebee-status-debug.log' by default, can be changed with the '-f' option"
|
||||
ICONMARKUP_HELP = "A Python format string that is valid Pango markup used for low level customization of icons on top of themes. There is no validation performed, this is delegated to the user. Used together with --markup=pango. Example: \"<span foreground='#ffffff' background='#000000'>{}</span>\". WARNING: highly experimental feature"
|
||||
|
||||
class print_usage(argparse.Action):
|
||||
def __init__(self, option_strings, dest, nargs=None, **kwargs):
|
||||
|
@ -61,6 +62,7 @@ def create_parser():
|
|||
help=MODULE_HELP)
|
||||
parser.add_argument("-t", "--theme", default="default", help=THEME_HELP)
|
||||
parser.add_argument("--markup", default="none", help="Specify the markup type of the output (e.g. 'pango')")
|
||||
parser.add_argument("--iconmarkup", default="none", help=ICONMARKUP_HELP)
|
||||
parser.add_argument("-p", "--parameters", nargs="+", action='append', default=[],
|
||||
help=PARAMETER_HELP)
|
||||
parser.add_argument("-l", "--list", choices=["modules", "themes"], action=print_usage,
|
||||
|
@ -129,4 +131,7 @@ class Config(bumblebee.store.Store):
|
|||
def markup(self):
|
||||
return self._args.markup
|
||||
|
||||
def iconmarkup(self):
|
||||
return self._args.iconmarkup
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue