This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
forked from thomas-/stationclock
-
Notifications
You must be signed in to change notification settings - Fork 1
/
texts.py
111 lines (80 loc) · 3.11 KB
/
texts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import pygame
import time
from pygame.sprite import Sprite
import settings
from utils import make_readable_time, make_backtimer_time
pygame.font.init()
class TextSprite(Sprite):
def __init__(self):
Sprite.__init__(self)
self.font = self.get_font()
self.update()
def render(self, string, color):
return self.font.render(string, True, color)
def update(self, *args, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
string, color = self.get_details()
self.image = self.render(string, color)
self.rect = self.image.get_rect()
self.set_position(self.rect)
def get_font(self):
return pygame.font.Font(settings.DATE_FONT, 32)
def get_details(self, *args, **kwargs):
return str('string'), (255, 255, 255)
def set_position(self, rect):
pass
class Date(TextSprite):
def get_font(self):
return pygame.font.Font(settings.DATE_FONT, settings.DATE_FONT_SIZE)
def get_details(self):
return time.strftime("%A %d %B"), (255, 255, 255)
def set_position(self, rect):
rect.top = 0 + settings.PADDING
rect.right = settings.RESOLUTION[0] - settings.PADDING
class ReadableTime(TextSprite):
def get_font(self):
return pygame.font.Font(settings.DATE_FONT, settings.DATE_FONT_SIZE)
def get_details(self):
return make_readable_time(), (255, 255, 255)
def set_position(self, rect):
rect.top = 0 + settings.PADDING
rect.left = 0 + settings.PADDING
class DigitalClock(TextSprite):
def get_font(self):
return pygame.font.Font(settings.CLOCK_FONT, settings.CLOCK_FONT_SIZE)
def get_details(self):
return time.strftime("%H:%M"), (255, 0, 0)
def set_position(self, rect):
rect.midbottom = (settings.RESOLUTION[0]/2, settings.RESOLUTION[1]/2 + 10)
class Backtimer(TextSprite):
def get_font(self):
return pygame.font.Font(settings.BACKTIMER_FONT, settings.BACKTIMER_FONT_SIZE)
def get_details(self):
return make_backtimer_time(), (0, 255, 0)
def set_position(self, rect):
rect.midtop = (settings.RESOLUTION[0]/2, settings.RESOLUTION[1]/2 + 10)
class Show(TextSprite):
value = 'No Show'
now_playing = False
def get_font(self):
return pygame.font.Font(settings.INFO_FONT, settings.INFO_FONT_SIZE)
def get_details(self):
return self.value, (41, 255, 211)
def set_position(self, rect):
if self.now_playing: extra = 50
else: extra = 0
rect.left = 0 + settings.PADDING
rect.bottom = settings.RESOLUTION[1] - settings.PADDING - extra
class Studio(TextSprite):
value = 0
now_playing = False
def get_font(self):
return pygame.font.Font(settings.INFO_FONT, settings.INFO_FONT_SIZE)
def get_details(self):
return 'Live from Studio %s' % self.value, (150, 255, 211)
def set_position(self, rect):
if self.now_playing: extra = 50
else: extra = 0
rect.right = settings.RESOLUTION[0] - settings.PADDING
rect.bottom = settings.RESOLUTION[1] - settings.PADDING - extra