From 23368a659b6fcd69b62e2024dacb18bdf8146840 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Fri, 10 Apr 2020 20:30:20 +0100 Subject: [PATCH] wasp: apps: Add a new (super simple) settings app --- wasp/apps/settings.py | 40 ++++++++++++++++++++++++++++++++ wasp/boards/pinetime/manifest.py | 1 + wasp/wasp.py | 2 ++ 3 files changed, 43 insertions(+) create mode 100644 wasp/apps/settings.py diff --git a/wasp/apps/settings.py b/wasp/apps/settings.py new file mode 100644 index 0000000..6a268a9 --- /dev/null +++ b/wasp/apps/settings.py @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# Copyright (C) 2020 Daniel Thompson +"""Ultra-simple settings application. + +Currently the settings application contains only one setting: brightness +""" + +import wasp +import icons + +class SettingsApp(): + NAME = 'Settings' + ICON = icons.settings + + def foreground(self): + self._draw() + wasp.system.request_event(wasp.EventMask.TOUCH) + + def touch(self, event): + brightness = wasp.system.brightness + 1 + if brightness > 3: + brightness = 1 + wasp.system.brightness = brightness + self._update() + + def _draw(self): + """Redraw the display from scratch.""" + wasp.watch.drawable.fill() + wasp.watch.drawable.string('Settings', 0, 6, width=240) + wasp.watch.drawable.string('Brightness', 0, 120 - 3 - 24, width=240) + self._update() + + def _update(self): + if wasp.system.brightness == 3: + say = "High" + elif wasp.system.brightness == 2: + say = "Mid" + else: + say = "Low" + wasp.watch.drawable.string(say, 0, 120 + 3, width=240) diff --git a/wasp/boards/pinetime/manifest.py b/wasp/boards/pinetime/manifest.py index 30d54e2..3d8cd9a 100644 --- a/wasp/boards/pinetime/manifest.py +++ b/wasp/boards/pinetime/manifest.py @@ -7,6 +7,7 @@ freeze('../..', 'apps/clock.py', 'apps/flashlight.py', 'apps/launcher.py', + 'apps/settings.py', 'apps/testapp.py', 'boot.py', 'demo.py', diff --git a/wasp/wasp.py b/wasp/wasp.py index 6016bd5..d336729 100644 --- a/wasp/wasp.py +++ b/wasp/wasp.py @@ -16,6 +16,7 @@ import widgets from apps.clock import ClockApp from apps.flashlight import FlashlightApp from apps.launcher import LauncherApp +from apps.settings import SettingsApp from apps.testapp import TestApp class EventType(): @@ -95,6 +96,7 @@ class Manager(): # TODO: Eventually these should move to main.py self.register(ClockApp(), True) self.register(FlashlightApp(), True) + self.register(SettingsApp(), True) self.register(TestApp(), True) def register(self, app, quick_ring=True):