chutney/time_display.py

42 lines
1.5 KiB
Python

from datetime import datetime
class TimeDisplay:
def __init__(self, character_display, lineTop):
self.displayedHourParts = [-1, -1]
self.displayedMinuteParts = [-1, -1]
self.character_display = character_display
self.lineTop = lineTop
self.character_display.displayTimeDots(7, self.lineTop)
def showTime(self):
hourParts = self.getTimeParts('%l')
minuteParts = self.getTimeParts('%M')
if hourParts[0] != self.displayedHourParts[0]:
self.displayedHourParts[0] = hourParts[0]
if hourParts[0] == 0:
self.character_display.clearNumberPixels(-1, self.lineTop)
else:
self.character_display.displayNumber(-1, self.lineTop, hourParts[0])
if hourParts[1] != self.displayedHourParts[1]:
self.displayedHourParts[1] = hourParts[1]
self.character_display.displayNumber(3, self.lineTop, hourParts[1])
if minuteParts[0] != self.displayedMinuteParts[0]:
self.displayedMinuteParts[0] = minuteParts[0]
self.character_display.displayNumber(9, self.lineTop, minuteParts[0])
if minuteParts[1] != self.displayedMinuteParts[1]:
self.displayedMinuteParts[1] = minuteParts[1]
self.character_display.displayNumber(13, self.lineTop, minuteParts[1])
def getTimeParts(self, timePart):
parts = datetime.now().strftime(timePart).strip().rjust(2, "0")
return [int(x) for x in parts]