[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).
This commit is contained in:
Tobias Witek 2020-02-09 13:46:56 +01:00
parent b157aa9fb5
commit 5d971267db
5 changed files with 51 additions and 17 deletions

View file

@ -44,7 +44,8 @@ def main():
) )
config = core.config.Config(sys.argv[1:]) 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 = [] modules = []
input_thread = threading.Thread(target=handle_input, args=(output,)) input_thread = threading.Thread(target=handle_input, args=(output,))

View file

@ -2,29 +2,39 @@ import argparse
import util.store 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 <module>:<alias> to provide an alias in case you want to load the same module multiple times, but specify different parameters." 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 <module>:<alias> 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>.<key>=<value>" PARAMETER_HELP = 'Provide configuration parameters in the form of <module>.<key>=<value>'
THEME_HELP = 'Specify the theme to use for drawing modules'
class Config(util.store.Store): class Config(util.store.Store):
def __init__(self, args): def __init__(self, args):
super(Config, self).__init__() 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 = 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) help=MODULE_HELP)
parser.add_argument("-p", "--parameters", nargs="+", action='append', default=[], parser.add_argument('-p', '--parameters', nargs='+', action='append', default=[],
help=PARAMETER_HELP) 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) self._args = parser.parse_args(args)
parameters = [ item for sub in self._args.parameters for item in sub ] parameters = [ item for sub in self._args.parameters for item in sub ]
for param in parameters: for param in parameters:
key, value = param.split("=", 1) key, value = param.split('=', 1)
self.set(key, value) self.set(key, value)
def modules(self): def modules(self):
return [item for sub in self._args.modules for item in sub] return [item for sub in self._args.modules for item in sub]
def interval(self): 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 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -2,8 +2,10 @@ import sys
import json import json
import time import time
import core.theme
class i3(object): class i3(object):
def __init__(self): def __init__(self, theme=core.theme.Theme()):
self._modules = [] self._modules = []
self._status = {} self._status = {}

6
core/theme.py Normal file
View file

@ -0,0 +1,6 @@
class Theme(object):
def __init__(self, name='default', iconset=None):
pass
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -4,19 +4,18 @@ import core.config
class config(unittest.TestCase): class config(unittest.TestCase):
def setUp(self): def setUp(self):
self._someModules = [ 'b', 'x', 'a' ] self.someModules = [ 'b', 'x', 'a' ]
self._moreModules = [ 'this', 'module', 'here' ] self.moreModules = [ 'this', 'module', 'here' ]
self.someTheme = 'some-theme'
def tearDown(self): self.someIconset = 'some-iconset'
pass
def test_module(self): def test_module(self):
cfg = core.config.Config([ '-m' ] + self._someModules) cfg = core.config.Config([ '-m' ] + self.someModules)
self.assertEqual(self._someModules, cfg.modules()) self.assertEqual(self.someModules, cfg.modules())
def test_module_ordering_maintained(self): def test_module_ordering_maintained(self):
cfg = core.config.Config([ '-m' ] + self._someModules + [ '-m' ] + self._moreModules) cfg = core.config.Config([ '-m' ] + self.someModules + [ '-m' ] + self.moreModules)
self.assertEqual(self._someModules + self._moreModules, cfg.modules()) self.assertEqual(self.someModules + self.moreModules, cfg.modules())
def test_default_interval(self): def test_default_interval(self):
cfg = core.config.Config([]) cfg = core.config.Config([])
@ -30,4 +29,20 @@ class config(unittest.TestCase):
cfg = core.config.Config([ '-p', 'interval=0.5']) cfg = core.config.Config([ '-p', 'interval=0.5'])
self.assertEqual(0.5, cfg.interval()) 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 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4