1
0
Fork 0
wasp-os/wasp/apps/launcher.py
Daniel Thompson 66743d42c8 wasp: Manager: Bring in proper separation of apps
This is getting us much closer to the final UI concept. We have a
quick ring from which we can select typical apps such as clock and
stopwatch which will (eventually) be supplemented with step counting
and heart rate monitoriing. More exotic apps (currenrtly torch, self
test, settings) are all relagated to the launcher ring.
2020-04-14 20:05:57 +01:00

80 lines
2.1 KiB
Python

# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (C) 2020 Daniel Thompson
import wasp
import icons
class LauncherApp():
"""An application launcher application.
"""
NAME = 'Launcher'
ICON = icons.app
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.set_color(0xffff)
draw.blit(app.ICON, x+13, y+12)
draw.set_color(0xbdb6)
draw.string(app.NAME, x, y+120-30, 120)
draw = wasp.watch.drawable
page = self._get_page(self._page)
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)