-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoclock.py
executable file
·75 lines (67 loc) · 2.27 KB
/
oclock.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
#!/usr/bin/env python
# On-line clock
import pygame, os, sys, time
class tc:
def __init__(s):
pygame.init()
s.res = 288, 66
s.screen = pygame.display.set_mode(s.res)
s.out = pygame.Surface(s.res)
pygame.display.set_caption("Off-Line")
s.clock = pygame.time.Clock()
s.font = pygame.font.Font("OCRA.otf", 50)
s.online = False
s.total = 0
if len(sys.argv) > 1:
s.total = 60 * int(sys.argv[1])
s.last = 0
def events(s):
for event in pygame.event.get():
if event.type == pygame.QUIT:
s.running = False
if (event.type == pygame.KEYDOWN and event.key == pygame.K_o):
s.online = not s.online
if s.online:
pygame.display.set_caption("On-Line")
else:
pygame.display.set_caption("Off-Line")
s.last = time.time()
# round up time to nearest minute when stopping:
if s.online == False:
s.total = 60 * (s.total // 60 + 1)
else:
# from https://freesound.org/people/wtermini/sounds/546450/
os.system("/usr/bin/play -q modem.flac &")
# reset:
if (s.online == False and event.type == pygame.KEYDOWN and event.key == pygame.K_r):
s.total = 0
# add one minute:
if (s.online == False and event.type == pygame.KEYDOWN and event.key == pygame.K_a):
s.total += 60
def run(s):
s.running = True
while s.running:
s.clock.tick(10)
s.events()
s.update()
pygame.quit()
def update(s):
if s.online:
tt = time.time()
s.total += tt - s.last
s.last = tt
s.screen.fill((0, 0, 0))
col = 0, 255, 0
else:
s.screen.fill((140, 140, 140))
col = 0, 0, 0
mins = s.total // 60
hours = mins // 60
mins = mins % 60
t = "%02u:%02u:%02u" % (hours, mins, s.total % 60)
tr = s.font.render(t, True, col)
#print(tr.get_size())
s.screen.blit(tr, (0, 0))
pygame.display.flip()
c = tc()
c.run()