-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
289 lines (219 loc) · 8.77 KB
/
app.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
from tkinter import *
import tkinter.messagebox
from tkinter import ttk
import matplotlib.pyplot as plt
import requests
import serial
import sys
import os
# Email Professora: jane.s.p.i@hotmail.com
menu = """
\tProff: Rosana
\tSerie: 2-B
\tPowered by C.E.S.P
"""
root = Tk()
def Creditos():
cred = Tk()
cred['bg'] = 'white'
cred.title('Creditos')
Label(cred, text=menu, bg='white').place(x=3,y=10)
Frame(cred, height=3, width=200, bd=1, relief=SUNKEN).place(x=10,y=20)
Frame(cred, height=3, width=200, bd=1, relief=SUNKEN).place(x=10,y=120)
cred.geometry('230x150')
cred.mainloop()
def Exit():
sys.exit()
header = {'User-Agent':"Mozilla /5.0 (Compatible MSIE 9.0;Windows NT 6.1;WOW64; Trident/5.0)"}
nome_calorias = ""
calorias = 0
data = [
("Bacon", 1, 5.41),
("Pao", 1, 3.0),
("Ovos Fritos", 1, 2.4),
("Pizza de Mussarela", 1, 2.45),
("Arroz", 1, 1.28),
("Macarrao Cozido", 1, 1.58),
("Mortadela", 1, 2.69),
("Frango Cozido", 1, 1.63),
("Salame", 1, 3.98),
("Iogurte", 1, 1.01),
("Mandioca Cozida", 1, 1.44),
("Tomate", 1, 0.15),
("Mandioca Cozida", 1, 1.44),
("Banana", 1, 0.99),
("Carne de Porco", 1, 2.62),
("Pao de Queijo", 1, 2.3)
]
def Arduino():
root = Tk()
root.title("Configurar Arduino / Porta")
root['bg'] = "white"
status_msg = False
msng = "offline"
menubar = Menu(root)
root.config(menu=menubar)
filemenu = Menu(root)
menubar.add_cascade(label='Menu', menu=filemenu)
filemenu.add_command(label='Alimentos', command=app_alimentos)
filemenu.add_command(label='Somar Calorias', command=somar_calorias)
filemenu.add_command(label='Adicionar Alimentos', command=add_alimentos)
filemenu.add_command(label='Configurar Arduino', command=Arduino)
filemenu.add_command(label='Grafico', command=grafico)
filemenu.add_command(label='Creditos', command=Creditos)
filemenu.add_command(label='Exit', command=Exit)
root.grid()
Label(root, text="Porta USB Arduino: ", font="Arial 10", bg='white').place(x=5, y=30)
porta = Entry(root)
porta.place(x=10, y=70)
Label(root, text="BaudRate (Velocidade da Porta): ", font="Arial 10", bg='white').place(x=5, y=110)
baudrate = Entry(root)
baudrate.place(x=10, y=150)
Label(root, text="Timeout (Tempo de Resposta): ", font="Arial 10", bg='white').place(x=5, y=190)
time = Entry(root)
time.place(x=10, y=230)
Label(root, text="Status: {}".format(msng), font="Arial 10", fg='red', bg="white").place(x=5, y=280)
def conectar():
if porta.get() and baudrate.get():
msng = "Conectado!"
Label(root, text="Status: {}".format(msng), font="Arial 10", fg='green', bg="white").place(x=5, y=280)
ser = serial.Serial(porta.get(), int(baudrate.get()))
tkinter.messagebox.showinfo('information', "Arduino Conectado!\n\nStatus Porta: {}\nDispositivo conectado: {}\n".format(ser.isOpen(), ser.name))
ser.write(b"init")
line = ser.readline()
print(line)
#tkinter.messagebox.showinfo('information', 'Data from Arduino: {}'.format(line.decode()))
#ser.close()
else:
tkinter.messagebox.showinfo('warning', "Dados invalidos!")
Button(root, text="Iniciar comunicação", font="Arial 10", bg='white', command=conectar).place(x=35, y=320)
root.geometry("300x400")
def app_alimentos():
alimentos = Tk()
alimentos.title('Alimentos Listados')
alimentos['bg'] = 'white'
menubar = Menu(alimentos)
alimentos.config(menu=menubar)
filemenu = Menu(menubar)
menubar.add_cascade(label='Menu', menu=filemenu)
filemenu.add_command(label='Alimentos', command=app_alimentos)
filemenu.add_command(label='Somar Calorias', command=somar_calorias)
filemenu.add_command(label='Adicionar Alimentos', command=add_alimentos)
filemenu.add_command(label='Configurar Arduino', command=Arduino)
filemenu.add_command(label='Grafico', command=grafico)
filemenu.add_command(label='Creditos', command=Creditos)
filemenu.add_command(label='Exit', command=Exit)
alimentos.grid()
dataCols = ('Alimentos Processados', 'Peso (Kg)', '(kcal, kJ)')
tree = ttk.Treeview(alimentos, columns=dataCols, show='headings')
tree.grid(row=0, column=0, sticky=N + S + W + E)
ysb = ttk.Scrollbar(alimentos, orient=VERTICAL, command=tree.yview)
xsb = ttk.Scrollbar(alimentos, orient=HORIZONTAL, command=tree.xview)
tree['yscroll'] = ysb.set
tree['xscroll'] = xsb.set
ysb.grid(row=0, column=1, sticky=N + S)
xsb.grid(row=1, column=0, sticky=E + W)
for c in dataCols:
tree.heading(c, text=c.title())
for item in data:
tree.insert('', 'end', values=item)
alimentos.mainloop()
def calculate_kcal():
Label(root, text="Entre com a Massa do Alimento: ", font="Arial 10", bg='white').place(x=5, y=50)
Frame(root, height=3, width=250, bd=1, relief=SUNKEN).place(x=15,y=30)
massa = Entry()
massa.place(x=10, y=90)
Label(root, text="Entre com o calor especifico da Agua: ", font="Arial 10", bg='white').place(x=5, y=130)
calor_especifico = Entry()
calor_especifico.place(x=10, y=170)
Label(root, text="Variacao da Temperatura da Agua: ", font="Arial 10", bg='white').place(x=5, y=210)
temp_agua = Entry()
temp_agua.place(x=10, y=250)
def show_result():
result = int(massa.get())*int(calor_especifico.get())-int(temp_agua.get())
tkinter.messagebox.showinfo('Information', "Este alimentos possui: %s (kcal)"%float(result))
Button(root, text="Calcular (kcal)", command=show_result).place(x=10, y=350)
Frame(root, height=3, width=250, bd=1, relief=SUNKEN).place(x=15,y=300)
def add_alimentos():
add = Tk()
add['bg'] = 'white'
add.title("Adicionar Alimentos")
Label(add, text="Alimento", bg='white').place(x=10, y=20)
alimento = Entry(add)
alimento.place(x=100, y=20)
Label(add, text="Gramas", bg='white').place(x=10, y=60)
gramas = Entry(add)
gramas.place(x=100, y=60)
Label(add, text="Calorias", bg='white').place(x=10, y=100)
calorias = Entry(add)
calorias.place(x=100, y=100)
def right():
data.append((str(alimento.get()), int(gramas.get()), float(calorias.get())))
tkinter.messagebox.showinfo('Information', "Adicionado com Sucesso!")
Button(add, text="Adicionar", command=right).place(x=10, y=160)
add.geometry("300x200")
add.mainloop()
def somar_calorias():
#root.destroy()
somador = Tk()
somador['bg'] = 'white'
somador.title('Somar Calorias')
menubar = Menu(somador)
somador.config(menu=menubar)
filemenu = Menu(menubar)
menubar.add_cascade(label='Menu', menu=filemenu)
filemenu.add_command(label='Alimentos', command=app_alimentos)
filemenu.add_command(label='Somar Calorias', command=somar_calorias)
filemenu.add_command(label='Adicionar Alimentos', command=add_alimentos)
filemenu.add_command(label='Configurar Arduino', command=Arduino)
filemenu.add_command(label='Grafico', command=grafico)
filemenu.add_command(label='Creditos', command=Creditos)
filemenu.add_command(label='Exit', command=Exit)
Label(somador, text="Entre com o Nome do Alimento:", font="Arial 10", bg='white').place(x=5, y=50)
nome_alimento = Entry()
nome_alimento.place(x=10, y=90)
Label(somador, text="Quantidade: ", font="Arial 10", bg='white').place(x=5, y=130)
quantidade = Entry()
quantidade.place(x=10, y=170)
def total_calorias():
global nome_calorias, calorias
for alimentos in data:
if alimentos[0].lower() == nome_alimento.get().lower():
nome_calorias += "%s: %s(kcal)\n"%(nome_alimento.get().lower(), float(alimentos[2])*float(quantidade.get()))
calorias += float(alimentos[2])*float(quantidade.get())
Label(somador, text="Calorias Ingeridas: %s (kcal)"%calorias, font="Arial 14", bg='white').place(x=10, y=230)
tkinter.messagebox.showinfo('Information', "%s\nVoce ingeriu: %s (kcal)\n\n"%(nome_calorias, calorias))
Button(somador, text="Somar", command=total_calorias).place(x=10, y=290)
somador.geometry("300x350")
somador.mainloop()
def grafico():
x = []
y = []
for i in data:
y.append(i[0])
x.append(i[2])
plt.title("Calorimetria")
plt.xlabel("(kcal)")
plt.ylabel("Alimentos")
plt.barh(y, x, label="Grupo Massas")
plt.legend()
plt.show()
def main():
root.title("Calorias - 2B")
root['bg'] = 'white'
menubar = Menu(root)
root.config(menu=menubar)
filemenu = Menu(menubar)
menubar.add_cascade(label='Menu', menu=filemenu)
filemenu.add_command(label='Alimentos', command=app_alimentos)
filemenu.add_command(label='Somar Calorias', command=somar_calorias)
filemenu.add_command(label='Adicionar Alimentos', command=add_alimentos)
filemenu.add_command(label='Configurar Arduino', command=Arduino)
filemenu.add_command(label='Grafico', command=grafico)
filemenu.add_command(label='Creditos', command=Creditos)
filemenu.add_command(label='Exit', command=Exit)
calculate_kcal()
root.geometry("300x400")
root.mainloop()
main()
#Arduino()