make prefix/suffix instance variables

they will be used in more than one method
This commit is contained in:
me 2020-01-31 11:44:07 +02:00
parent 9d8c1f910e
commit 4a7a26456d

View file

@ -334,6 +334,8 @@ class WidgetDrawer(object):
self._theme = theme self._theme = theme
self._config = config self._config = config
self._widgets = [] self._widgets = []
self._prefix = None
self._suffix = None
def add_separator(self, widget, separator): def add_separator(self, widget, separator):
"""Add separator (if theme has one)""" """Add separator (if theme has one)"""
@ -367,28 +369,28 @@ class WidgetDrawer(object):
padding = self._theme.padding(widget) padding = self._theme.padding(widget)
prefix = self._theme.prefix(widget, padding) self._prefix = self._theme.prefix(widget, padding)
suffix = self._theme.suffix(widget, padding) self._suffix = self._theme.suffix(widget, padding)
if self._config.markup() == "pango": if self._config.markup() == "pango":
# add prefix/suffix colors # add prefix/suffix colors
fg = self._theme.prefix_fg(widget) fg = self._theme.prefix_fg(widget)
bg = self._theme.prefix_bg(widget) bg = self._theme.prefix_bg(widget)
prefix = "<span {} {}>{}</span>".format( self._prefix = "<span {} {}>{}</span>".format(
"foreground='{}'".format(fg) if fg else "", "foreground='{}'".format(fg) if fg else "",
"background='{}'".format(bg) if bg else "", "background='{}'".format(bg) if bg else "",
prefix self._prefix
) )
if prefix: if self._prefix:
full_text = u"{}{}".format(prefix, full_text) full_text = u"{}{}".format(self._prefix, full_text)
if suffix: if self._suffix:
full_text = u"{}{}".format(full_text, suffix) full_text = u"{}{}".format(full_text, self._suffix)
width = self._theme.minwidth(widget) width = self._theme.minwidth(widget)
if width: if width:
full_text = full_text.ljust(len(width) + len(prefix) + len(suffix)) full_text = full_text.ljust(len(width) + len(self._prefix) + len(self._suffix))
markup = "none" if not self._config else self._config.markup() markup = "none" if not self._config else self._config.markup()
@ -402,7 +404,7 @@ class WidgetDrawer(object):
"separator_block_width": self._theme.separator_block_width(widget), "separator_block_width": self._theme.separator_block_width(widget),
"separator": True if separator is None else False, "separator": True if separator is None else False,
"min_width": None, "min_width": None,
# "min_width": width + "A"*(len(prefix) + len(suffix)) if width else None, # "min_width": width + "A"*(len(self._prefix) + len(self._suffix)) if width else None,
"align": self._theme.align(widget), "align": self._theme.align(widget),
"instance": widget.id, "instance": widget.id,
"name": module.id, "name": module.id,