-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-to-leds-gui.py
73 lines (60 loc) · 2.56 KB
/
send-to-leds-gui.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
import tkinter as tk
from tkinter import messagebox, INSERT
import json
old_output = {}
try:
with open("gui-info.json", "r") as infile:
old_output = json.load(infile)
except FileNotFoundError:
print("Couldn't find gui-info.json, moving on...")
def on_closing():
save()
window.destroy()
def save():
output = {}
for location in all_locations:
output[location] = {}
for message in all_messages:
output[location][message] = check_buttons[location][message].get()
if message == "Custom message":
text_in_box = custom_text[location].get("1.0", "end")[:-1]
if len(text_in_box) > 0:
output[location]["text"] = text_in_box
else:
output[location][message] = check_buttons[location][message].get()
with open("gui-info.json", "w") as outfile:
json.dump(output, outfile)
return output
def send_button():
output = save()
messagebox.showinfo("hello", "{0}".format(output))
all_messages = ['PPH', 'eComm', 'Good morning', 'Good job everybody', "Custom message"]
all_locations = ['All Cells', 'C1 + C2', 'C4 / Cutting', 'C5', 'C8', 'C9', 'C13 + C14'] # TODO: fix networking to take these as well as LED IDs
window = tk.Tk()
window.protocol("WM_DELETE_WINDOW", on_closing)
window.title("Send to LEDs")
check_buttons = {}
custom_text = {}
# Loads up the GUI
for i, location in enumerate(all_locations):
led_id = i + 1
location_label = tk.Label(text = location)
location_label.grid(column = i, row = 0, sticky = 'w')
check_buttons[location] = {}
for j, message in enumerate(all_messages):
check_buttons[location][message] = tk.IntVar()
check_button = tk.Checkbutton(text="{0}".format(message),
variable = check_buttons[location][message])
# check the old buttons that were checked previously
if old_output != {} and location in old_output and message in old_output[location]:
if old_output[location][message] == 1:
check_button.select()
check_button.grid(column = i, row = j + 1, sticky = 'w')
custom_text[location] = tk.Text(width = 20, height = 3)
if old_output != {} and 'text' in old_output[location]:
text = old_output[location]['text']
custom_text[location].insert(INSERT, text) # TODO: get the old custom text into the box
custom_text[location].grid(column = i, row = j + 2)
button = tk.Button(text = 'Send', command = send_button)
button.grid(column = 0, sticky = 'w')
window.mainloop()