-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr_feria.py
More file actions
294 lines (241 loc) · 11.1 KB
/
pr_feria.py
File metadata and controls
294 lines (241 loc) · 11.1 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
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
290
291
292
293
294
#v00: 17/11/25
#-------------------------------
import tkinter as tk
from tkinter import Toplevel
from tkinter import *
import datetime
import importlib
import pr_feria_custom
ahora = str(datetime.datetime.now())
def reload_data():
importlib.reload(pr_feria_custom)
return pr_feria_custom.lis_custom
def win00(): #L_verds, L_fruts, L_ot_comer, L_ot_cosas):
def guardar_listacustom():
global lis_select2
lis_select2 = []
for m, lis in enumerate(lis_select):
for n, elm in enumerate(lis):
if elm.get():
lis_select2.append(Alldata[m][n])
## print(f"lis_select2: {lis_select2}") #debug
lis_custom = []
check2 = True
try:
lis_custom = lis_select2 + data_pers2
check2 = False
except:
print('data_pers2: no data')
if check2:
lis_custom = lis_select2
if len(lis_custom)>0:
with open("pr_feria_custom.py", "w") as f:
f.write(f"lis_custom = {lis_custom}")
reload_data()
vent_lg.destroy()
def elementos_NE():
def guardar_elementos_NE():
global data_pers2
temp000 = ent_agre.get()
if (temp000.lstrip()).rstrip() == '' or temp000 is None:
data_pers2 = []
else:
temp001 = temp000.split(',')
data_pers2 = [(elm.lstrip()).rstrip() for elm in temp001]
## print(f"data_pers2: {data_pers2}") #debug
vent_agre.destroy()
vent_agre = tk.Toplevel()
vent_agre.geometry('300x100')
vent_agre.title("Agregar elementos")
lab_agre = tk.Label(vent_agre, text="Ingresar frutas/verduras/otros (separar con ,)")
ent_agre = tk.Entry(vent_agre, width=40)
but_agre = tk.Button(vent_agre, text="Aceptar y Cerrar", command=guardar_elementos_NE)
lab_agre.place(x=10, y=10)
ent_agre.place(x=10, y=35)
but_agre.place(x=10, y=60)
vent_agre.mainloop()
vent_lg = tk.Toplevel()
vent_lg.geometry('650x500')
vent_lg.title("Lista general")
container = tk.Frame(vent_lg)
container.pack(fill="both", expand=True)
canvas = tk.Canvas(container)#, height=100) # visible height
canvas.pack(side="left", fill="both", expand=True)
scrollbar = tk.Scrollbar(container, orient="vertical", command=canvas.yview)
scrollbar.pack(side="right", fill="y")
canvas.configure(yscrollcommand=scrollbar.set)
# Inner frame inside the canvas
table_frame = tk.Frame(canvas)
canvas.create_window((0, 0), window=table_frame, anchor="nw")
global lis_select
lis_select = []
ies = []
# Build table
for j, data in enumerate(Alldata):
listemp = []
for i, item in enumerate(data, start=2):
if i==2:
tk.Label(table_frame, text=titulos[j], font=("Arial",9,"bold"), anchor="w").grid(row=i-1, column=j*2, sticky="w", padx=10, pady=0)
tk.Label(table_frame, text=item, anchor="w").grid(row=i, column=j*2, sticky="w", padx=10, pady=0)
var_sel = tk.BooleanVar(value=False) # starts unchecked
chkbt = tk.Checkbutton(table_frame, variable=var_sel, anchor="w")
chkbt.grid(row=i, column=j*2+1, padx=10, pady=0)
listemp.append(var_sel)
lis_select.append(listemp)
ies.append(i)
but000 = tk.Button(table_frame, text="Ingresar elementos no especificados", command=elementos_NE).grid(row=ies[2]+2, column=4, columnspan=4,sticky="w", padx=10)
but001 = tk.Button(table_frame, text="Aceptar y Guardar", command=guardar_listacustom).grid(row=ies[2]+5, column=4, sticky="w", padx=10)
# Update scrollregion whenever table_frame resizes
def on_frame_configure(event):
canvas.configure(scrollregion=canvas.bbox("all"))
table_frame.bind("<Configure>", on_frame_configure)
vent_lg.mainloop()
def f_lisgral(event):
win00()
def f_liscustom(event):
def imprimir_lc():
l_print = []
for k, elm in enumerate(lis_print):
if elm.get():
l_print.append(pr_feria_custom.lis_custom[k])
global Allpers_imp
Allpers_imp = [[]for i in range(len(Alldata))]
for j in range(len(Alldata)):
Allpers_imp[j] = [x for x in l_print if x in Alldata[j]]
if len(Allpers_imp[j])>0:
Allpers_imp[j].insert(0, titulos[j])
Allpers_imp[j].append('')
Allpers_adicionales = [] #idem data_pers2
for elm in l_print:
c = 0
for lis in Alldata:
if elm in lis:
c += 1
if c == 0:
Allpers_adicionales.append(elm)
if len(Allpers_adicionales)>0:
Allpers_adicionales.insert(0, 'Adicionales')
Allpers_imp.append(Allpers_adicionales)
for lx in Allpers_imp:
print(*lx, sep='\n')
vent_lc.destroy()
root.destroy()
vent_lc = tk.Toplevel()
data_custom = pr_feria_custom.lis_custom
dims = '700x200' #+ str(len(data_custom)*25+100)
vent_lc.geometry(dims)
## vent_lc.configure(bg='light yellow')
vent_lc.title("Lista personal")
container = tk.Frame(vent_lc)
container.pack(fill="both", expand=True)
container.configure(bg='light yellow')
canvas = tk.Canvas(container, height=100) # visible height
canvas.pack(side="left", fill="both", expand=True)
scrollbar = tk.Scrollbar(container, orient="vertical", command=canvas.yview)
scrollbar.pack(side="right", fill="y")
canvas.configure(yscrollcommand=scrollbar.set, bg='light yellow')
# Inner frame inside the canvas
table_frame = tk.Frame(canvas)
canvas.create_window((0, 0), window=table_frame, anchor="nw")
table_frame.configure(bg='light yellow')
global lis_print
lis_print = []
# Build table
if len(data_custom)>0:
Allpers_prev = [[]for i in range(len(Alldata))]
for j in range(len(Alldata)):
Allpers_prev[j] = [x for x in data_custom if x in Alldata[j]]
if len(Allpers_prev[j])>0:
Allpers_prev[j].insert(0, titulos[j])
Allpers_adicionales = [] #idem data_pers2
for x in data_custom:
c = 0
for lis in Alldata:
if x in lis:
c += 1
if c == 0:
Allpers_adicionales.append(x)
if len(Allpers_adicionales)>0:
Allpers_adicionales.insert(0, 'Adicionales')
Allpers_prev.append(Allpers_adicionales)
for k, lis in enumerate(Allpers_prev):
for i, item in enumerate(lis, start=2):
if i==2:
tk.Label(table_frame, text= lis[i-2], font=("Arial",9,"bold"), anchor="w", bg='light yellow').grid(row=i-1, column=k*2, sticky="w", padx=10, pady=0)
continue
tk.Label(table_frame, text= item, anchor="w", bg='light yellow').grid(row=i, column=k*2, sticky="w", padx=10, pady=0)
var_cri = tk.BooleanVar(value=False) # starts unchecked
chkbt = tk.Checkbutton(table_frame, variable=var_cri, bg='light yellow')
chkbt.grid(row=i, column=k*2+1, padx=10, pady=0)
lis_print.append(var_cri)
but_lc00 = tk.Button(table_frame, text="Imprimir selección", command=imprimir_lc).grid(row=i+2, column=0, columnspan=2,sticky="w", padx=10)
vent_lc.mainloop()
#start--------------------------------------------------------
print(ahora[:19])
root = tk.Tk()
root.geometry("200x160+40+40")
root.title("Feria")
global Lista_verduras, Lista_frutas, Lista_otros_comer, Lista_otros_cosas, Alldata, titulos
Lista_verduras = ['palta','papa','zanahoria','zapallo camote','limon','tomate','lechuga','ajo','cebolla','cebolla morada',
'pimenton','pepino','espinaca','zapallo italiano','choclo','rabano','betarraga',
'cilantro','perejil','brocoli','apio','hongos','rucula','aceituna',
'aceituna morada','tomate cherry','lentejas','porotos','garbanzos',
'maiz curagua','berenjena','esparrago','alcachofa','porotos granados','choclo porotos','albahaca']
Lista_frutas = ['platano','naranja','manzana','frutilla','pera',
'nueces','almendra','durazno','kiwi','cereza','uva',
'sandia','melon','pepino (fruta)','mango','chirimoya','frambuesa','arandano',
'mora']
Lista_otros_comer = ['aji panka','humitas','huevos','pescado']
Lista_otros_cosas = ['colets','pastillas cloro','tierra de hoja']
Alldata = [Lista_verduras, Lista_frutas, Lista_otros_comer, Lista_otros_cosas]
titulos = ['Verduras','Frutas','Otros (comer)','Otros (cosas)']
lab00 = tk.Label(root, text="Frutas, verduras y otros", font=("Arial",9,"bold"), anchor="w")
but01 = tk.Button(root, text="Crear Lista (todos los items)")
but04 = tk.Button(root, text="Lista personal")
#-------
i_frus = tk.PhotoImage(file="group-of-fruits-48.png")
frus = tk.Label(root, image=i_frus, compound="left")
i_vegs = tk.PhotoImage(file="group-of-vegetables-48.png")
vegs = tk.Label(root, image=i_vegs, compound="left")
#-------
lab00.place(x=10, y=10)
but01.place(x=10, y=35)
but04.place(x=10, y=60)
frus.place(x=10, y=100)
vegs.place(x=55, y=100)
but01.bind('<Button-1>', f_lisgral)
but04.bind('<Button-1>', f_liscustom)
root.mainloop()
#---------------
try:
vent_pr = tk.Tk()
Allpers_imp2 = []
for lx in Allpers_imp:
for x in lx:
Allpers_imp2.append(x)
dims = '200x' + str(len(Allpers_imp2)*25+100)
vent_pr.geometry(dims)
vent_pr.title('Mi lista')
for n, item in enumerate(Allpers_imp2, start=1):
if item in titulos or item == 'Adicionales':
tk.Label(vent_pr, text=item, font=("Arial",9,"bold"), anchor="w").grid(row=n, column=0, columnspan=4, sticky="w", padx=10, pady=0)
else:
tk.Label(vent_pr, text=item, anchor="w").grid(row=n, column=0, columnspan=4, sticky="w", padx=10, pady=0)
#-------
i_fru0 = tk.PhotoImage(file="banana-32.png")
fru0 = tk.Label(vent_pr, image=i_fru0, compound="left")
i_fru1 = tk.PhotoImage(file="orange-32.png")
fru1 = tk.Label(vent_pr, image=i_fru1, compound="left")
i_veg0 = tk.PhotoImage(file="eggplant-32.png")
veg0 = tk.Label(vent_pr, image=i_veg0, compound="left")
i_veg1 = tk.PhotoImage(file="potato-32.png")
veg1 = tk.Label(vent_pr, image=i_veg1, compound="left")
fru0.grid(row=0, column=0, sticky="w")
fru1.grid(row=0, column=1, sticky="w")
veg0.grid(row=0, column=2, sticky="w")
veg1.grid(row=0, column=3, sticky="w")
#-------
vent_pr.mainloop()
except:
vent_pr.destroy()
print('---')