1
0
Fork 0

widgets: status: Add a status bar combo widget

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2020-10-21 21:28:09 +01:00
parent 9f3c75d512
commit 398ce598fc
4 changed files with 64 additions and 24 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -151,27 +151,28 @@ knob = (
b'\x16\xd0\x1c\xc8\x10'
)
# 2-bit RLE, generated from res/notification.png, 105 bytes
# 2-bit RLE, generated from res/notification.png, 104 bytes
notification = (
b'\x02'
b' '
b'\x0f\xc2\x1d\xc4\x1c\xc4\x19\xca\x14\xce\x11\xd0\x0f\xd2\x0e\xc5'
b'\x08\xc5\r\xc4\x0c\xc4\x0c\xc4\x0c\xc4\x0b\xc4\x0e\xc4\n\xc4'
b'\x0e\xc4\n\xc4\x0e\xc4\n\xc3\x0f\xc4\t\xc4\x10\xc3\t\xc4'
b'\x10\xc4\x08\xc4\x10\xc4\x08\xc4\x10\xc4\x08\xc4\x10\xc4\x08\xc3'
b'\x11\xc4\x07\xc4\x12\xc4\x06\xc4\x12\xc4\x06\xc4\x12\xc4\x05\xc5'
b'\x12\xc4\x05\xc4\x14\xc4\x03\xc5\x14\xc5\x02\xde\x01\xff\x01\x01'
b'\xde\x0f\xc4\x1d\xc2\x0f'
b'\x1e '
b'\x0e\xc2\x1b\xc4\x1a\xc4\x18\xc8\x14\xcc\x11\xce\x0f\xd0\x0e\xc5'
b'\x06\xc5\r\xc4\n\xc4\x0c\xc4\n\xc4\x0b\xc4\x0c\xc4\n\xc4'
b'\x0c\xc4\n\xc4\x0c\xc4\n\xc3\r\xc4\t\xc4\x0e\xc3\t\xc4'
b'\x0e\xc4\x08\xc4\x0e\xc4\x08\xc4\x0e\xc4\x08\xc4\x0e\xc4\x08\xc3'
b'\x0f\xc4\x07\xc4\x10\xc4\x06\xc4\x10\xc4\x06\xc4\x10\xc4\x05\xc5'
b'\x10\xc4\x05\xc4\x12\xc4\x03\xc5\x12\xc5\x02\xdc\x01\xfc\x01\xdc'
b'\x0e\xc4\x1b\xc2\x0e'
)
# 2-bit RLE, generated from res/blestatus.png, 104 bytes
blestatus = (
b'\x02'
b'\x11 '
b'\x07\xc1\x10\xc2\x0f\xc3\x0e\xc4\r\xc5\x0c\xc6\x0b\xc7\n\xc3'
b'\x01\xc4\x03\xc2\x04\xc3\x02\xc4\x01\xc4\x03\xc3\x03\xc4\x01\xc4'
b'\x02\xc3\x02\xc4\x03\xc4\x01\xc3\x01\xc4\x05\xcb\x07\xc9\t\xc7'
b'\x0b\xc5\x0c\xc5\x0b\xc7\t\xc9\x07\xcb\x05\xc4\x01\xc3\x01\xc4'
b'\x03\xc4\x02\xc3\x02\xc4\x01\xc4\x03\xc3\x03\xc4\x01\xc2\x04\xc3'
b'\x02\xc4\x08\xc3\x01\xc4\t\xc7\n\xc6\x0b\xc5\x0c\xc4\r\xc3'
b'\x0e\xc2\x0f\xc1\t'
b'\x16 '
b'\x07\xc1\x15\xc2\x14\xc3\x13\xc4\x12\xc5\x11\xc6\x10\xc7\x0f\xc3'
b'\x01\xc4\x08\xc2\x04\xc3\x02\xc4\x06\xc4\x03\xc3\x03\xc4\x06\xc4'
b'\x02\xc3\x02\xc4\x08\xc4\x01\xc3\x01\xc4\n\xcb\x0c\xc9\x0e\xc7'
b'\x10\xc5\x11\xc5\x10\xc7\x0e\xc9\x0c\xcb\n\xc4\x01\xc3\x01\xc4'
b'\x08\xc4\x02\xc3\x02\xc4\x06\xc4\x03\xc3\x03\xc4\x06\xc2\x04\xc3'
b'\x02\xc4\r\xc3\x01\xc4\x0e\xc7\x0f\xc6\x10\xc5\x11\xc4\x12\xc3'
b'\x13\xc2\x14\xc1\x0e'
)

View file

@ -115,19 +115,22 @@ class Clock:
class NotificationBar:
"""Show BT status and if there are pending notifications."""
def __init__(self, x=8, y=8):
def __init__(self, x=2, y=8):
self._pos = (x, y)
def draw(self):
"""Update the notification widget.
"""Redraw the notification widget.
For this simple widget :py:meth:`~.draw` is simply a synonym for
:py:meth:`~.update`.
:py:meth:`~.update` because we unconditionally update from scratch.
"""
self.update()
def update(self):
"""Update the widget.
This widget does not implement lazy redraw internally since this
can often be implemented (with less state) by the container.
"""
draw = watch.drawable
(x, y) = self._pos
@ -135,14 +138,50 @@ class NotificationBar:
if wasp.watch.connected():
draw.blit(icons.blestatus, x, y, fg=0x7bef)
if wasp.system.notifications:
draw.blit(icons.notification, x+24, y, fg=0x7bef)
draw.blit(icons.notification, x+22, y, fg=0x7bef)
else:
draw.fill(0, x+24, y, 32, 32)
draw.fill(0, x+22, y, 30, 32)
elif wasp.system.notifications:
draw.blit(icons.notification, x, y, fg=0x7bef)
draw.fill(0, x+32, y, 32, 32)
draw.fill(0, x+30, y, 22, 32)
else:
draw.fill(0, x, y, 56, 32)
draw.fill(0, x, y, 52, 32)
class StatusBar:
"""Combo widget to handle notification, time and battery level."""
def __init__(self):
self._clock = Clock()
self._meter = BatteryMeter()
self._notif = NotificationBar()
@property
def clock(self):
"""True if the clock should be included in the status bar, False
otherwise.
"""
return self._clock.enabled
@clock.setter
def clock(self, enabled):
self._clock.enabled = enabled
def draw(self):
"""Redraw the status bar from scratch."""
self._clock.draw()
self._meter.draw()
self._notif.draw()
def update(self):
"""Lazily update the status bar.
:returns: An time tuple if the time has changed since the last call,
None otherwise.
"""
now = self._clock.update()
if now:
self._meter.update()
self._notif.update()
return now
class ScrollIndicator:
"""Scrolling indicator.