Add watchface with weekday

* Allow overriding of date string in clock.py
* Override it to display the weekday in week_clock.py

Signed-off-by: Francesco Gazzetta <fgaz@fgaz.me>
This commit is contained in:
Francesco Gazzetta 2021-12-31 19:16:12 +01:00 committed by Daniel Thompson
parent 1c3a835448
commit 4b7cf88576
7 changed files with 47 additions and 6 deletions

View File

@ -246,6 +246,10 @@ application (and the "blank" white screen is a torch application):
:alt: Weather application running in the wasp-os simulator
:width: 179
.. image:: res/WeekClkApp.png
:alt: Digital clock application, including the week day
:width: 179
.. image:: res/WordClkApp.png
:alt: Shows a time as words in the wasp-os simulator
:width: 179

View File

@ -19,6 +19,8 @@ Watch faces
.. automodule:: apps.fibonacci_clock
.. automodule:: apps.week_clock
.. automodule:: apps.word_clock
Built-in

BIN
res/WeekClkApp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@ -62,6 +62,14 @@ class ClockApp():
wasp.system.bar.clock = False
self._draw(True)
def _day_string(self, now):
"""Produce a string representing the current day"""
# Format the month as text
month = now[1] - 1
month = MONTH[month*3:(month+1)*3]
return '{} {} {}'.format(now[2], month, now[0])
def _draw(self, redraw=False):
"""Draw or lazily update the display.
@ -93,18 +101,13 @@ class ClockApp():
# Skip the update
return
# Format the month as text
month = now[1] - 1
month = MONTH[month*3:(month+1)*3]
# Draw the changeable parts of the watch face
draw.blit(DIGITS[now[4] % 10], 4*48, 80, fg=hi)
draw.blit(DIGITS[now[4] // 10], 3*48, 80, fg=lo)
draw.blit(DIGITS[now[3] % 10], 1*48, 80, fg=hi)
draw.blit(DIGITS[now[3] // 10], 0*48, 80, fg=lo)
draw.set_color(hi)
draw.string('{} {} {}'.format(now[2], month, now[0]),
0, 180, width=240)
draw.string(self._day_string(now), 0, 180, width=240)
# Record the minute that is currently being displayed
self._min = now[4]

View File

@ -24,6 +24,7 @@ class FacesApp():
"""Activate the application."""
choices = []
choices.append(('clock', 'Clock'))
choices.append(('week_clock', 'WeekClock'))
choices.append(('chrono', 'Chrono'))
choices.append(('dual_clock', 'DualClock'))
choices.append(('fibonacci_clock', 'FibonacciClock'))

30
wasp/apps/week_clock.py Normal file
View File

@ -0,0 +1,30 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (C) 2022 Francesco Gazzetta
"""Digital clock with weekday
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shows a time (as HH:MM) together with a battery meter, the date, and the weekday.
.. figure:: res/WeekClkApp.png
:width: 179
"""
from apps.clock import ClockApp, MONTH
WDAY = 'MonTueWedThuFriSatSun'
class WeekClockApp(ClockApp):
NAME = 'WeekClk'
def _day_string(self, now):
"""Produce a string representing the current day"""
# Format the month as text
month = now[1] - 1
month = MONTH[month*3:(month+1)*3]
# Format the weekday as text
wday = now[6]
wday = WDAY[wday*3:(wday+1)*3]
return '{} {} {} {}'.format(wday, now[2], month, now[0])

View File

@ -28,6 +28,7 @@ manifest = (
'apps/testapp.py',
'apps/timer.py',
'apps/weather.py',
'apps/week_clock.py',
'apps/word_clock.py',
'fonts/__init__.py',
'fonts/clock.py',