from datetime import datetime class TimeDisplay: def __init__(self, characterDisplay, topRow): self.characterDisplay = characterDisplay self.topRow = topRow self.currentHour = [-1, -1] self.currentMinute = [-1, -1] self.currentColor = (0, 0, 0) self.color = (255, 80, 0) self.hourStartColumn = -1 self.timeDotsColumn = 7 self.minuteStartColumn = 9 self.characterDisplay.displayTimeDots( x=self.timeDotsColumn, y=self.topRow, color=self.color ) def showTime(self): self.showHour(self.getHourDigits()) self.showMinute(self.getMinuteDigits()) def showHour(self, hour): if hour[0] != self.currentHour[0]: self.currentHour[0] = hour[0] if hour[0] == 0: self.characterDisplay.clearDigit( x=self.hourStartColumn, y=self.topRow ) else: self.characterDisplay.displayDigit( x=self.hourStartColumn, y=self.topRow, digit=hour[0], color=self.color ) if hour[1] != self.currentHour[1]: self.currentHour[1] = hour[1] self.characterDisplay.displayDigit( x=self.hourStartColumn + 4, y=self.topRow, digit=hour[1], color=self.color ) def showMinute(self, minute): if minute[0] != self.currentMinute[0]: self.currentMinute[0] = minute[0] self.characterDisplay.displayDigit( x=self.minuteStartColumn, y=self.topRow, digit=minute[0], color=self.color ) if minute[1] != self.currentMinute[1]: self.currentMinute[1] = minute[1] self.characterDisplay.displayDigit( x=self.minuteStartColumn + 4, y=self.topRow, digit=minute[1], color=self.color ) def getHourDigits(self): return self.getTimeDigits('%l') def getMinuteDigits(self): return self.getTimeDigits('%M') def getTimeDigits(self, format): digits = datetime.now().strftime(format).strip().rjust(2, '0') return [int(x) for x in digits]