apps: software: Automatically track y position for checkboxes

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2021-03-10 21:33:22 +00:00
parent cec8d97aeb
commit df5aa24d2d

View file

@ -24,34 +24,52 @@ class SoftwareApp():
def foreground(self): def foreground(self):
"""Activate the application.""" """Activate the application."""
self.db = (
('alarm', wasp.widgets.Checkbox(0, 0, 'Alarm')), def factory(label):
('calc', wasp.widgets.Checkbox(0, 40, 'Calculator')), nonlocal y
('chrono', wasp.widgets.Checkbox(0, 80, 'Chrono')),
('fibonacci_clock', wasp.widgets.Checkbox(0, 120, 'Fibonacci Clock')), cb = wasp.widgets.Checkbox(0, y, label)
('gameoflife', wasp.widgets.Checkbox(0, 160, 'Game Of Life')), y += 40
('musicplayer', wasp.widgets.Checkbox(0, 0, 'Music Player')), if y > 160:
('play2048', wasp.widgets.Checkbox(0, 40, 'Play 2048')), y = 0
('snake', wasp.widgets.Checkbox(0, 80, 'Snake Game')), return cb
('flashlight', wasp.widgets.Checkbox(0, 120, 'Torch')),
('testapp', wasp.widgets.Checkbox(0, 160, 'Test')),
('timer', wasp.widgets.Checkbox(0, 0, 'Timer')), y = 0
) db = []
self.si = wasp.widgets.ScrollIndicator() db.append(('alarm', factory('Alarm')))
self.page = 0 db.append(('calc', factory('Calculator')))
db.append(('chrono', factory('Chrono')))
db.append(('fibonacci_clock', factory('Fibonacci Clock')))
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')))
db.append(('flashlight', factory('Torch')))
db.append(('testapp', factory('Test')))
db.append(('timer', factory('Timer')))
# Get the initial state for the checkboxes # Get the initial state for the checkboxes
for _, checkbox in self.db: for _, checkbox in db:
label = checkbox.label.replace(' ', '') label = checkbox.label.replace(' ', '')
for app in wasp.system.launcher_ring: for app in wasp.system.launcher_ring:
if type(app).__name__.startswith(label): if type(app).__name__.startswith(label):
checkbox.state = True checkbox.state = True
break break
self.si = wasp.widgets.ScrollIndicator()
self.page = 0
self.db = db
self._draw() self._draw()
wasp.system.request_event(wasp.EventMask.TOUCH | wasp.system.request_event(wasp.EventMask.TOUCH |
wasp.EventMask.SWIPE_UPDOWN) wasp.EventMask.SWIPE_UPDOWN)
def background(self):
del self.si
del self.page
del self.db
def get_page(self): def get_page(self):
i = self.page * 5 i = self.page * 5
return self.db[i:i+5] return self.db[i:i+5]