[core/theme] Add prefix/postfix methods

Add a way to specify prefix and postfix strings to the full text of a
widget's text. Currently, the theme does not fill those yet.

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-08 11:31:20 +01:00
parent e6666becb3
commit 64f5fc100e
6 changed files with 73 additions and 6 deletions

View file

@ -7,12 +7,14 @@ module parameters, etc.) to all other components
import argparse
MODULE_HELP = ""
THEME_HELP = ""
def create_parser():
"""Create the argument parser"""
parser = argparse.ArgumentParser(description="display system data in the i3bar")
parser.add_argument("-m", "--modules", nargs="+", default=[],
help=MODULE_HELP)
help=MODULE_HELP)
parser.add_argument("-t", "--theme", default="default", help=THEME_HELP)
return parser
class Config(object):
@ -32,4 +34,8 @@ class Config(object):
"name": x if not ":" in x else x.split(":")[1],
} for x in self._args.modules]
def theme(self):
"""Return the name of the selected theme"""
return self._args.theme
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -19,8 +19,8 @@ class Widget(object):
class I3BarOutput(object):
"""Manage output according to the i3bar protocol"""
def __init__(self):
pass
def __init__(self, theme):
self._theme = theme
def start(self):
"""Print start preamble for i3bar protocol"""
@ -32,8 +32,13 @@ class I3BarOutput(object):
def draw_widget(self, result, widget):
"""Draw a single widget"""
full_text = widget.full_text()
if self._theme.prefix():
full_text = "{}{}".format(self._theme.prefix(), full_text)
if self._theme.suffix():
full_text = "{}{}".format(full_text, self._theme.suffix())
result.append({
u"full_text": widget.full_text()
u"full_text": "{}".format(full_text)
})
def draw(self, widgets, engine=None):

View file

@ -14,6 +14,14 @@ class Theme(object):
def __init__(self, name):
self._theme = self.load(name)
def prefix(self):
"""Return the theme prefix for a widget's full text"""
return None
def suffix(self):
"""Return the theme suffix for a widget's full text"""
return None
def load(self, name):
"""Load and parse a theme file"""
path = theme_path()