1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (C) 2020 Daniel Thompson
"""Application launcher
~~~~~~~~~~~~~~~~~~~~~~~
.. figure:: res/LauncherApp.png
:width: 179
"""
import wasp
import icons
class LauncherApp():
"""An application launcher application."""
NAME = 'Launcher'
ICON = icons.app
def __init__(self):
self._scroll = wasp.widgets.ScrollIndicator(y=6)
def foreground(self):
"""Activate the application."""
self._page = 0
self._draw()
wasp.system.request_event(wasp.EventMask.TOUCH |
wasp.EventMask.SWIPE_UPDOWN)
def swipe(self, event):
i = self._page
n = self._num_pages
if event[0] == wasp.EventType.UP:
i += 1
if i >= n:
i -= 1
wasp.watch.vibrator.pulse()
return
else:
i -= 1
if i < 0:
wasp.system.switch(wasp.system.quick_ring[0])
return
self._page = i
wasp.watch.display.mute(True)
self._draw()
wasp.watch.display.mute(False)
def touch(self, event):
page = self._get_page(self._page)
x = event[1]
y = event[2]
app = page[2 * (y // 120) + (x // 120)]
if app:
wasp.system.switch(app)
else:
wasp.watch.vibrator.pulse()
@property
def _num_pages(self):
"""Work out what the highest possible pages it."""
num_apps = len(wasp.system.launcher_ring)
return (num_apps + 3) // 4
def _get_page(self, i):
apps = wasp.system.launcher_ring
page = apps[4*i: 4*(i+1)]
while len(page) < 4:
page.append(None)
return page
def _draw(self):
"""Redraw the display from scratch."""
def draw_app(app, x, y):
if not app:
return
draw.blit(app.ICON if 'ICON' in dir(app) else icons.app, x+13, y+12)
draw.set_color(wasp.system.theme('mid'))
draw.string(app.NAME, x, y+120-30, 120)
draw = wasp.watch.drawable
page_num = self._page
page = self._get_page(page_num)
draw.fill()
draw_app(page[0], 0, 0)
draw_app(page[1], 120, 0)
draw_app(page[2], 0, 120)
draw_app(page[3], 120, 120)
scroll = self._scroll
scroll.up = page_num > 0
scroll.down = page_num < (self._num_pages-1)
scroll.draw()
|