2020-04-11 21:26:12 +02:00
|
|
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
# Copyright (C) 2020 Daniel Thompson
|
2020-05-10 15:10:04 +02:00
|
|
|
"""The complete set of wasp-os application entry points are documented
|
|
|
|
below as part of a template application. Note that the template does
|
|
|
|
not rely on any specific parent class. This is because applications in
|
|
|
|
wasp-os can rely on *duck typing* making a class hierarchy pointless.
|
2020-04-12 09:41:31 +02:00
|
|
|
"""
|
2020-04-11 21:26:12 +02:00
|
|
|
|
|
|
|
import wasp
|
|
|
|
import icons
|
|
|
|
|
|
|
|
class TemplateApp():
|
2020-05-10 15:10:04 +02:00
|
|
|
"""Template application.
|
|
|
|
|
|
|
|
The template application includes every application entry point. It
|
|
|
|
is used as a reference guide and can also be used as a template for
|
|
|
|
creating new applications.
|
|
|
|
|
|
|
|
.. data:: NAME = 'Template'
|
|
|
|
|
|
|
|
Applications must provide a short ``NAME`` that is used by the
|
|
|
|
launcher to describe the application. Names that are longer than
|
|
|
|
8 characters are likely to be abridged by the launcher in order
|
|
|
|
to fit on the screen.
|
|
|
|
|
|
|
|
.. data:: ICON = RLE2DATA
|
|
|
|
|
|
|
|
Applications can optionally provide an icon for display by the
|
|
|
|
launcher. Applications that expect to be installed on the quick
|
|
|
|
ring will not be listed by the launcher and need not provide any
|
|
|
|
icon. When no icon is provided the system will use a default
|
|
|
|
icon.
|
|
|
|
|
|
|
|
The icon is an opportunity to differentiate your application from others
|
|
|
|
so supplying an icon is strongly recommended. The icon, when provided,
|
|
|
|
must not be larger than 96x64.
|
|
|
|
|
2020-04-11 21:26:12 +02:00
|
|
|
"""
|
|
|
|
NAME = 'Template'
|
|
|
|
ICON = icons.app
|
|
|
|
|
|
|
|
def __init__(self):
|
2020-04-12 09:41:31 +02:00
|
|
|
"""Initialize the application."""
|
2020-04-11 21:26:12 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
def foreground(self):
|
|
|
|
"""Activate the application."""
|
|
|
|
self._draw()
|
|
|
|
wasp.system.request_event(wasp.EventMask.TOUCH |
|
|
|
|
wasp.EventMask.SWIPE_UPDOWN |
|
|
|
|
wasp.EventMask.BUTTON)
|
2020-04-12 09:41:31 +02:00
|
|
|
wasp.system.request_tick(1000)
|
|
|
|
|
|
|
|
def background(self):
|
|
|
|
"""De-activate the application."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def sleep(self):
|
|
|
|
"""Notify the application the device is about to sleep."""
|
|
|
|
return False
|
|
|
|
|
|
|
|
def wake(self):
|
|
|
|
"""Notify the application the device is waking up."""
|
|
|
|
pass
|
2020-04-11 21:26:12 +02:00
|
|
|
|
2021-06-20 11:21:25 +02:00
|
|
|
def preview(self):
|
|
|
|
"""Provide a preview for the watch face selection.
|
|
|
|
|
|
|
|
preview() must be implemented by watch face applications because it
|
|
|
|
is called by the watch face selector. When called the application should
|
|
|
|
redraw the screen as through it was the foreground() application. The
|
|
|
|
application will not be active after the preview.
|
|
|
|
|
|
|
|
Other applications should not implement this entry point.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2020-04-11 21:26:12 +02:00
|
|
|
def press(self, button, state):
|
2020-04-12 09:41:31 +02:00
|
|
|
"""Notify the application of a button-press event."""
|
2020-04-11 21:26:12 +02:00
|
|
|
draw = wasp.watch.drawable
|
|
|
|
draw.string('Button', 0, 108, width=240)
|
|
|
|
|
|
|
|
def swipe(self, event):
|
2020-04-12 09:41:31 +02:00
|
|
|
"""Notify the application of a touchscreen swipe event."""
|
2020-04-11 21:26:12 +02:00
|
|
|
draw = wasp.watch.drawable
|
|
|
|
if event[0] == wasp.EventType.UP:
|
|
|
|
draw.string('Swipe up', 0, 108, width=240)
|
|
|
|
else:
|
|
|
|
draw.string('Swipe down', 0, 108, width=240)
|
|
|
|
|
2020-04-12 09:41:31 +02:00
|
|
|
def tick(self, ticks):
|
|
|
|
"""Notify the application that its periodic tick is due."""
|
|
|
|
pass
|
|
|
|
|
2020-04-11 21:26:12 +02:00
|
|
|
def touch(self, event):
|
2020-04-12 09:41:31 +02:00
|
|
|
"""Notify the application of a touchscreen touch event."""
|
2020-04-11 21:26:12 +02:00
|
|
|
draw = wasp.watch.drawable
|
|
|
|
wasp.watch.drawable.string('({}, {})'.format(
|
|
|
|
event[1], event[2]), 0, 108, width=240)
|
|
|
|
|
|
|
|
def _draw(self):
|
|
|
|
"""Draw the display from scratch."""
|
|
|
|
draw = wasp.watch.drawable
|
|
|
|
draw.fill()
|
2020-04-12 09:41:31 +02:00
|
|
|
draw.string(self.NAME, 0, 6, width=240)
|
|
|
|
self._update()
|
|
|
|
|
|
|
|
def _update(self):
|
2020-05-10 10:34:57 +02:00
|
|
|
"""Update the dynamic parts of the application display."""
|
2020-04-12 09:41:31 +02:00
|
|
|
pass
|