From 5d971267db998ef7e9ba15672ae896aaa2e56262 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 9 Feb 2020 13:46:56 +0100 Subject: [PATCH] [core/theme] Add preparatory work for themes Add two new parameters: theme and iconset Add a placeholder class core.theme.Theme, an instance of which is passed in to the i3 output object (which is the only object that should ever have need of the theme, hopefully). --- bumblebee-status | 3 ++- core/config.py | 22 ++++++++++++++++------ core/output.py | 4 +++- core/theme.py | 6 ++++++ tests/core/test_config.py | 33 ++++++++++++++++++++++++--------- 5 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 core/theme.py diff --git a/bumblebee-status b/bumblebee-status index a52691c..a889d46 100755 --- a/bumblebee-status +++ b/bumblebee-status @@ -44,7 +44,8 @@ def main(): ) config = core.config.Config(sys.argv[1:]) - output = core.output.i3() + theme = core.theme.Theme(config.theme(), config.iconset()) + output = core.output.i3(theme) modules = [] input_thread = threading.Thread(target=handle_input, args=(output,)) diff --git a/core/config.py b/core/config.py index 8878ffd..cbef3df 100644 --- a/core/config.py +++ b/core/config.py @@ -2,29 +2,39 @@ import argparse import util.store -MODULE_HELP = "Specify a space-separated list of modules to load. The order of the list determines their order in the i3bar (from left to right). Use : to provide an alias in case you want to load the same module multiple times, but specify different parameters." -PARAMETER_HELP = "Provide configuration parameters in the form of .=" +MODULE_HELP = 'Specify a space-separated list of modules to load. The order of the list determines their order in the i3bar (from left to right). Use : to provide an alias in case you want to load the same module multiple times, but specify different parameters.' +PARAMETER_HELP = 'Provide configuration parameters in the form of .=' +THEME_HELP = 'Specify the theme to use for drawing modules' class Config(util.store.Store): def __init__(self, args): super(Config, self).__init__() parser = argparse.ArgumentParser(description='bumblebee-status is a modular, theme-able status line generator for the i3 window manager. https://github.com/tobi-wan-kenobi/bumblebee-status/wiki') - parser.add_argument("-m", "--modules", nargs="+", action='append', default=[], + parser.add_argument('-m', '--modules', nargs='+', action='append', default=[], help=MODULE_HELP) - parser.add_argument("-p", "--parameters", nargs="+", action='append', default=[], + parser.add_argument('-p', '--parameters', nargs='+', action='append', default=[], help=PARAMETER_HELP) + parser.add_argument('-t', '--theme', default='default', help=THEME_HELP) + parser.add_argument('-i', '--iconset', default='auto', + help='Specify the name of an iconset to use (overrides theme default)') self._args = parser.parse_args(args) parameters = [ item for sub in self._args.parameters for item in sub ] for param in parameters: - key, value = param.split("=", 1) + key, value = param.split('=', 1) self.set(key, value) def modules(self): return [item for sub in self._args.modules for item in sub] def interval(self): - return float(self.get("interval", 1)) + return float(self.get('interval', 1)) + + def theme(self): + return self._args.theme + + def iconset(self): + return self._args.iconset # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/core/output.py b/core/output.py index 98a00e0..ac2e418 100644 --- a/core/output.py +++ b/core/output.py @@ -2,8 +2,10 @@ import sys import json import time +import core.theme + class i3(object): - def __init__(self): + def __init__(self, theme=core.theme.Theme()): self._modules = [] self._status = {} diff --git a/core/theme.py b/core/theme.py new file mode 100644 index 0000000..73aa92a --- /dev/null +++ b/core/theme.py @@ -0,0 +1,6 @@ + +class Theme(object): + def __init__(self, name='default', iconset=None): + pass + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/tests/core/test_config.py b/tests/core/test_config.py index fac57ca..1b35ab8 100644 --- a/tests/core/test_config.py +++ b/tests/core/test_config.py @@ -4,19 +4,18 @@ import core.config class config(unittest.TestCase): def setUp(self): - self._someModules = [ 'b', 'x', 'a' ] - self._moreModules = [ 'this', 'module', 'here' ] - - def tearDown(self): - pass + self.someModules = [ 'b', 'x', 'a' ] + self.moreModules = [ 'this', 'module', 'here' ] + self.someTheme = 'some-theme' + self.someIconset = 'some-iconset' def test_module(self): - cfg = core.config.Config([ '-m' ] + self._someModules) - self.assertEqual(self._someModules, cfg.modules()) + cfg = core.config.Config([ '-m' ] + self.someModules) + self.assertEqual(self.someModules, cfg.modules()) def test_module_ordering_maintained(self): - cfg = core.config.Config([ '-m' ] + self._someModules + [ '-m' ] + self._moreModules) - self.assertEqual(self._someModules + self._moreModules, cfg.modules()) + cfg = core.config.Config([ '-m' ] + self.someModules + [ '-m' ] + self.moreModules) + self.assertEqual(self.someModules + self.moreModules, cfg.modules()) def test_default_interval(self): cfg = core.config.Config([]) @@ -30,4 +29,20 @@ class config(unittest.TestCase): cfg = core.config.Config([ '-p', 'interval=0.5']) self.assertEqual(0.5, cfg.interval()) + def test_default_theme(self): + cfg = core.config.Config([]) + self.assertEqual('default', cfg.theme()) + + def test_theme(self): + cfg = core.config.Config(['-t', self.someTheme]) + self.assertEqual(self.someTheme, cfg.theme()) + + def test_default_iconset(self): + cfg = core.config.Config([]) + self.assertEqual('auto', cfg.iconset()) + + def test_iconset(self): + cfg = core.config.Config(['-i', self.someIconset]) + self.assertEqual(self.someIconset, cfg.iconset()) + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4