[core/theme] Add simple theme stub
Add support for default fg/bg colors
This commit is contained in:
parent
99cca7002c
commit
affeba5b8f
4 changed files with 75 additions and 2 deletions
|
@ -8,6 +8,7 @@ class i3(object):
|
||||||
def __init__(self, theme=core.theme.Theme()):
|
def __init__(self, theme=core.theme.Theme()):
|
||||||
self._modules = []
|
self._modules = []
|
||||||
self._status = {}
|
self._status = {}
|
||||||
|
self._theme = theme
|
||||||
|
|
||||||
def modules(self, modules=None):
|
def modules(self, modules=None):
|
||||||
if not modules:
|
if not modules:
|
||||||
|
@ -40,6 +41,8 @@ class i3(object):
|
||||||
'full_text': widget.full_text(),
|
'full_text': widget.full_text(),
|
||||||
'instance': widget.id(),
|
'instance': widget.id(),
|
||||||
'name': module.id(),
|
'name': module.id(),
|
||||||
|
'color': self._theme.fg(widget),
|
||||||
|
'background': self._theme.bg(widget),
|
||||||
})
|
})
|
||||||
return widgets
|
return widgets
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,41 @@
|
||||||
|
import os
|
||||||
|
import io
|
||||||
|
import json
|
||||||
|
|
||||||
|
THEME_BASE_DIR=os.path.dirname(os.path.realpath(__file__))
|
||||||
|
PATHS=[
|
||||||
|
'.',
|
||||||
|
os.path.join(THEME_BASE_DIR, '../themes'),
|
||||||
|
os.path.expanduser('~/.config/bumblebee-status/themes'),
|
||||||
|
]
|
||||||
|
|
||||||
class Theme(object):
|
class Theme(object):
|
||||||
def __init__(self, name='default', iconset=None):
|
def __init__(self, name='default', iconset=None, raw_data=None):
|
||||||
pass
|
self.name = name
|
||||||
|
if raw_data:
|
||||||
|
self._data = raw_data
|
||||||
|
else:
|
||||||
|
self._data = self.load(name)
|
||||||
|
|
||||||
|
def load(self, name):
|
||||||
|
for path in PATHS:
|
||||||
|
theme_file = os.path.join(path, '{}.json'.format(name))
|
||||||
|
if os.path.isfile(theme_file):
|
||||||
|
with io.open(theme_file, encoding='utf-8') as data:
|
||||||
|
return json.load(data)
|
||||||
|
raise RuntimeError('unable to find theme {}'.format(name))
|
||||||
|
|
||||||
|
def fg(self, widget=None):
|
||||||
|
return self.__get(widget, 'fg')
|
||||||
|
|
||||||
|
def bg(self, widget=None):
|
||||||
|
return self.__get(widget, 'bg')
|
||||||
|
|
||||||
|
def __get(self, widget, key, default=None):
|
||||||
|
value = default
|
||||||
|
if 'defaults' in self._data:
|
||||||
|
value = self._data['defaults'].get(key, value)
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
28
tests/core/test_theme.py
Normal file
28
tests/core/test_theme.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import core.theme
|
||||||
|
|
||||||
|
class theme(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.invalidThemeName = 'this-theme-does-not-exist'
|
||||||
|
self.validThemeName = 'default'
|
||||||
|
self.defaults = {
|
||||||
|
'defaults': {
|
||||||
|
'fg': 'red', 'bg': 'black'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_invalid_theme(self):
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
core.theme.Theme(self.invalidThemeName)
|
||||||
|
|
||||||
|
def test_valid_theme(self):
|
||||||
|
theme = core.theme.Theme(self.validThemeName)
|
||||||
|
self.assertEqual(self.validThemeName, theme.name)
|
||||||
|
|
||||||
|
def test_defaults(self):
|
||||||
|
theme = core.theme.Theme(raw_data=self.defaults)
|
||||||
|
self.assertEqual(self.defaults['defaults']['fg'], theme.fg())
|
||||||
|
self.assertEqual(self.defaults['defaults']['bg'], theme.bg())
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
7
themes/default.json
Normal file
7
themes/default.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"icons": [ "ascii" ],
|
||||||
|
"defaults": {
|
||||||
|
"urgent": true,
|
||||||
|
"fg": "#aabbcc"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue