1
0
Fork 0

apps: pager: notifications: Added remove all notifications dialog

Signed-off-by: Aidan Houlihan <aidandhoulihan@gmail.com>
[daniel@redfelineninja.org.uk: Minor changes to .gitignore]
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
Aidan Houlihan 2020-11-01 09:51:28 +13:00 committed by Daniel Thompson
parent 4c0120aa1e
commit 393dfefc86
6 changed files with 159 additions and 4 deletions

2
.gitignore vendored
View file

@ -6,3 +6,5 @@ cscope.out
docs/build
attic/
wasp/boards/*/watch.py
.idea
.vscode

BIN
res/no.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B

BIN
res/yes.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

View file

@ -82,19 +82,40 @@ class NotificationApp(PagerApp):
def __init__(self):
super().__init__('')
self.confirmation_view = wasp.widgets.ConfirmationView()
def foreground(self):
notes = wasp.system.notifications
id = next(iter(notes))
note = notes[id]
del notes[id]
note = notes.pop(next(iter(notes)))
title = note['title'] if 'title' in note else 'Untitled'
body = note['body'] if 'body' in note else ''
self._msg = '{}\n\n{}'.format(title, body)
wasp.system.request_event(wasp.EventMask.TOUCH)
super().foreground()
def swipe(self, event):
if event[0] == wasp.EventType.DOWN:
self.confirmation_view.active = True
self._draw()
super().swipe(event)
def _draw(self):
if self.confirmation_view.active:
self.confirmation_view.draw('clear notifications?')
else:
super()._draw()
def touch(self, event):
if self.confirmation_view.active:
is_confirmed = self.confirmation_view.touch(event)
if is_confirmed:
wasp.system.notifications = {}
wasp.system.navigate(wasp.EventType.BACK)
self.confirmation_view.active = False
class CrashApp():
"""Crash handler application.

View file

@ -247,3 +247,62 @@ pause = (
b'\x18\xca\x1d\xcb\x14\xcb\x1f\xcd\x0e\xcd!\xd1\x04\xd1#\xe4'
b'&\xe0)\xdd-\xda1\xd47\xce?\xff\x8f'
)
yes_button = (
96, 60,
b'a]\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01'
b'[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01'
b'[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01'
b'[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01'
b'\x08\x05\x0f\x05\x05\x14\n\x0f\x08\x01\x03\x01\x08\x05\x0f\x05'
b'\x05\x14\n\x0f\x08\x01\x03\x01\x08\x05\x0f\x05\x05\x14\n\x0f'
b'\x08\x01\x03\x01\x08\x05\x0f\x05\x05\x14\n\x0f\x08\x01\x03\x01'
b'\x08\x05\x0f\x05\x05\x14\n\x0f\x08\x01\x03\x01\x08\x05\x0f\x05'
b'\x05\x05\x14\x05\x17\x01\x03\x01\x08\x05\x0f\x05\x05\x05\x14\x05'
b'\x17\x01\x03\x01\x08\x05\x0f\x05\x05\x05\x14\x05\x17\x01\x03\x01'
b'\x08\x05\x0f\x05\x05\x05\x14\x05\x17\x01\x03\x01\x08\x05\x0f\x05'
b'\x05\x05\x14\x05\x17\x01\x03\x01\r\x0f\n\x0f\x0f\n\r\x01'
b'\x03\x01\r\x0f\n\x0f\x0f\n\r\x01\x03\x01\r\x0f\n\x0f'
b'\x0f\n\r\x01\x03\x01\r\x0f\n\x0f\x0f\n\r\x01\x03\x01'
b'\r\x0f\n\x0f\x0f\n\r\x01\x03\x01\x12\x05\x0f\x05#\x05'
b'\x08\x01\x03\x01\x12\x05\x0f\x05#\x05\x08\x01\x03\x01\x12\x05'
b'\x0f\x05#\x05\x08\x01\x03\x01\x12\x05\x0f\x05#\x05\x08\x01'
b'\x03\x01\x12\x05\x0f\x05#\x05\x08\x01\x03\x01\x12\x05\x0f\x14'
b'\x05\x0f\r\x01\x03\x01\x12\x05\x0f\x14\x05\x0f\r\x01\x03\x01'
b'\x12\x05\x0f\x14\x05\x0f\r\x01\x03\x01\x12\x05\x0f\x14\x05\x0f'
b'\r\x01\x03\x01\x12\x05\x0f\x14\x05\x0f\r\x01\x03\x01[\x01'
b'\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01'
b'\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01'
b'\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01'
b'\x03\x01[\x01\x03\x01[\x01\x03]\xc2'
)
no_button = (
96, 60,
b'a]\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01'
b'[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01'
b'[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01'
b'[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01\x16\x05\n\x05'
b'\n\n\x1d\x01\x03\x01\x16\x05\n\x05\n\n\x1d\x01\x03\x01'
b'\x16\x05\n\x05\n\n\x1d\x01\x03\x01\x16\x05\n\x05\n\n'
b'\x1d\x01\x03\x01\x16\x05\n\x05\n\n\x1d\x01\x03\x01\x16\n'
b'\x05\x05\x05\x05\n\x05\x18\x01\x03\x01\x16\n\x05\x05\x05\x05'
b'\n\x05\x18\x01\x03\x01\x16\n\x05\x05\x05\x05\n\x05\x18\x01'
b'\x03\x01\x16\n\x05\x05\x05\x05\n\x05\x18\x01\x03\x01\x16\n'
b'\x05\x05\x05\x05\n\x05\x18\x01\x03\x01\x16\x05\x05\n\x05\x05'
b'\n\x05\x18\x01\x03\x01\x16\x05\x05\n\x05\x05\n\x05\x18\x01'
b'\x03\x01\x16\x05\x05\n\x05\x05\n\x05\x18\x01\x03\x01\x16\x05'
b'\x05\n\x05\x05\n\x05\x18\x01\x03\x01\x16\x05\x05\n\x05\x05'
b'\n\x05\x18\x01\x03\x01\x16\x05\n\x05\x05\x05\n\x05\x18\x01'
b'\x03\x01\x16\x05\n\x05\x05\x05\n\x05\x18\x01\x03\x01\x16\x05'
b'\n\x05\x05\x05\n\x05\x18\x01\x03\x01\x16\x05\n\x05\x05\x05'
b'\n\x05\x18\x01\x03\x01\x16\x05\n\x05\x05\x05\n\x05\x18\x01'
b'\x03\x01\x16\x05\n\x05\n\n\x1d\x01\x03\x01\x16\x05\n\x05'
b'\n\n\x1d\x01\x03\x01\x16\x05\n\x05\n\n\x1d\x01\x03\x01'
b'\x16\x05\n\x05\n\n\x1d\x01\x03\x01\x16\x05\n\x05\n\n'
b'\x1d\x01\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01'
b'[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01'
b'[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01'
b'[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01[\x01\x03\x01'
b'[\x01\x03]\xc2'
)

View file

@ -286,3 +286,76 @@ class Slider():
elif v >= self._steps:
v = self._steps - 1
self.value = v
_message_string_x_coord = const(0)
_message_string_y_coord = const(60)
_yes_button_x_coord = const(20)
_yes_button_y_coord = const(100)
_no_button_x_coord = const(120)
_no_button_y_coord = const(100)
class ConfirmationView:
"Confirmation widget allowing user confirmation of a setting"
def __init__(self):
self.active = False
self.yes_button_bounds = (
(_yes_button_x_coord, _yes_button_y_coord),
(
icons.yes_button[0] + _yes_button_x_coord,
icons.yes_button[1] + _yes_button_y_coord,
),
)
self.no_button_bounds = (
(_no_button_x_coord, _no_button_y_coord),
(
icons.no_button[0] + _no_button_x_coord,
icons.no_button[1] + _no_button_y_coord,
)
)
def draw(self, message):
wasp.watch.drawable.fill(1)
wasp.watch.drawable.string(
message,
_message_string_x_coord,
_message_string_y_coord
)
wasp.watch.drawable.blit(
icons.yes_button,
_yes_button_x_coord,
_yes_button_y_coord,
)
wasp.watch.drawable.blit(
icons.no_button,
_no_button_x_coord,
_no_button_y_coord,
)
self.active = True
def touch(self, event):
x_coord = event[1]
y_coord = event[2]
is_yes_button_press = (
x_coord > self.yes_button_bounds[0][0]
and y_coord > self.yes_button_bounds[0][1]
and x_coord < self.yes_button_bounds[1][0]
and y_coord < self.yes_button_bounds[1][1]
)
is_no_button_press = (
x_coord > self.no_button_bounds[0][0]
and y_coord > self.no_button_bounds[0][1]
and x_coord < self.no_button_bounds[1][0]
and y_coord < self.no_button_bounds[1][1]
)
if is_yes_button_press:
return True
elif is_no_button_press:
return False
else:
return None