forked from techdiem/RasPi-OLED-Menu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelperFunctions.py
More file actions
78 lines (71 loc) · 2.38 KB
/
helperFunctions.py
File metadata and controls
78 lines (71 loc) · 2.38 KB
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
from PIL import ImageFont
from setupHandler import device, client, establishConnection
from globalParameters import globalParameters, mediaVariables
from subprocess import call
from time import sleep
import threading
from luma.core.render import canvas
def drawMenu(draw, entries):
counter = globalParameters.counter
position = 0
#Draw menu
for i in range(len(entries)):
x = 6
y = 2+position*12
fontawesome = ImageFont.truetype(globalParameters.font_icons, size=10)
font = ImageFont.truetype(globalParameters.font_text, size=10)
draw.rectangle((x, y, x+120, y+12), outline=255, fill=0)
if entries[i] == "Zurück":
draw.text((x+2, y+2), text="\uf053", font=fontawesome, fill="white")
draw.text((x+12, y+1), "Zurück", font=font, fill="white")
else:
draw.text((x+2, y+1), entries[i], font=font, fill="white")
position += 1
#Draw entry selector
draw.polygon(((0, 2+counter*12), (0, 10+counter*12), (5, 6+counter*12)), fill="white")
def shutdownSystem():
print("Shutting down system")
try:
client.stop()
except: pass
device.cleanup()
call("sudo shutdown -h now", shell=True)
exit()
def playRadioStation(stationid):
print("Playing ID", stationid)
try:
client.play(stationid)
except:
print("Error playing the station!")
establishConnection()
globalParameters.setScreen(0)
def playbackControl(command):
try:
if command == "pause": client.pause()
elif command == "previous": client.previous()
elif command == "next": client.next()
elif command == "play": client.play()
print("Playback:", command)
except:
print("Error changing the playback mode!")
establishConnection()
globalParameters.setScreen(0)
def loadRadioStations():
try:
client.clear()
client.load("[Radio Streams]")
mediaVariables.loadedPlaylist = "[Radio Streams]"
except:
print("Error loading radio station playlist!")
establishConnection()
def loadPlaylist(name):
try:
client.clear()
client.load(name)
client.shuffle()
mediaVariables.loadedPlaylist = name
print("Loaded and playing Playlist", name)
client.play()
except:
print("Error loading and playing Playlist", name)
establishConnection()