diff options
| author | xj9 <xj9@sunshinegardens.org> | 2020-09-18 12:14:39 -0600 |
|---|---|---|
| committer | xj9 <xj9@sunshinegardens.org> | 2020-09-18 12:20:39 -0600 |
| commit | 767a18e3ab7f6342c922f99a7c07e6e6606967f6 (patch) | |
| tree | b2be3321fe38d57ad111f0ad9c7f5deba7608fe5 | |
| parent | bcf8c0c32f176eaebd1c1ac031835f375b388b8d (diff) | |
add theme parser tool (python)
```
cd tools
python
>>> import themes
>>> theme = themes.parse_theme('../themes/orca.svg')
assert theme.background == '#000000'
assert theme.f_high == '#ffffff'
assert theme.f_med == '#777777'
assert theme.f_low == '#444444'
assert theme.f_inv == '#000000'
assert theme.b_high == '#dddddd'
assert theme.b_med == '#72dec2'
assert theme.b_low == '#222222'
assert theme.b_inv == '#ffb545'
```
| -rw-r--r-- | tools/themes.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/themes.py b/tools/themes.py new file mode 100644 index 0000000..d516727 --- /dev/null +++ b/tools/themes.py @@ -0,0 +1,34 @@ +""" +Nine colors should be more than enough for any interface. +""" +import xml.sax + +class ThemeHandler(xml.sax.ContentHandler): + def __init__(self): + self.background = None + self.f_high = None + self.f_med = None + self.f_low = None + self.f_inv = None + self.b_high = None + self.b_med = None + self.b_low = None + self.b_inv = None + + def parseColor(self, attrs): + data = {k: v for k, v in attrs.items()} + if data.get('id') and data.get('fill'): + setattr(self, data['id'], data['fill']) + + def startElement(self, name, attrs): + if name in ('circle', 'rect'): + self.parseColor(attrs) + + +def parse_theme(path): + theme = ThemeHandler() + parser = xml.sax.make_parser() + parser.setContentHandler(theme) + with open(path, 'r') as fd: + parser.parse(fd) + return theme |
