summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorkozova1 <mug66kk@gmail.com>2020-12-05 18:27:55 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-12-13 16:51:07 (GMT)
commit2624a6e998f7b5a78a38fa98be15bf3d25ed81a9 (patch)
tree932437f9d64c3ca21745deacce570224c240a8de /tools
parent784c9bb36d29457ddb3a5ef5af55918e1f4cd93c (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 'tools')
-rw-r--r--tools/test_theme.py15
-rwxr-xr-xtools/themer.py81
2 files changed, 96 insertions, 0 deletions
diff --git a/tools/test_theme.py b/tools/test_theme.py
new file mode 100644
index 0000000..dc2b990
--- /dev/null
+++ b/tools/test_theme.py
@@ -0,0 +1,15 @@
+from themer import DefaultTheme
+
+class Theme(DefaultTheme):
+ # These colors were chosen specifically because they're hard to miss.
+ # Using this theme on an actual device is not advised
+ # The default theme was generated by removing all the lines below and adding `pass` instead.
+ BLE_COLOR = 0xfb80
+ SCROLL_INDICATOR_COLOR = 0xf800
+ BATTERY_CHARGING_COLOR = 0x07ff
+ SMALL_CLOCK_COLOR = 0x599f
+ NOTIFICATION_COLOR = 0x8fe0
+ ACCENT_MID = 0xf800
+ ACCENT_LO = 0x001f
+ ACCENT_HI = 0x07e0
+ SLIDER_DEFAULT_COLOR = 0x7777
diff --git a/tools/themer.py b/tools/themer.py
new file mode 100755
index 0000000..819c35c
--- /dev/null
+++ b/tools/themer.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python3
+"""Compiles themes for wasp-os"""
+
+from argparse import ArgumentParser, RawTextHelpFormatter
+from importlib import import_module
+from typing import Tuple
+
+class DefaultTheme():
+ """This represents the default theme.
+
+ Import this file and extend the Theme class, only changing the variables.
+ Export the resulting class as 'Theme'.
+ serialize() should NEVER be overriden!
+ """
+ BLE_COLOR = 0x7bef
+ SCROLL_INDICATOR_COLOR = 0x7bef
+ BATTERY_CHARGING_COLOR = 0x7bef
+ SMALL_CLOCK_COLOR = 0xe73c
+ NOTIFICATION_COLOR = 0x7bef
+ ACCENT_MID = 0xb5b6
+ ACCENT_LO = 0xbdb6
+ ACCENT_HI = 0xffff
+ SLIDER_DEFAULT_COLOR = 0x39ff
+
+ def serialize(self) -> bytes:
+ """Serializes the theme for use in wasp-os"""
+ def split_bytes(x: int) -> Tuple[int, int]:
+ return (x & 0xFF, (x >> 8) & 0xFF)
+ theme_bytes = bytes([
+ *split_bytes(self.BLE_COLOR),
+ *split_bytes(self.SCROLL_INDICATOR_COLOR),
+ *split_bytes(self.BATTERY_CHARGING_COLOR),
+ *split_bytes(self.SMALL_CLOCK_COLOR),
+ *split_bytes(self.NOTIFICATION_COLOR),
+ *split_bytes(self.ACCENT_MID),
+ *split_bytes(self.ACCENT_LO),
+ *split_bytes(self.ACCENT_HI),
+ *split_bytes(self.SLIDER_DEFAULT_COLOR),
+ ])
+ return theme_bytes
+
+
+if __name__ == '__main__':
+ parser = ArgumentParser(
+ description='''Compiles themes into a format understood by wasp-os.
+ The resulting string should be put in main.py like this:
+
+ theme_string = THEME_STRING_GOES_HERE
+
+ for the theme to take effect.
+ ''',
+ epilog=''' To create a theme,
+ import this file and extend the DefaultTheme class, only changing the variables.
+ Export the resulting class as 'Theme'.
+ Example:
+ --------
+ theme.py:
+ from themer import DefaultTheme
+
+ class Theme(DefaultTheme):
+ BLE_ICON_COLOR = 0x041F
+
+ shell:
+ $ ./themer.py theme # NOTE: do not include .py at end of file!
+ > b'\xef{\xef{\xef{<\xe7\xef{\xb6\xb5\xb6\xbd\xff\xff\xff9'
+
+ main.py:
+ ...
+ wasp.system.set_theme(b'\xef{\xef{\xef{<\xe7\xef{\xb6\xb5\xb6\xbd\xff\xff\xff9')
+ ...
+ ''',
+ formatter_class=RawTextHelpFormatter
+ )
+
+ parser.add_argument('input_file', type=str, nargs=1)
+ args = parser.parse_args()
+
+ theme = DefaultTheme()
+ theme = import_module(args.input_file[0]).Theme()
+ print(theme.serialize())
+