manager: Introduce shared "system bar"

Providing a status bar for all apps to use allows us to reduce allocations
within the applications.

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2020-11-04 19:00:37 +00:00
parent f95f45cda3
commit 8e89e38175
5 changed files with 14 additions and 18 deletions

View file

@ -31,16 +31,13 @@ class ClockApp():
NAME = 'Clock'
ICON = icons.clock
def __init__(self):
self._bar = wasp.widgets.StatusBar()
def foreground(self):
"""Activate the application.
Configure the status bar, redraw the display and request a periodic
tick callback every second.
"""
self._bar.clock = False
wasp.system.bar.clock = False
self._draw(True)
wasp.system.request_tick(1000)
@ -82,13 +79,13 @@ class ClockApp():
draw.rleblit(digits.clock_colon, pos=(2*48, 80), fg=0xb5b6)
# Redraw the status bar
self._bar.draw()
wasp.system.bar.draw()
else:
# The update is doubly lazy... we update the status bar and if
# the status bus update reports a change in the time of day
# then we compare the minute on display to make sure we
# only update the main clock once per minute.
now = self._bar.update()
now = wasp.system.bar.update()
if not now or self._min == now[4]:
# Skip the update
return

View file

@ -61,12 +61,9 @@ class FibonacciClockApp():
NAME = 'Fibo'
ICON = icon
def __init__(self):
self._bar = wasp.widgets.StatusBar()
def foreground(self):
"""Activate the application."""
self._bar.clock = False
wasp.system.bar.clock = False
self._draw(True)
wasp.system.request_tick(1000)
@ -86,9 +83,9 @@ class FibonacciClockApp():
if redraw:
now = wasp.watch.rtc.get_localtime()
draw.fill()
self._bar.draw()
wasp.system.bar.draw()
else:
now = self._bar.update()
now = wasp.system.bar.update()
if not now or self._min == now[4]:
return

View file

@ -42,12 +42,12 @@ class StepCounterApp():
def __init__(self):
watch.accel.reset()
self._bar = wasp.widgets.StatusBar()
self._count = 0
self._prev_day = -1
def foreground(self):
"""Activate the application."""
wasp.system.bar.clock = True
self._draw()
wasp.system.request_tick(1000)
@ -62,13 +62,13 @@ class StepCounterApp():
draw.blit(feet, 12, 132-24)
self._update()
self._bar.draw()
wasp.system.bar.draw()
def _update(self):
draw = wasp.watch.drawable
# Update the status bar
now = self._bar.update()
now = wasp.system.bar.update()
# Reset the step counter if we have move onto the next day
if now and now[2] != self._prev_day:

View file

@ -17,12 +17,12 @@ class StopwatchApp():
ICON = icons.app
def __init__(self):
self._bar = wasp.widgets.StatusBar()
self._reset()
self._count = 0
def foreground(self):
"""Activate the application."""
wasp.system.bar.clock = True
self._draw()
wasp.system.request_tick(97)
wasp.system.request_event(wasp.EventMask.TOUCH |
@ -111,7 +111,7 @@ class StopwatchApp():
self._last_count = -1
self._update()
self._bar.draw()
wasp.system.bar.draw()
self._draw_splits()
def _update(self):
@ -125,7 +125,7 @@ class StopwatchApp():
self._reset()
# Update the statusbar
self._bar.update()
wasp.system.bar.update()
if self._last_count != self._count:
centisecs = self._count

View file

@ -100,6 +100,8 @@ class Manager():
def __init__(self):
self.app = None
self.bar = widgets.StatusBar()
self.quick_ring = []
self.launcher = LauncherApp()
self.launcher_ring = []