2020-03-22 16:40:18 +01:00
|
|
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
# Copyright (C) 2020 Daniel Thompson
|
|
|
|
|
2020-05-14 23:29:35 +02:00
|
|
|
"""Widget library
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
The widget library allows common fragments of logic and drawing code to be
|
|
|
|
shared between applications.
|
|
|
|
"""
|
|
|
|
|
2020-10-21 22:08:12 +02:00
|
|
|
import fonts
|
2020-02-03 23:35:16 +01:00
|
|
|
import icons
|
2020-07-19 21:50:33 +02:00
|
|
|
import wasp
|
2020-02-03 23:35:16 +01:00
|
|
|
import watch
|
2020-10-21 22:08:12 +02:00
|
|
|
|
2020-05-24 15:20:02 +02:00
|
|
|
from micropython import const
|
2020-02-03 23:35:16 +01:00
|
|
|
|
2020-07-19 21:50:33 +02:00
|
|
|
class BatteryMeter:
|
2020-05-14 23:29:35 +02:00
|
|
|
"""Battery meter widget.
|
|
|
|
|
|
|
|
A simple battery meter with a charging indicator, will draw at the
|
|
|
|
top-right of the display.
|
|
|
|
"""
|
2020-02-03 23:35:16 +01:00
|
|
|
def __init__(self):
|
2020-02-04 09:43:49 +01:00
|
|
|
self.level = -2
|
2020-02-03 23:35:16 +01:00
|
|
|
|
|
|
|
def draw(self):
|
2020-05-14 23:29:35 +02:00
|
|
|
"""Draw from meter (from scratch)."""
|
2020-02-04 09:43:49 +01:00
|
|
|
self.level = -2
|
2020-02-03 23:35:16 +01:00
|
|
|
self.update()
|
2020-04-05 10:48:03 +02:00
|
|
|
|
2020-02-03 23:35:16 +01:00
|
|
|
def update(self):
|
2020-05-14 23:29:35 +02:00
|
|
|
"""Update the meter.
|
|
|
|
|
|
|
|
The update is lazy and won't redraw unless the level has changed.
|
|
|
|
"""
|
2020-02-04 09:43:49 +01:00
|
|
|
icon = icons.battery
|
2020-03-09 01:00:13 +01:00
|
|
|
draw = watch.drawable
|
2020-02-04 09:43:49 +01:00
|
|
|
|
2020-02-03 23:35:16 +01:00
|
|
|
if watch.battery.charging():
|
|
|
|
if self.level != -1:
|
2020-12-28 12:12:16 +01:00
|
|
|
draw.blit(icon, 239-icon[1], 0,
|
2020-12-13 17:46:19 +01:00
|
|
|
fg=wasp.system.theme('battery'))
|
2020-02-03 23:35:16 +01:00
|
|
|
self.level = -1
|
|
|
|
else:
|
|
|
|
level = watch.battery.level()
|
|
|
|
if level == self.level:
|
|
|
|
return
|
|
|
|
|
2020-02-04 09:43:49 +01:00
|
|
|
|
2020-12-28 12:12:16 +01:00
|
|
|
green = level // 3
|
|
|
|
if green > 31:
|
|
|
|
green = 31
|
|
|
|
red = 31-green
|
|
|
|
rgb = (red << 11) + (green << 6)
|
2020-02-03 23:35:16 +01:00
|
|
|
|
2020-10-21 22:09:43 +02:00
|
|
|
if self.level < 0 or ((level > 5) ^ (self.level > 5)):
|
2020-02-04 09:43:49 +01:00
|
|
|
if level > 5:
|
2020-12-28 12:12:16 +01:00
|
|
|
draw.blit(icon, 239-icon[1], 0,
|
2020-12-13 17:46:19 +01:00
|
|
|
fg=wasp.system.theme('battery'))
|
2020-02-04 09:43:49 +01:00
|
|
|
else:
|
|
|
|
rgb = 0xf800
|
2020-12-28 12:12:16 +01:00
|
|
|
draw.blit(icon, 239-icon[1], 0, fg=0xf800)
|
2020-02-04 09:43:49 +01:00
|
|
|
|
2020-12-28 12:12:16 +01:00
|
|
|
w = icon[1] - 10
|
|
|
|
x = 239 - 5 - w
|
|
|
|
h = 2*level // 11
|
|
|
|
if 18 - h:
|
|
|
|
draw.fill(0, x, 9, w, 18 - h)
|
2020-02-03 23:35:16 +01:00
|
|
|
if h:
|
2020-12-28 12:12:16 +01:00
|
|
|
draw.fill(rgb, x, 27 - h, w, h)
|
2020-02-03 23:35:16 +01:00
|
|
|
|
2020-02-04 09:43:49 +01:00
|
|
|
self.level = level
|
2020-04-05 10:48:03 +02:00
|
|
|
|
2020-10-21 22:08:12 +02:00
|
|
|
class Clock:
|
|
|
|
"""Small clock widget."""
|
|
|
|
def __init__(self, enabled=True):
|
|
|
|
self.on_screen = None
|
|
|
|
self.enabled = enabled
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
"""Redraw the clock from scratch.
|
|
|
|
|
|
|
|
The container is required to clear the canvas prior to the redraw
|
|
|
|
and the clock is only drawn if it is enabled.
|
|
|
|
"""
|
|
|
|
self.on_screen = None
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update the clock widget if needed.
|
|
|
|
|
|
|
|
This is a lazy update that only redraws if the time has changes
|
|
|
|
since the last call *and* the clock is enabled.
|
|
|
|
|
|
|
|
:returns: An time tuple if the time has changed since the last call,
|
|
|
|
None otherwise.
|
|
|
|
"""
|
|
|
|
now = wasp.watch.rtc.get_localtime()
|
|
|
|
on_screen = self.on_screen
|
|
|
|
|
|
|
|
if on_screen and on_screen == now:
|
|
|
|
return None
|
|
|
|
|
2020-11-22 10:27:14 +01:00
|
|
|
if self.enabled and (not on_screen
|
|
|
|
or now[4] != on_screen[4] or now[3] != on_screen[3]):
|
2020-10-21 22:08:12 +02:00
|
|
|
t1 = '{:02}:{:02}'.format(now[3], now[4])
|
|
|
|
|
|
|
|
draw = wasp.watch.drawable
|
|
|
|
draw.set_font(fonts.sans28)
|
2020-12-05 19:27:55 +01:00
|
|
|
draw.set_color(wasp.system.theme('status-clock'))
|
2020-12-28 12:12:16 +01:00
|
|
|
draw.string(t1, 52, 4, 138)
|
2020-10-21 22:08:12 +02:00
|
|
|
|
|
|
|
self.on_screen = now
|
|
|
|
return now
|
|
|
|
|
2020-10-20 19:56:08 +02:00
|
|
|
class NotificationBar:
|
2020-07-24 18:04:46 +02:00
|
|
|
"""Show BT status and if there are pending notifications."""
|
2020-12-28 12:12:16 +01:00
|
|
|
def __init__(self, x=0, y=0):
|
2020-07-19 21:50:33 +02:00
|
|
|
self._pos = (x, y)
|
|
|
|
|
|
|
|
def draw(self):
|
2020-10-21 22:28:09 +02:00
|
|
|
"""Redraw the notification widget.
|
2020-07-19 21:50:33 +02:00
|
|
|
|
|
|
|
For this simple widget :py:meth:`~.draw` is simply a synonym for
|
2020-10-21 22:28:09 +02:00
|
|
|
:py:meth:`~.update` because we unconditionally update from scratch.
|
2020-07-19 21:50:33 +02:00
|
|
|
"""
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update the widget.
|
2020-10-21 22:28:09 +02:00
|
|
|
|
|
|
|
This widget does not implement lazy redraw internally since this
|
|
|
|
can often be implemented (with less state) by the container.
|
2020-07-19 21:50:33 +02:00
|
|
|
"""
|
|
|
|
draw = watch.drawable
|
|
|
|
(x, y) = self._pos
|
|
|
|
|
2020-07-24 18:04:46 +02:00
|
|
|
if wasp.watch.connected():
|
2020-12-05 19:27:55 +01:00
|
|
|
draw.blit(icons.blestatus, x, y, fg=wasp.system.theme('ble'))
|
2020-07-24 18:04:46 +02:00
|
|
|
if wasp.system.notifications:
|
2020-12-05 19:27:55 +01:00
|
|
|
draw.blit(icons.notification, x+22, y,
|
|
|
|
fg=wasp.system.theme('notify-icon'))
|
2020-07-24 18:04:46 +02:00
|
|
|
else:
|
2020-10-21 22:28:09 +02:00
|
|
|
draw.fill(0, x+22, y, 30, 32)
|
2020-07-24 18:04:46 +02:00
|
|
|
elif wasp.system.notifications:
|
2020-12-05 19:27:55 +01:00
|
|
|
draw.blit(icons.notification, x, y,
|
|
|
|
fg=wasp.system.theme('notify-icon'))
|
2020-10-21 22:28:09 +02:00
|
|
|
draw.fill(0, x+30, y, 22, 32)
|
2020-07-19 21:50:33 +02:00
|
|
|
else:
|
2020-10-21 22:28:09 +02:00
|
|
|
draw.fill(0, x, y, 52, 32)
|
|
|
|
|
|
|
|
class StatusBar:
|
|
|
|
"""Combo widget to handle notification, time and battery level."""
|
|
|
|
def __init__(self):
|
|
|
|
self._clock = Clock()
|
|
|
|
self._meter = BatteryMeter()
|
|
|
|
self._notif = NotificationBar()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def clock(self):
|
|
|
|
"""True if the clock should be included in the status bar, False
|
|
|
|
otherwise.
|
|
|
|
"""
|
|
|
|
return self._clock.enabled
|
|
|
|
|
|
|
|
@clock.setter
|
|
|
|
def clock(self, enabled):
|
|
|
|
self._clock.enabled = enabled
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
"""Redraw the status bar from scratch."""
|
|
|
|
self._clock.draw()
|
|
|
|
self._meter.draw()
|
|
|
|
self._notif.draw()
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Lazily update the status bar.
|
|
|
|
|
|
|
|
:returns: An time tuple if the time has changed since the last call,
|
|
|
|
None otherwise.
|
|
|
|
"""
|
|
|
|
now = self._clock.update()
|
|
|
|
if now:
|
|
|
|
self._meter.update()
|
|
|
|
self._notif.update()
|
|
|
|
return now
|
2020-07-19 21:50:33 +02:00
|
|
|
|
|
|
|
class ScrollIndicator:
|
2020-05-14 23:29:35 +02:00
|
|
|
"""Scrolling indicator.
|
|
|
|
|
2020-10-10 22:36:26 +02:00
|
|
|
A pair of arrows that prompted the user to swipe up/down to access
|
|
|
|
additional pages of information.
|
2020-05-14 23:29:35 +02:00
|
|
|
"""
|
2020-04-05 10:48:03 +02:00
|
|
|
def __init__(self, x=240-18, y=240-24):
|
|
|
|
self._pos = (x, y)
|
|
|
|
self.up = True
|
|
|
|
self.down = True
|
|
|
|
|
|
|
|
def draw(self):
|
2020-05-14 23:29:35 +02:00
|
|
|
"""Draw from scrolling indicator.
|
|
|
|
|
|
|
|
For this simple widget :py:meth:`~.draw` is simply a synonym for
|
|
|
|
:py:meth:`~.update`.
|
|
|
|
"""
|
2020-04-05 10:48:03 +02:00
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
2020-05-14 23:29:35 +02:00
|
|
|
"""Update from scrolling indicator."""
|
2020-04-05 10:48:03 +02:00
|
|
|
draw = watch.drawable
|
2020-12-05 19:27:55 +01:00
|
|
|
color = wasp.system.theme('scroll-indicator')
|
|
|
|
|
2020-04-05 10:48:03 +02:00
|
|
|
if self.up:
|
2020-12-28 12:12:16 +01:00
|
|
|
draw.blit(icons.up_arrow, self._pos[0], self._pos[1], fg=color)
|
2020-04-05 10:48:03 +02:00
|
|
|
if self.down:
|
2020-12-28 12:12:16 +01:00
|
|
|
draw.blit(icons.down_arrow, self._pos[0], self._pos[1]+13, fg=color)
|
2020-05-24 15:20:02 +02:00
|
|
|
|
2021-01-10 11:30:27 +01:00
|
|
|
class Button():
|
|
|
|
"""A button with a text label."""
|
|
|
|
def __init__(self, x, y, w, h, label):
|
|
|
|
self._im = (x, y, w, h, label)
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
"""Draw the button."""
|
|
|
|
draw = wasp.watch.drawable
|
|
|
|
im = self._im
|
|
|
|
bg = draw.darken(wasp.system.theme('ui'))
|
|
|
|
frame = wasp.system.theme('mid')
|
|
|
|
txt = wasp.system.theme('bright')
|
|
|
|
|
|
|
|
draw.fill(bg, im[0], im[1], im[2], im[3])
|
|
|
|
draw.set_color(txt, bg)
|
|
|
|
draw.set_font(fonts.sans24)
|
|
|
|
draw.string(im[4], im[0], im[1]+(im[3]//2)-12, width=im[2])
|
|
|
|
|
|
|
|
draw.fill(frame, im[0],im[1], im[2], 2)
|
|
|
|
draw.fill(frame, im[0], im[1]+im[3]-2, im[2], 2)
|
|
|
|
draw.fill(frame, im[0], im[1], 2, im[3])
|
|
|
|
draw.fill(frame, im[0]+im[2]-2, im[1], 2, im[3])
|
|
|
|
|
|
|
|
def touch(self, event):
|
|
|
|
"""Handle touch events."""
|
|
|
|
x = event[1]
|
|
|
|
y = event[2]
|
|
|
|
|
|
|
|
# Adopt a slightly oversized hit box
|
|
|
|
im = self._im
|
|
|
|
x1 = im[0] - 10
|
|
|
|
x2 = x1 + im[2] + 20
|
|
|
|
y1 = im[1] - 10
|
|
|
|
y2 = y1 + im[3] + 20
|
|
|
|
|
|
|
|
if x >= x1 and x < x2 and y >= y1 and y < y2:
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2020-12-29 13:32:38 +01:00
|
|
|
class Checkbox():
|
|
|
|
"""A simple (labelled) checkbox."""
|
|
|
|
def __init__(self, x, y, label=None):
|
|
|
|
self._im = (x, y, label)
|
|
|
|
self.state = False
|
|
|
|
|
2021-01-03 15:50:04 +01:00
|
|
|
@property
|
|
|
|
def label(self):
|
|
|
|
return self._im[2]
|
|
|
|
|
2020-12-29 13:32:38 +01:00
|
|
|
def draw(self):
|
|
|
|
"""Draw the checkbox and label."""
|
|
|
|
draw = wasp.watch.drawable
|
|
|
|
im = self._im
|
|
|
|
if im[2]:
|
2021-01-03 15:48:19 +01:00
|
|
|
draw.set_color(wasp.system.theme('bright'))
|
2020-12-29 21:07:50 +01:00
|
|
|
draw.set_font(fonts.sans24)
|
2020-12-29 13:32:38 +01:00
|
|
|
draw.string(im[2], im[0], im[1]+6)
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Draw the checkbox."""
|
|
|
|
draw = wasp.watch.drawable
|
|
|
|
im = self._im
|
|
|
|
if self.state:
|
2020-12-31 20:12:38 +01:00
|
|
|
c1 = wasp.system.theme('ui')
|
|
|
|
c2 = draw.lighten(c1, wasp.system.theme('contrast'))
|
2020-12-29 13:32:38 +01:00
|
|
|
fg = c2
|
|
|
|
else:
|
|
|
|
c1 = 0
|
|
|
|
c2 = 0
|
2020-12-31 20:12:38 +01:00
|
|
|
fg = wasp.system.theme('mid')
|
2020-12-29 13:32:38 +01:00
|
|
|
# Draw checkbox on the right margin if there is a label, otherwise
|
|
|
|
# draw at the natural location
|
|
|
|
x = 239 - 32 - 4 if im[2] else im[0]
|
|
|
|
draw.blit(icons.checkbox, x, im[1], fg, c1, c2)
|
|
|
|
|
|
|
|
def touch(self, event):
|
|
|
|
"""Handle touch events."""
|
2020-12-29 21:07:50 +01:00
|
|
|
y = event[2]
|
2020-12-29 13:32:38 +01:00
|
|
|
im = self._im
|
|
|
|
if y >= im[1] and y < im[1]+40:
|
|
|
|
self.state = not self.state
|
|
|
|
self.update()
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2020-05-24 15:20:02 +02:00
|
|
|
_SLIDER_KNOB_DIAMETER = const(40)
|
|
|
|
_SLIDER_KNOB_RADIUS = const(_SLIDER_KNOB_DIAMETER // 2)
|
|
|
|
_SLIDER_WIDTH = const(220)
|
|
|
|
_SLIDER_TRACK = const(_SLIDER_WIDTH - _SLIDER_KNOB_DIAMETER)
|
|
|
|
_SLIDER_TRACK_HEIGHT = const(8)
|
|
|
|
_SLIDER_TRACK_Y1 = const(_SLIDER_KNOB_RADIUS - (_SLIDER_TRACK_HEIGHT // 2))
|
|
|
|
_SLIDER_TRACK_Y2 = const(_SLIDER_TRACK_Y1 + _SLIDER_TRACK_HEIGHT)
|
|
|
|
|
|
|
|
class Slider():
|
|
|
|
"""A slider to select values."""
|
2020-12-05 19:27:55 +01:00
|
|
|
def __init__(self, steps, x=10, y=90, color=None):
|
2020-05-24 15:20:02 +02:00
|
|
|
self.value = 0
|
|
|
|
self._steps = steps
|
|
|
|
self._stepsize = _SLIDER_TRACK / (steps-1)
|
|
|
|
self._x = x
|
|
|
|
self._y = y
|
|
|
|
self._color = color
|
2020-12-05 19:27:55 +01:00
|
|
|
self._lowlight = None
|
2020-05-24 15:20:02 +02:00
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
"""Draw the slider."""
|
|
|
|
draw = watch.drawable
|
|
|
|
x = self._x
|
|
|
|
y = self._y
|
|
|
|
color = self._color
|
2020-12-05 19:27:55 +01:00
|
|
|
if self._color is None:
|
2020-12-31 20:12:38 +01:00
|
|
|
self._color = wasp.system.theme('ui')
|
2020-12-05 19:27:55 +01:00
|
|
|
color = self._color
|
|
|
|
if self._lowlight is None:
|
2020-12-31 20:12:38 +01:00
|
|
|
self._lowlight = draw.lighten(color, wasp.system.theme('contrast'))
|
2020-05-24 15:20:02 +02:00
|
|
|
light = self._lowlight
|
|
|
|
|
|
|
|
knob_x = x + ((_SLIDER_TRACK * self.value) // (self._steps-1))
|
2020-06-04 23:57:50 +02:00
|
|
|
draw.blit(icons.knob, knob_x, y, color)
|
2020-05-24 15:20:02 +02:00
|
|
|
|
|
|
|
w = knob_x - x
|
|
|
|
if w > 0:
|
|
|
|
draw.fill(0, x, y, w, _SLIDER_TRACK_Y1)
|
|
|
|
if w > _SLIDER_KNOB_RADIUS:
|
|
|
|
draw.fill(0, x, y+_SLIDER_TRACK_Y1,
|
|
|
|
_SLIDER_KNOB_RADIUS, _SLIDER_TRACK_HEIGHT)
|
|
|
|
draw.fill(color, x+_SLIDER_KNOB_RADIUS, y+_SLIDER_TRACK_Y1,
|
|
|
|
w-_SLIDER_KNOB_RADIUS, _SLIDER_TRACK_HEIGHT)
|
|
|
|
else:
|
|
|
|
draw.fill(0, x, y+_SLIDER_TRACK_Y1, w, _SLIDER_TRACK_HEIGHT)
|
|
|
|
draw.fill(0, x, y+_SLIDER_TRACK_Y2, w, _SLIDER_TRACK_Y1)
|
|
|
|
|
|
|
|
sx = knob_x + _SLIDER_KNOB_DIAMETER
|
|
|
|
w = _SLIDER_WIDTH - _SLIDER_KNOB_DIAMETER - w
|
|
|
|
if w > 0:
|
|
|
|
draw.fill(0, sx, y, w, _SLIDER_TRACK_Y1)
|
|
|
|
if w > _SLIDER_KNOB_RADIUS:
|
|
|
|
draw.fill(0, sx+w-_SLIDER_KNOB_RADIUS, y+_SLIDER_TRACK_Y1,
|
|
|
|
_SLIDER_KNOB_RADIUS, _SLIDER_TRACK_HEIGHT)
|
|
|
|
draw.fill(light, sx, y+_SLIDER_TRACK_Y1,
|
|
|
|
w-_SLIDER_KNOB_RADIUS, _SLIDER_TRACK_HEIGHT)
|
|
|
|
else:
|
|
|
|
draw.fill(0, sx, y+_SLIDER_TRACK_Y1, w, _SLIDER_TRACK_HEIGHT)
|
|
|
|
draw.fill(0, sx, y+_SLIDER_TRACK_Y2, w, _SLIDER_TRACK_Y1)
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
self.draw()
|
|
|
|
|
|
|
|
def touch(self, event):
|
|
|
|
tx = event[1]
|
|
|
|
threshold = self._x + 20 - (self._stepsize / 2)
|
|
|
|
v = int((tx - threshold) / self._stepsize)
|
|
|
|
if v < 0:
|
|
|
|
v = 0
|
|
|
|
elif v >= self._steps:
|
|
|
|
v = self._steps - 1
|
|
|
|
self.value = v
|
2020-10-31 21:51:28 +01:00
|
|
|
|
2020-12-29 21:07:50 +01:00
|
|
|
class Spinner():
|
|
|
|
"""A simple Spinner widget.
|
|
|
|
|
|
|
|
In order to have large enough hit boxes the spinner is a fairly large
|
|
|
|
widget and requires 60x120 px.
|
|
|
|
"""
|
|
|
|
def __init__(self, x, y, mn, mx, field=1):
|
|
|
|
self._im = (x, y, mn, mx, field)
|
|
|
|
self.value = mn
|
|
|
|
|
|
|
|
def draw(self):
|
2021-01-12 21:22:44 +01:00
|
|
|
"""Draw the spinner."""
|
2020-12-29 21:07:50 +01:00
|
|
|
draw = watch.drawable
|
|
|
|
im = self._im
|
2020-12-31 20:12:38 +01:00
|
|
|
fg = draw.lighten(wasp.system.theme('ui'), wasp.system.theme('contrast'))
|
2020-12-29 21:07:50 +01:00
|
|
|
draw.blit(icons.up_arrow, im[0]+30-8, im[1]+20, fg)
|
|
|
|
draw.blit(icons.down_arrow, im[0]+30-8, im[1]+120-20-9, fg)
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update the spinner value."""
|
|
|
|
draw = watch.drawable
|
|
|
|
im = self._im
|
2021-01-03 15:48:19 +01:00
|
|
|
draw.set_color(wasp.system.theme('bright'))
|
2020-12-29 21:07:50 +01:00
|
|
|
draw.set_font(fonts.sans28)
|
|
|
|
s = str(self.value)
|
|
|
|
if len(s) < im[4]:
|
|
|
|
s = '0' * (im[4] - len(s)) + s
|
|
|
|
draw.string(s, im[0], im[1]+60-14, width=60)
|
|
|
|
|
|
|
|
def touch(self, event):
|
|
|
|
x = event[1]
|
|
|
|
y = event[2]
|
|
|
|
im = self._im
|
|
|
|
if x >= im[0] and x < im[0]+60 and y >= im[1] and y < im[1]+120:
|
|
|
|
if y < im[1] + 60:
|
|
|
|
self.value += 1
|
|
|
|
if self.value > im[3]:
|
|
|
|
self.value = im[2]
|
|
|
|
else:
|
|
|
|
self.value -= 1
|
|
|
|
if self.value < im[2]:
|
2021-01-12 21:22:44 +01:00
|
|
|
self.value = im[3]
|
2020-12-29 21:07:50 +01:00
|
|
|
|
|
|
|
self.update()
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2020-10-31 21:51:28 +01:00
|
|
|
|
|
|
|
class ConfirmationView:
|
2020-12-29 13:32:04 +01:00
|
|
|
"""Confirmation widget allowing user confirmation of a setting."""
|
2020-10-31 21:51:28 +01:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.active = False
|
2020-12-30 11:29:02 +01:00
|
|
|
self.value = False
|
2021-01-10 11:34:37 +01:00
|
|
|
self._yes = Button(20, 140, 90, 45, 'Yes')
|
|
|
|
self._no = Button(130, 140, 90, 45, 'No')
|
2020-10-31 21:51:28 +01:00
|
|
|
|
|
|
|
def draw(self, message):
|
2021-01-10 11:34:37 +01:00
|
|
|
draw = wasp.watch.drawable
|
|
|
|
mute = wasp.watch.display.mute
|
|
|
|
|
|
|
|
mute(True)
|
|
|
|
draw.set_color(wasp.system.theme('bright'))
|
2021-01-05 04:00:47 +01:00
|
|
|
draw.set_font(fonts.sans24)
|
2021-01-10 11:34:37 +01:00
|
|
|
draw.fill()
|
|
|
|
draw.string(message, 0, 60)
|
|
|
|
self._yes.draw()
|
|
|
|
self._no.draw()
|
|
|
|
mute(False)
|
|
|
|
|
2020-10-31 21:51:28 +01:00
|
|
|
self.active = True
|
|
|
|
|
|
|
|
def touch(self, event):
|
2020-12-30 11:29:02 +01:00
|
|
|
if not self.active:
|
|
|
|
return False
|
|
|
|
|
2021-01-10 11:34:37 +01:00
|
|
|
if self._yes.touch(event):
|
|
|
|
self.active = False
|
|
|
|
self.value = True
|
|
|
|
return True
|
|
|
|
elif self._no.touch(event):
|
2020-11-29 09:58:37 +01:00
|
|
|
self.active = False
|
2021-01-10 11:34:37 +01:00
|
|
|
self.value = False
|
2020-10-31 21:51:28 +01:00
|
|
|
return True
|
2020-12-30 11:29:02 +01:00
|
|
|
|
|
|
|
return False
|