2020-04-10 21:30:20 +02:00
|
|
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
2021-01-12 21:27:52 +01:00
|
|
|
# Copyright (C) 2020-21 Daniel Thompson
|
2020-04-10 21:30:20 +02:00
|
|
|
|
|
|
|
import wasp
|
2021-01-12 21:27:52 +01:00
|
|
|
import fonts
|
2020-04-10 21:30:20 +02:00
|
|
|
import icons
|
|
|
|
|
|
|
|
class SettingsApp():
|
2020-08-16 19:48:15 +02:00
|
|
|
"""Ultra-simple settings application.
|
|
|
|
|
|
|
|
Currently the settings application contains only one setting: brightness
|
|
|
|
|
|
|
|
.. figure:: res/SettingsApp.png
|
|
|
|
:width: 179
|
|
|
|
|
|
|
|
Screenshot of the settings application
|
|
|
|
"""
|
2020-04-10 21:30:20 +02:00
|
|
|
NAME = 'Settings'
|
|
|
|
ICON = icons.settings
|
|
|
|
|
2020-05-24 15:20:20 +02:00
|
|
|
def __init__(self):
|
|
|
|
self._slider = wasp.widgets.Slider(3, 10, 90)
|
2020-10-27 18:10:56 +01:00
|
|
|
self._nfy_slider = wasp.widgets.Slider(3, 10, 90)
|
2020-12-05 13:49:56 +01:00
|
|
|
self._scroll_indicator = wasp.widgets.ScrollIndicator()
|
2021-01-12 21:27:52 +01:00
|
|
|
self._HH = wasp.widgets.Spinner(50, 60, 0, 23, 2)
|
|
|
|
self._MM = wasp.widgets.Spinner(130, 60, 0, 59, 2)
|
|
|
|
self._dd = wasp.widgets.Spinner(20, 60, 1, 31, 1)
|
|
|
|
self._mm = wasp.widgets.Spinner(90, 60, 1, 12, 1)
|
|
|
|
self._yy = wasp.widgets.Spinner(160, 60, 20, 99, 2)
|
|
|
|
self._settings = ['Brightness', 'Notification Level', 'Time', 'Date']
|
2020-10-27 18:10:56 +01:00
|
|
|
self._sett_index = 0
|
|
|
|
self._current_setting = self._settings[0]
|
2020-05-24 15:20:20 +02:00
|
|
|
|
2020-04-10 21:30:20 +02:00
|
|
|
def foreground(self):
|
2020-11-26 22:23:38 +01:00
|
|
|
self._slider.value = wasp.system.brightness - 1
|
2020-04-10 21:30:20 +02:00
|
|
|
self._draw()
|
|
|
|
wasp.system.request_event(wasp.EventMask.TOUCH)
|
2020-10-27 18:10:56 +01:00
|
|
|
wasp.system.request_event(wasp.EventMask.SWIPE_UPDOWN)
|
2020-04-10 21:30:20 +02:00
|
|
|
|
|
|
|
def touch(self, event):
|
2020-10-27 18:10:56 +01:00
|
|
|
if self._current_setting == 'Brightness':
|
|
|
|
self._slider.touch(event)
|
|
|
|
wasp.system.brightness = self._slider.value + 1
|
|
|
|
elif self._current_setting == 'Notification Level':
|
|
|
|
self._nfy_slider.touch(event)
|
|
|
|
wasp.system.notify_level = self._nfy_slider.value + 1
|
2021-01-12 21:27:52 +01:00
|
|
|
elif self._current_setting == 'Time':
|
|
|
|
if self._HH.touch(event) or self._MM.touch(event):
|
|
|
|
now = list(wasp.watch.rtc.get_localtime())
|
|
|
|
now[3] = self._HH.value
|
|
|
|
now[4] = self._MM.value
|
|
|
|
wasp.watch.rtc.set_localtime(now)
|
|
|
|
elif self._current_setting == 'Date':
|
|
|
|
if self._yy.touch(event) or self._mm.touch(event) \
|
|
|
|
or self._dd.touch(event):
|
|
|
|
now = list(wasp.watch.rtc.get_localtime())
|
|
|
|
now[0] = self._yy.value + 2000
|
|
|
|
now[1] = self._mm.value
|
|
|
|
now[2] = self._dd.value
|
|
|
|
wasp.watch.rtc.set_localtime(now)
|
2020-04-10 21:30:20 +02:00
|
|
|
self._update()
|
|
|
|
|
2020-10-27 18:10:56 +01:00
|
|
|
def swipe(self, event):
|
|
|
|
"""Handle NEXT events by augmenting the default processing by resetting
|
|
|
|
the count if we are not currently timing something.
|
|
|
|
|
|
|
|
No other swipe event is possible for this application.
|
|
|
|
"""
|
|
|
|
if event[0] == wasp.EventType.UP:
|
|
|
|
self._sett_index += 1
|
|
|
|
self._draw()
|
|
|
|
elif event[0] == wasp.EventType.DOWN:
|
|
|
|
self._sett_index -= 1
|
|
|
|
self._draw()
|
|
|
|
|
2020-04-10 21:30:20 +02:00
|
|
|
def _draw(self):
|
|
|
|
"""Redraw the display from scratch."""
|
2021-01-03 15:47:23 +01:00
|
|
|
draw = wasp.watch.drawable
|
2021-01-12 21:27:52 +01:00
|
|
|
mute = wasp.watch.display.mute
|
2020-10-27 18:10:56 +01:00
|
|
|
self._current_setting = self._settings[self._sett_index % len(self._settings)]
|
2021-01-12 21:27:52 +01:00
|
|
|
mute(True)
|
2021-01-03 15:47:23 +01:00
|
|
|
draw.fill()
|
|
|
|
draw.set_color(wasp.system.theme('bright'))
|
2021-01-12 21:27:52 +01:00
|
|
|
draw.set_font(fonts.sans24)
|
2021-01-03 15:47:23 +01:00
|
|
|
draw.string(self._current_setting, 0, 6, width=240)
|
2020-10-27 18:10:56 +01:00
|
|
|
if self._current_setting == 'Brightness':
|
|
|
|
self._slider.value = wasp.system.brightness - 1
|
|
|
|
elif self._current_setting == 'Notification Level':
|
|
|
|
self._nfy_slider.value = wasp.system.notify_level - 1
|
2021-01-12 21:27:52 +01:00
|
|
|
elif self._current_setting == 'Time':
|
|
|
|
now = wasp.watch.rtc.get_localtime()
|
|
|
|
self._HH.value = now[3]
|
|
|
|
self._MM.value = now[4]
|
|
|
|
draw.set_font(fonts.sans28)
|
|
|
|
draw.string(':', 110, 120-14, width=20)
|
|
|
|
self._HH.draw()
|
|
|
|
self._MM.draw()
|
|
|
|
elif self._current_setting == 'Date':
|
|
|
|
now = wasp.watch.rtc.get_localtime()
|
|
|
|
self._yy.value = now[0] - 2000
|
|
|
|
self._mm.value = now[1]
|
|
|
|
self._dd.value = now[2]
|
|
|
|
self._yy.draw()
|
|
|
|
self._mm.draw()
|
|
|
|
self._dd.draw()
|
|
|
|
self._scroll_indicator.draw()
|
2020-04-10 21:30:20 +02:00
|
|
|
self._update()
|
2021-01-12 21:27:52 +01:00
|
|
|
mute(False)
|
2020-04-10 21:30:20 +02:00
|
|
|
|
|
|
|
def _update(self):
|
2021-01-03 15:47:23 +01:00
|
|
|
draw = wasp.watch.drawable
|
2021-01-12 21:27:52 +01:00
|
|
|
draw.set_color(wasp.system.theme('bright'))
|
2020-10-27 18:10:56 +01:00
|
|
|
if self._current_setting == 'Brightness':
|
|
|
|
if wasp.system.brightness == 3:
|
|
|
|
say = "High"
|
|
|
|
elif wasp.system.brightness == 2:
|
|
|
|
say = "Mid"
|
|
|
|
else:
|
|
|
|
say = "Low"
|
|
|
|
self._slider.update()
|
2021-01-12 21:27:52 +01:00
|
|
|
draw.string(say, 0, 150, width=240)
|
2020-10-27 18:10:56 +01:00
|
|
|
elif self._current_setting == 'Notification Level':
|
|
|
|
if wasp.system.notify_level == 3:
|
|
|
|
say = "High"
|
|
|
|
elif wasp.system.notify_level == 2:
|
|
|
|
say = "Mid"
|
|
|
|
else:
|
|
|
|
say = "Silent"
|
|
|
|
self._nfy_slider.update()
|
2021-01-12 21:27:52 +01:00
|
|
|
draw.string(say, 0, 150, width=240)
|