2021-01-03 15:54:34 +01:00
|
|
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
# Copyright (C) 2020 Daniel Thompson
|
2021-01-13 22:51:17 +01:00
|
|
|
"""Software
|
|
|
|
~~~~~~~~~~~
|
|
|
|
|
|
|
|
A tool to enable/disable applications.
|
|
|
|
|
|
|
|
.. figure:: res/SoftwareApp.png
|
|
|
|
:width: 179
|
|
|
|
|
|
|
|
Most applications are disabled by default at boot in order to conserve
|
|
|
|
RAM (which is in short supply and very useful to anyone wanting to
|
|
|
|
write an application). This tools allows us to boot and conserve RAM
|
|
|
|
whilst still allowing users to activate so many awesome applications!
|
|
|
|
"""
|
2021-01-03 15:54:34 +01:00
|
|
|
|
|
|
|
import wasp
|
|
|
|
import icons
|
|
|
|
|
2021-03-03 21:41:11 +01:00
|
|
|
|
2021-01-03 15:54:34 +01:00
|
|
|
class SoftwareApp():
|
|
|
|
"""Enable and disable applications."""
|
|
|
|
NAME = 'Software'
|
|
|
|
ICON = icons.software
|
|
|
|
|
|
|
|
def foreground(self):
|
|
|
|
"""Activate the application."""
|
2021-03-10 22:33:22 +01:00
|
|
|
|
|
|
|
def factory(label):
|
|
|
|
nonlocal y
|
|
|
|
|
|
|
|
cb = wasp.widgets.Checkbox(0, y, label)
|
|
|
|
y += 40
|
|
|
|
if y > 160:
|
|
|
|
y = 0
|
|
|
|
return cb
|
|
|
|
|
|
|
|
y = 0
|
|
|
|
db = []
|
|
|
|
db.append(('alarm', factory('Alarm')))
|
|
|
|
db.append(('calc', factory('Calculator')))
|
2021-06-20 11:28:27 +02:00
|
|
|
db.append(('faces', factory('Faces')))
|
2021-03-10 22:33:22 +01:00
|
|
|
db.append(('gameoflife', factory('Game Of Life')))
|
|
|
|
db.append(('musicplayer', factory('Music Player')))
|
|
|
|
db.append(('play2048', factory('Play 2048')))
|
|
|
|
db.append(('snake', factory('Snake Game')))
|
2021-06-20 18:24:10 +02:00
|
|
|
db.append(('sports', factory('Sports')))
|
2021-03-10 22:33:22 +01:00
|
|
|
db.append(('flashlight', factory('Torch')))
|
|
|
|
db.append(('testapp', factory('Test')))
|
|
|
|
db.append(('timer', factory('Timer')))
|
2021-03-31 01:10:24 +02:00
|
|
|
db.append(('weather', factory('Weather')))
|
2021-01-03 15:54:34 +01:00
|
|
|
|
|
|
|
# Get the initial state for the checkboxes
|
2021-03-10 22:33:22 +01:00
|
|
|
for _, checkbox in db:
|
2021-01-03 15:54:34 +01:00
|
|
|
label = checkbox.label.replace(' ', '')
|
|
|
|
for app in wasp.system.launcher_ring:
|
|
|
|
if type(app).__name__.startswith(label):
|
|
|
|
checkbox.state = True
|
|
|
|
break
|
|
|
|
|
2021-03-10 22:33:22 +01:00
|
|
|
self.si = wasp.widgets.ScrollIndicator()
|
|
|
|
self.page = 0
|
|
|
|
self.db = db
|
|
|
|
|
2021-01-03 15:54:34 +01:00
|
|
|
self._draw()
|
|
|
|
wasp.system.request_event(wasp.EventMask.TOUCH |
|
|
|
|
wasp.EventMask.SWIPE_UPDOWN)
|
|
|
|
|
2021-03-10 22:33:22 +01:00
|
|
|
def background(self):
|
|
|
|
del self.si
|
|
|
|
del self.page
|
|
|
|
del self.db
|
|
|
|
|
2021-01-03 15:54:34 +01:00
|
|
|
def get_page(self):
|
|
|
|
i = self.page * 5
|
|
|
|
return self.db[i:i+5]
|
|
|
|
|
|
|
|
def swipe(self, event):
|
|
|
|
"""Notify the application of a touchscreen swipe event."""
|
|
|
|
page = self.page
|
2021-01-10 19:06:18 +01:00
|
|
|
pages = (len(self.db)-1) // 5
|
2021-01-03 15:54:34 +01:00
|
|
|
if event[0] == wasp.EventType.DOWN:
|
2021-01-10 19:06:18 +01:00
|
|
|
page = page - 1 if page > 0 else pages
|
|
|
|
if event[0] == wasp.EventType.UP:
|
2021-01-03 15:54:34 +01:00
|
|
|
page = page + 1 if page < pages else 0
|
|
|
|
self.page = page
|
|
|
|
|
|
|
|
mute = wasp.watch.display.mute
|
|
|
|
mute(True)
|
|
|
|
self._draw()
|
|
|
|
mute(False)
|
|
|
|
|
|
|
|
def touch(self, event):
|
|
|
|
"""Notify the application of a touchscreen touch event."""
|
|
|
|
for module, checkbox in self.get_page():
|
|
|
|
if checkbox.touch(event):
|
|
|
|
label = checkbox.label.replace(' ', '')
|
|
|
|
if checkbox.state:
|
2021-01-10 11:37:25 +01:00
|
|
|
wasp.system.register('apps.{}.{}App'.format(module, label))
|
2021-01-03 15:54:34 +01:00
|
|
|
else:
|
|
|
|
for app in wasp.system.launcher_ring:
|
|
|
|
if type(app).__name__.startswith(label):
|
|
|
|
wasp.system.launcher_ring.remove(app)
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
def _draw(self):
|
|
|
|
"""Draw the display from scratch."""
|
|
|
|
wasp.watch.drawable.fill()
|
|
|
|
self.si.draw()
|
|
|
|
for _, checkbox in self.get_page():
|
|
|
|
checkbox.draw()
|