summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAidan Houlihan <aidandhoulihan@gmail.com>2020-10-31 20:51:28 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-11-29 09:12:03 (GMT)
commit393dfefc86be9b0fe518d4a1421fe642ada9b75e (patch)
treefb2f800eeacf7bd2f02adf616355d4e8011ab51e
parent4c0120aa1ea93a280824e96e9221b8dbee82121f (diff)
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>
-rw-r--r--.gitignore2
-rw-r--r--res/no.pngbin0 -> 454 bytes
-rw-r--r--res/yes.pngbin0 -> 500 bytes
-rw-r--r--wasp/apps/pager.py29
-rw-r--r--wasp/icons.py59
-rw-r--r--wasp/widgets.py73
6 files changed, 159 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 17474de..5f31c56 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,5 @@ cscope.out
docs/build
attic/
wasp/boards/*/watch.py
+.idea
+.vscode
diff --git a/res/no.png b/res/no.png
new file mode 100644
index 0000000..cb295d1
--- /dev/null
+++ b/res/no.png
Binary files differ
diff --git a/res/yes.png b/res/yes.png
new file mode 100644
index 0000000..48bd3fe
--- /dev/null
+++ b/res/yes.png
Binary files differ
diff --git a/wasp/apps/pager.py b/wasp/apps/pager.py
index db12b3f..416a006 100644
--- a/wasp/apps/pager.py
+++ b/wasp/apps/pager.py
@@ -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.
diff --git a/wasp/icons.py b/wasp/icons.py
index 09c6e53..d9d775a 100644
--- a/wasp/icons.py
+++ b/wasp/icons.py
@@ -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'
+)
diff --git a/wasp/widgets.py b/wasp/widgets.py
index f064c69..39d8b19 100644
--- a/wasp/widgets.py
+++ b/wasp/widgets.py
@@ -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