/
clock.py
executable file
·148 lines (130 loc) · 4.78 KB
/
clock.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
import os
import multiprocessing as mp
#import time
import pygame
from pygame.locals import *
#from time import localtime
from datetime import datetime
from screen import screen
from timekeeper import timekeeper
from separator import separator
from calendar import calendar
from alarm import alarm
class clock :
def __init__(self) :
self.default_color = (255, 255, 0)
self.default_s_color = (127, 127, 0)
self.a_color = (255, 255, 0)
self.a_s_color = (127, 0, 0)
self.b_color = (0, 0, 0)
self.default_font = 'data/Roboto-Light.ttf'
self.clock = pygame.time.Clock()
self.screen = screen()
pygame.mouse.set_visible(False)
#self.font = pygame.font.Font('segoeui.ttf', 126)
self.font = pygame.font.Font(self.default_font, 190)
self.dateFont = pygame.font.Font(self.default_font, 36)
os.putenv('SDL_MOUSEDRV', 'TSLIB')
os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen')
def touch(self, updates) :
tx = datetime.today()
while True :
self.clock.tick(10)
# Scan touchscreen events
for event in pygame.event.get():
if(event.type is MOUSEBUTTONDOWN):
#pos = pygame.mouse.get_pos()
#print("Down: " + str(pos))
ts = datetime.today()
elif(event.type is MOUSEBUTTONUP):
pos = pygame.mouse.get_pos()
#print("Up: " + str(pos))
updates.put({'ts': ts, 'pos': pos})
def run(self) :
touchQ = mp.Queue()
touchT = mp.Process(target=self.touch, args=(touchQ,))
touchT.start()
tq = mp.Queue()
tk = timekeeper(tq)
tk.start()
sq = mp.Queue()
sp = separator(sq)
sp.start()
dq = mp.Queue()
cd = calendar(dq)
cd.start()
aq = mp.Queue()
al = alarm(aq)
al.start()
current = "Starting"
currentSep = ""
currentDate = "Aquiring calendar data"
currentAlarm = ""
#lastTime = ""
while 1:
self.clock.tick(100)
newTouch = None
try :
newTouch = touchQ.get_nowait()
except mp.queues.Empty :
pass
if (newTouch) :
print (newTouch)
newTime = None
try :
newTime = tq.get_nowait()
except mp.queues.Empty :
pass
if (newTime) :
current = newTime
newSep = None
try :
newSep = sq.get_nowait()
except mp.queues.Empty :
pass
if (newSep) :
currentSep = newSep
newDate = None
try :
newDate = dq.get_nowait()
except mp.queues.Empty :
pass
if (newDate) :
currentDate = newDate
newAlarm = None
try :
newAlarm = aq.get_nowait()
except mp.queues.Empty :
pass
if (newAlarm) :
currentAlarm = newAlarm
#if(lastTime != current) :
if (newTime or newSep or newDate or newAlarm) :
if (currentAlarm == "alarm") :
color = self.a_color
s_color = self.a_s_color
else :
color = self.default_color
s_color = self.default_s_color
time_surface = self.font.render(current, True, color)
time_surface_shadow = self.font.render(current, True, s_color)
colon_surface = self.font.render(currentSep, True, color)
colon_surface_shadow = self.font.render(currentSep, True, s_color)
#tz_surface = self.font.render(tz, True, color)
date_surface = self.dateFont.render(currentDate, True, color)
date_surface_shadow = self.dateFont.render(currentDate, True, s_color)
self.screen.scr.fill(self.b_color)
self.screen.scr.blit(time_surface_shadow, (8, 26))
self.screen.scr.blit(time_surface, (2, 22))
self.screen.scr.blit(colon_surface_shadow, (227, 26))
self.screen.scr.blit(colon_surface, (223, 22))
#self.screen.scr.blit(tz_surface, (120, 196))
#self.screen.scr.blit(tz_surface, (120, 196))
self.screen.scr.blit(date_surface_shadow, (12, 12))
self.screen.scr.blit(date_surface, (10, 10))
#lastTime = current
pygame.display.update()
if __name__ == '__main__' :
c = clock()
c.run()