-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
153 lines (120 loc) · 4.2 KB
/
main.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
149
150
151
152
from tkinter import *
import tkinter
from PIL import ImageTk,Image
import read_interface
import gui
def load_app_imgs(program : gui.gui_program):
frameCnt = 44
frames = program.get_ref('temp-gif')
if not frames:
frames = [PhotoImage(file='./icons/term.gif', format='gif -index %i' %(i))
for i in range(frameCnt)]
program.set_ref('temp-gif', frames)
bulbFrm = 30
lightframs = program.get_ref('light-gif')
if not lightframs:
lightframs = [PhotoImage(file='./icons/light.gif', format='gif -index %i' %(i))
for i in range(bulbFrm)]
program.set_ref('light-gif', lightframs)
def clear_app_frame(program : gui.gui_program):
for widgets in program.get_frame('app').winfo_children():
widgets.destroy()
def inicio_fn(program : gui.gui_program):
if program.get_state() == 'inicio':
return
clear_app_frame(program)
img = program.get_ref('inicio_img')
if not img:
img = Image.open('./icons/inicio.png')
img = img.resize((850, 700), Image.ANTIALIAS)
img = ImageTk.PhotoImage(img)
img = program.set_ref('inicio_img', img)
elem = program.push_to_frame('app', Label, image=img)
elem.pack()
program.set_state('inicio')
def monitor_fn(program : gui.gui_program):
if program.get_state() == 'monitor':
return
clear_app_frame(program)
program.def_frame(program.get_frame('app'), 'Temp', text='Temp',
height=720, width=430).grid(row=0,column=0)
program.get_frame('Temp').pack_propagate(False)
program.get_frame('Temp').grid_propagate(False)
program.def_frame(program.get_frame('app'), 'Light', text='Luz',
height=720, width=430).grid(row=0,column=1)
program.get_frame('Light').pack_propagate(False)
program.get_frame('Light').grid_propagate(False)
frameCnt = 44
frames = program.get_ref('temp-gif')
bulbFrm = 30
lightframs = program.get_ref('light-gif')
tmpdat = program.push_to_frame('Temp', Label, text='0')
tmpanim = program.def_elem(program.get_frame('Temp'), 'Temp-anim', Label)
tmpanim.pack()
tmpdat.pack()
lgtdat = program.push_to_frame('Light', Label, text='0')
lgtanim = program.def_elem(program.get_frame('Light'), 'Light-anim', Label)
lgtanim.pack()
lgtdat.pack()
program.set_state('monitor')
i = 0
j = 0
com = read_interface.reader(0, 255)
while program.get_state() != 'exit':
adc = com.poll()
i = com.inrange(0, frameCnt)
j = com.inrange(1, bulbFrm)
program.root.after(5)
program.get_frame('Temp').update()
program.get_frame('Light').update()
VS = [(5/255)*adc[0], (5/255)*adc[1]]
VSstr = ['{:.2f}'.format(VS[0]), '{:.2f}'.format(VS[1])]
tmpdat.configure(text=f'Frame{i}\n\nADC:{adc[0]}\n\nV:{VSstr[0]}')
tmpanim.configure(image=frames[i])
lgtdat.configure(text=f'Frame:{j}\n\nADC:{adc[1]}\n\nV:{VSstr[1]}')
lgtanim.configure(image=lightframs[j])
def ayuda_fn(program : gui.gui_program):
if program.get_state() == 'ayuda':
return
clear_app_frame(program)
ref = program.push_to_frame('app', Label, text='Ayuda')
ref.pack()
program.set_state('ayuda')
def exit_fn(program : gui.gui_program):
program.set_state('exit')
program.root.quit()
def main():
program = gui.gui_program(
'Instru-Monitor', './icons/programico.png', (1080, 720),
height=720, width=1080
)
program.get_frame('main').pack()
program.get_frame('main').grid_propagate(False)
program.root.resizable(False, False)
program.def_frame(
program.get_frame('main'), 'menu', text='Menu', height=720, width=200
).grid(row=0, column=0)
program.get_frame('menu').pack_propagate(False)
program.get_frame('menu').grid_propagate(False)
program.def_frame(
program.get_frame('main'), 'app', text='App', height=720, width=880
).grid(row=0, column=1)
program.get_frame('app').pack_propagate(False)
program.get_frame('app').grid_propagate(False)
menu_strings = ['Inicio', 'Monitor', 'Ayuda', 'Salir']
menu_functors = [
lambda p=program: inicio_fn(p), lambda p=program: monitor_fn(p),
lambda p=program: ayuda_fn(p), lambda p=program: exit_fn(p)
]
pixel = tkinter.PhotoImage(width=1, height=1)
for s,f in zip(menu_strings, menu_functors):
b = program.push_to_frame(
'menu', Button, text=s, image=pixel, width=200/1.5, height=720/4.5,
compound='c', command=f
)
b.pack(side=TOP)
load_app_imgs(program)
inicio_fn(program)
program.start_gui()
if __name__=="__main__":
main()