From 393dfefc86be9b0fe518d4a1421fe642ada9b75e Mon Sep 17 00:00:00 2001 From: Aidan Houlihan Date: Sun, 1 Nov 2020 09:51:28 +1300 Subject: [PATCH] apps: pager: notifications: Added remove all notifications dialog Signed-off-by: Aidan Houlihan [daniel@redfelineninja.org.uk: Minor changes to .gitignore] Signed-off-by: Daniel Thompson --- .gitignore | 2 ++ res/no.png | Bin 0 -> 454 bytes res/yes.png | Bin 0 -> 500 bytes wasp/apps/pager.py | 29 +++++++++++++++--- wasp/icons.py | 59 ++++++++++++++++++++++++++++++++++++ wasp/widgets.py | 73 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 res/no.png create mode 100644 res/yes.png 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 0000000000000000000000000000000000000000..cb295d1347d8af500cfb4fd78eb716c410010958 GIT binary patch literal 454 zcmeAS@N?(olHy`uVBq!ia0vp^2|#Sa!3HE}UfI8efq}8t)5S5QBJS;+i+P6(1X$+& z|NkPyvEf$IB3?uDEpl=b6X(jlkA0&s?b@wdHHmyW(ha3k9ZefkZ?4II%lF`$+gF#g zE4Rh=FgSc-VmNz$39ACb4aSIjEF27F4AaaRnHpppp87U0B(Nt`3PYvNuq-IQGI!pd zzJEFAznADK&z!23u%&Zl;!EScFTYs|N)=3f7{U+x97rzHalCKiDg1T4SHLZv%U_l} zuG*Du_ghQEhLK65My+O<cVUAgh41tZ6UM-2CvFI~0U6+WY3?%5F6 z^#TnHI*$8;3zjwhzggR0%W#i<$?g9orOO__VPy6*x%{Q4?N8RuO18aku3r>gz1hi` zf&KjgABTsZ8H6`X_CGbpSbF!wr)gbs6Ykwz;x5fp5&To=!0bF{-v-+U0avwb`|M0M zd$Mseu<0@|9^gChNzH*_1M`MGoB|AQ7El4X8Fq}^?wYqcdh=v mfP3Gc!q@C)(|4_`VT>%9CI5E%<`=;DVeoYIb6Mw<&;$TV!N0@+ literal 0 HcmV?d00001 diff --git a/res/yes.png b/res/yes.png new file mode 100644 index 0000000000000000000000000000000000000000..48bd3fe527d3edf66356659dd36d6a2150d7c4a5 GIT binary patch literal 500 zcmeAS@N?(olHy`uVBq!ia0vp^2|#Sa!3HE}UfI8efq`+ir;B4qMcmst4~3c(1X@1+ zmA`fD(lVLHe0-6;=jXfXyeaQqG&$HS(@(~TeHrTko5Kst8#ANU_`l>$_`Tq}gWHv8 zE;$CLPYeRH_IofhFeI@b`J_Ua3gxt@N)y=G`u6Smuba8v&rseqjg3Kuli@&C(2)-1 z`DC57KZ<} zYlGJ{0Yk00(_%NH_l28$(tr6m6&_W-PUkZfXW4Gg$*l0$!B-_Zr(;imN5l1%Y|@7B z`R?p~{qjzePPpBy~mtbHxG687fM&_hSA$(MUE5jp0 uUiJT9Z=HIWR=<$bKK@SC!jC-WQ`i+xb<1C$q`V1e3WKMspUXO@geCxV%gGu5 literal 0 HcmV?d00001 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