-
Notifications
You must be signed in to change notification settings - Fork 2
/
informer.py
132 lines (99 loc) · 3.3 KB
/
informer.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
import os
import threading
from guizero import App, Text, Picture, TextBox
import simpleaudio.functionchecks as fc
from PIL import Image, ExifTags
banner = None
picture = None
def getPicture(imageUrl):
global picture
basewidth = 1024
baseheight = 768
app = App(title="Picture")
app.width = basewidth
app.height = baseheight
app.tk.attributes("-fullscreen", True)
drawPicture(imageUrl, app)
app.display()
picture = None
app = None
return picture
def drawPicture(imageUrl, master):
basewidth = 1024
baseheight = 768
global picture
if picture is not None:
master = picture.master
picture.destroy()
master.focus()
pilImage = rotateByExif(Image.open(imageUrl))
if (pilImage.size[1] > pilImage.size[0]):
basewidth = int(float(baseheight) / float(pilImage.size[1]) * float(pilImage.size[0]))
wpercent = (basewidth / float(pilImage.size[0]))
hsize = int((float(pilImage.size[1]) * float(wpercent)))
rpil = pilImage.resize((basewidth, hsize), Image.ANTIALIAS)
picture = Picture(master, image=rpil)
return picture
def rotateByExif(image):
try:
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation] == 'Orientation':
break
exif = dict(image._getexif().items())
if exif[orientation] == 3:
image = image.rotate(180, expand=True)
elif exif[orientation] == 6:
image = image.rotate(270, expand=True)
elif exif[orientation] == 8:
image = image.rotate(90, expand=True)
except (AttributeError, KeyError, IndexError):
# cases: image don't have getexif
pass
return image
def getBanner(text):
global banner
if banner == None:
app = App(title="Information")
app.width = 1200
app.height = 1090
app.tk.attributes("-fullscreen", True)
banner = TextBox(app, text=text, width="fill", height="fill", multiline=True, align="top")
banner.text_size = 50
banner.text_color = "red"
app.display()
banner = None
return banner
def updateBanner(text):
global banner
if banner is None:
banner = getBanner(text)
if banner is not None:
banner.value = text
banner.master.focus()
def updatePicture(filename):
global picture
if picture is None:
getPicture(filename)
else:
master = picture.master
drawPicture(filename, master)
def showPicture(filename):
focus_thread = threading.Thread(target=takeFocus, args=(False,))
focus_thread.start()
picture_thread = threading.Thread(target=updatePicture, args=(filename,))
picture_thread.start()
def showBanner(message):
focus_thread = threading.Thread(target=takeFocus, args=(True,))
focus_thread.start()
banner_thread = threading.Thread(target=updateBanner, args=(message,))
banner_thread.start()
def takeFocus(withMusic):
os.system('echo "on 0" | cec-client RPI -s -d 1')
os.system('echo "as" | cec-client RPI -s -d 1')
if withMusic == True:
fc.LeftRightCheck.run()
def switchOffTv():
os.system('echo "standby 0" | cec-client RPI -s -d 1')
def switchOnTv():
os.system('echo "on 0" | cec-client RPI -s -d 1')
os.system('echo "as" | cec-client RPI -s -d 1')