-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathconnectedframe.py
More file actions
executable file
·166 lines (120 loc) · 4.87 KB
/
connectedframe.py
File metadata and controls
executable file
·166 lines (120 loc) · 4.87 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python
from Tkinter import *
from os import putenv, getenv, system
from PIL import Image, ImageTk
from glob import glob
dropbox_link = getenv("DROPBOX_LINK")
download_interval = int(getenv("DOWNLOAD_INTERVAL_HOURS")) * 60 * 60 * 1000
carousel_interval = int(getenv("CAROUSEL_INTERVAL_SECONDS")) * 1000
frame_owner = getenv("FRAME_OWNER")
ifttt_key = getenv("IFTTT_KEY")
base_path = "/usr/src/app/images/"
carrousel_status = True
image_index = 0
image_list = []
initial_init = True
def download_images(url):
archive = base_path + "temp.zip"
remove = "sudo rm -rf " + base_path + "*"
download = "wget -q "+ url + " -O " + archive
extract = "unzip -o " + archive + " -d " + base_path
system(remove)
system(download)
system(extract)
def resize_images():
images = list_images()
for file in images:
img = Image.open(file)
img = img.resize((640, 480), Image.ANTIALIAS)
img.save(file, "JPEG")
def list_images():
images = []
dir = base_path + "*.jpg"
images = glob(dir)
return images
def previous_image():
global image_index
image_index = image_index - 1
if image_index < 0:
image_index = len(image_list) - 1
image_path = image_list[image_index]
update_image(image_path)
def next_image():
global image_index
image_index = image_index + 1
if image_index > len(image_list) - 1:
image_index = 0
image_path = image_list[image_index]
update_image(image_path)
def play_pause():
global carrousel_status
carrousel_status = not carrousel_status
if(carrousel_status):
img = ImageTk.PhotoImage(Image.open("/usr/src/app/icons/pause.png"))
else:
img = ImageTk.PhotoImage(Image.open("/usr/src/app/icons/play.png"))
play_button.configure(image=img)
play_button.image = img
def carrousel():
if(carrousel_status):
next_image()
root.after(carousel_interval, carrousel)
def update_image(image_path):
img = ImageTk.PhotoImage(Image.open(image_path))
center_label.configure(image=img)
center_label.image = img
img = ImageTk.PhotoImage(Image.open("/usr/src/app/icons/like.png"))
like_button.configure(image=img)
like_button.image = img
def initialize():
global image_list, carrousel_status, initial_init
current_carrousel_status = carrousel_status
carrousel_status = False
download_images(dropbox_link)
resize_images()
image_list = list_images()
carrousel_status = current_carrousel_status
if(initial_init):
initial_init = False
root.after(1000, initialize)
else:
root.after(download_interval, initialize)
def send_event():
img = ImageTk.PhotoImage(Image.open("/usr/src/app/icons/liked.png"))
like_button.configure(image=img)
like_button.image = img
command = "curl -X POST -H \"Content-Type: application/json\" -d '{\"value1\":\"" + frame_owner + "\",\"value2\":\"" + image_list[image_index] + "\"}' https://maker.ifttt.com/trigger/connectedframe_like/with/key/" + ifttt_key
system(command)
root = Tk()
root.title('Connected Frame')
root.geometry('{}x{}'.format(800, 480))
root.attributes("-fullscreen", True)
root.config(cursor='none')
initialize()
left_column = Frame(root, bg='black', width=80, height=480)
center_column = Frame(root, bg='black', width=640, height=480)
right_column = Frame(root, bg='black', width=80, height=480)
left_column.pack_propagate(0)
center_column.pack_propagate(0)
right_column.pack_propagate(0)
left_column.grid(row=0, column=0, sticky="nsew")
center_column.grid(row=0, column=1, sticky="nsew")
right_column.grid(row=0, column=2, sticky="nsew")
next_icon = ImageTk.PhotoImage(Image.open("/usr/src/app/icons/next.png"))
previous_icon = ImageTk.PhotoImage(Image.open("/usr/src/app/icons/previous.png"))
play_icon = ImageTk.PhotoImage(Image.open("/usr/src/app/icons/pause.png"))
like_icon = ImageTk.PhotoImage(Image.open("/usr/src/app/icons/like.png"))
previous_button = Button(left_column, image=previous_icon, borderwidth=0, background="black", foreground="white", activebackground="black", activeforeground="white", highlightthickness=0, command=previous_image)
next_button = Button(left_column, image=next_icon, borderwidth=0, background="black", foreground="white", activebackground="black", activeforeground="white", highlightthickness=0, command=next_image)
play_button = Button(right_column, image=play_icon, borderwidth=0, background="black", foreground="white", activebackground="black", activeforeground="white", highlightthickness=0, command=play_pause)
like_button = Button(right_column, image=like_icon, borderwidth=0, background="black", foreground="white", activebackground="black", activeforeground="white", highlightthickness=0, command=send_event)
center_image = Image.open(image_list[0])
center_photo = ImageTk.PhotoImage(center_image)
center_label = Label(center_column, image=center_photo)
previous_button.pack(fill=BOTH, expand=1)
next_button.pack(fill=BOTH, expand=1)
center_label.pack(side="bottom", fill=BOTH, expand=1)
play_button.pack(fill=BOTH, expand=1)
like_button.pack(fill=BOTH, expand=1)
carrousel()
root.mainloop()