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:
parent
f95f45cda3
commit
8e89e38175
5 changed files with 14 additions and 18 deletions
|
@ -31,16 +31,13 @@ class ClockApp():
|
||||||
NAME = 'Clock'
|
NAME = 'Clock'
|
||||||
ICON = icons.clock
|
ICON = icons.clock
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self._bar = wasp.widgets.StatusBar()
|
|
||||||
|
|
||||||
def foreground(self):
|
def foreground(self):
|
||||||
"""Activate the application.
|
"""Activate the application.
|
||||||
|
|
||||||
Configure the status bar, redraw the display and request a periodic
|
Configure the status bar, redraw the display and request a periodic
|
||||||
tick callback every second.
|
tick callback every second.
|
||||||
"""
|
"""
|
||||||
self._bar.clock = False
|
wasp.system.bar.clock = False
|
||||||
self._draw(True)
|
self._draw(True)
|
||||||
wasp.system.request_tick(1000)
|
wasp.system.request_tick(1000)
|
||||||
|
|
||||||
|
@ -82,13 +79,13 @@ class ClockApp():
|
||||||
draw.rleblit(digits.clock_colon, pos=(2*48, 80), fg=0xb5b6)
|
draw.rleblit(digits.clock_colon, pos=(2*48, 80), fg=0xb5b6)
|
||||||
|
|
||||||
# Redraw the status bar
|
# Redraw the status bar
|
||||||
self._bar.draw()
|
wasp.system.bar.draw()
|
||||||
else:
|
else:
|
||||||
# The update is doubly lazy... we update the status bar and if
|
# The update is doubly lazy... we update the status bar and if
|
||||||
# the status bus update reports a change in the time of day
|
# the status bus update reports a change in the time of day
|
||||||
# then we compare the minute on display to make sure we
|
# then we compare the minute on display to make sure we
|
||||||
# only update the main clock once per minute.
|
# 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]:
|
if not now or self._min == now[4]:
|
||||||
# Skip the update
|
# Skip the update
|
||||||
return
|
return
|
||||||
|
|
|
@ -61,12 +61,9 @@ class FibonacciClockApp():
|
||||||
NAME = 'Fibo'
|
NAME = 'Fibo'
|
||||||
ICON = icon
|
ICON = icon
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self._bar = wasp.widgets.StatusBar()
|
|
||||||
|
|
||||||
def foreground(self):
|
def foreground(self):
|
||||||
"""Activate the application."""
|
"""Activate the application."""
|
||||||
self._bar.clock = False
|
wasp.system.bar.clock = False
|
||||||
self._draw(True)
|
self._draw(True)
|
||||||
wasp.system.request_tick(1000)
|
wasp.system.request_tick(1000)
|
||||||
|
|
||||||
|
@ -86,9 +83,9 @@ class FibonacciClockApp():
|
||||||
if redraw:
|
if redraw:
|
||||||
now = wasp.watch.rtc.get_localtime()
|
now = wasp.watch.rtc.get_localtime()
|
||||||
draw.fill()
|
draw.fill()
|
||||||
self._bar.draw()
|
wasp.system.bar.draw()
|
||||||
else:
|
else:
|
||||||
now = self._bar.update()
|
now = wasp.system.bar.update()
|
||||||
if not now or self._min == now[4]:
|
if not now or self._min == now[4]:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,12 @@ class StepCounterApp():
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
watch.accel.reset()
|
watch.accel.reset()
|
||||||
self._bar = wasp.widgets.StatusBar()
|
|
||||||
self._count = 0
|
self._count = 0
|
||||||
self._prev_day = -1
|
self._prev_day = -1
|
||||||
|
|
||||||
def foreground(self):
|
def foreground(self):
|
||||||
"""Activate the application."""
|
"""Activate the application."""
|
||||||
|
wasp.system.bar.clock = True
|
||||||
self._draw()
|
self._draw()
|
||||||
wasp.system.request_tick(1000)
|
wasp.system.request_tick(1000)
|
||||||
|
|
||||||
|
@ -62,13 +62,13 @@ class StepCounterApp():
|
||||||
draw.blit(feet, 12, 132-24)
|
draw.blit(feet, 12, 132-24)
|
||||||
|
|
||||||
self._update()
|
self._update()
|
||||||
self._bar.draw()
|
wasp.system.bar.draw()
|
||||||
|
|
||||||
def _update(self):
|
def _update(self):
|
||||||
draw = wasp.watch.drawable
|
draw = wasp.watch.drawable
|
||||||
|
|
||||||
# Update the status bar
|
# 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
|
# Reset the step counter if we have move onto the next day
|
||||||
if now and now[2] != self._prev_day:
|
if now and now[2] != self._prev_day:
|
||||||
|
|
|
@ -17,12 +17,12 @@ class StopwatchApp():
|
||||||
ICON = icons.app
|
ICON = icons.app
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._bar = wasp.widgets.StatusBar()
|
|
||||||
self._reset()
|
self._reset()
|
||||||
self._count = 0
|
self._count = 0
|
||||||
|
|
||||||
def foreground(self):
|
def foreground(self):
|
||||||
"""Activate the application."""
|
"""Activate the application."""
|
||||||
|
wasp.system.bar.clock = True
|
||||||
self._draw()
|
self._draw()
|
||||||
wasp.system.request_tick(97)
|
wasp.system.request_tick(97)
|
||||||
wasp.system.request_event(wasp.EventMask.TOUCH |
|
wasp.system.request_event(wasp.EventMask.TOUCH |
|
||||||
|
@ -111,7 +111,7 @@ class StopwatchApp():
|
||||||
|
|
||||||
self._last_count = -1
|
self._last_count = -1
|
||||||
self._update()
|
self._update()
|
||||||
self._bar.draw()
|
wasp.system.bar.draw()
|
||||||
self._draw_splits()
|
self._draw_splits()
|
||||||
|
|
||||||
def _update(self):
|
def _update(self):
|
||||||
|
@ -125,7 +125,7 @@ class StopwatchApp():
|
||||||
self._reset()
|
self._reset()
|
||||||
|
|
||||||
# Update the statusbar
|
# Update the statusbar
|
||||||
self._bar.update()
|
wasp.system.bar.update()
|
||||||
|
|
||||||
if self._last_count != self._count:
|
if self._last_count != self._count:
|
||||||
centisecs = self._count
|
centisecs = self._count
|
||||||
|
|
|
@ -100,6 +100,8 @@ class Manager():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.app = None
|
self.app = None
|
||||||
|
|
||||||
|
self.bar = widgets.StatusBar()
|
||||||
|
|
||||||
self.quick_ring = []
|
self.quick_ring = []
|
||||||
self.launcher = LauncherApp()
|
self.launcher = LauncherApp()
|
||||||
self.launcher_ring = []
|
self.launcher_ring = []
|
||||||
|
|
Loading…
Reference in a new issue