diff options
| author | kozova1 <mug66kk@gmail.com> | 2020-12-05 18:27:55 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-12-13 16:51:07 (GMT) |
| commit | 2624a6e998f7b5a78a38fa98be15bf3d25ed81a9 (patch) | |
| tree | 932437f9d64c3ca21745deacce570224c240a8de /wasp/wasp.py | |
| parent | 784c9bb36d29457ddb3a5ef5af55918e1f4cd93c (diff) | |
Added basic theming engine.
This theming engine uses a bytestring (but supports anything indexable,
as long as the index results are a byte long),
stored as `wasp.system._theme`.
It has a default value, which should not change anything about the way this looks currently.
The theme can be set via `wasp.system.set_theme`,
but this should *ONLY* be used in `main.py`.
`wasp.system.set_theme` will return True if it was successful,
or False if the theme is of an old format.
Using an old format theme will *not* crash the watch,
but will use the default theme instead.
To theme this, one has to use tools/themer.py (use flag -h for complete explanation)
to generate a bytestring that's added in main.py (see diff).
The bytestring is then loaded into 'wasp.system._theme'.
Theme values can be looked up by apps by using `wasp.system.theme("theme-key")`.
Theme keys appear in the function body of `wasp.system.theme()`.
I've took the liberty of converting existing apps to use this method,
and it seems to work well.
A test theme is provided in `tools/test_theme.py`
Signed-off-by: kozova1 <mug66kk@gmail.com>
Diffstat (limited to 'wasp/wasp.py')
| -rw-r--r-- | wasp/wasp.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/wasp/wasp.py b/wasp/wasp.py index 7cf2883..4837e12 100644 --- a/wasp/wasp.py +++ b/wasp/wasp.py @@ -14,7 +14,6 @@ wasp.watch is an import of :py:mod:`watch` and is simply provided as a shortcut (and to reduce memory by keeping it out of other namespaces). """ - import gc import machine import micropython @@ -118,6 +117,8 @@ class Manager(): self.musicstate = {} self.musicinfo = {} + self._theme = b'\xef{\xef{\xef{<\xe7\xef{\xb6\xb5\xb6\xbd\xff\xff\xff9' + self.blank_after = 15 self._alarms = [] @@ -514,4 +515,30 @@ class Manager(): self._scheduling = enable + def set_theme(self, new_theme) -> bool: + """Sets the system theme. + + Accepts anything that supports indexing, + and has a len() equivalent to the default theme.""" + if len(self._theme) != len(new_theme): + return False + self._theme = new_theme + return True + + def theme(self, theme_part: str) -> int: + """Returns the relevant part of theme. For more see ../tools/themer.py""" + theme_parts = ("ble", + "scroll-indicator", + "battery-charging", + "status-clock", + "notify-icon", + "accent-mid", + "accent-lo", + "accent-hi", + "slider-default") + if theme_part not in theme_parts: + raise IndexError('Theme part {} does not exist'.format(theme_part)) + idx = theme_parts.index(theme_part) * 2 + return self._theme[idx] | (self._theme[idx+1] << 8) + system = Manager() |
