-
Notifications
You must be signed in to change notification settings - Fork 2
/
horario.py
290 lines (217 loc) · 10.4 KB
/
horario.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
290
import tkinter as tk
from tkinter import messagebox
from des import *
from variables import *
ICON = "assets/favicon.ico"
from conex_bd import RunQuery
# Modulos de interfaz grafica para la seccion Horario #
def MostrarHorario(app, contenido):
EliminarBotones(buttons)
EliminarVentanas(ventanas)
container = tk.Frame(contenido)
canvas = tk.Canvas(container, width=545, height=450)
scrollbar = tk.Scrollbar(container, orient="vertical", command=canvas.yview)
scrollable_frame = tk.Frame(canvas, bg='#E4F2F9')
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(
scrollregion=canvas.bbox("all")
)
)
tipo_bloque, bloques, asig_list = EmitirPlanificacion('horario')
canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)
b = tk.Button(scrollable_frame, text="Hrs", font=("", 8), wraplength=80, width=7, height=1, relief = tk.GROOVE, bg = '#CEE9F7')
b.grid(row=1,column=0)
for i in range(0,9):
text = tipo_bloque[i][0] + "\n-\n" + tipo_bloque[i][1]
a = tk.Button(scrollable_frame, text=text, font=("", 8), wraplength=80, width=7, height=3, relief = tk.GROOVE, bg='#CEE9F7')
a.grid(row=i+2,column=0)
buttons.append(a)
for i in range(1,7):
bl_dia = []
for bloque in bloques: #filtra todos los bloques que corresponden al dia i
if(bloque[2] == DiaSemana(i)):
bl_dia.append(bloque)
bloques = [b for b in bloques if b not in bl_dia] #se borran los bloques que ya se guardaron en bl_dia
for j in range (1,11):
t = ""
w = 12
h = 3
color = '#E4F2F9'
if j == 1:
t = DiaSemana(i)
h = 1
color = '#CEE9F7'
elif bl_dia != []:
for bloque in bl_dia:
if(bloque[0]+1 == j):
for asig in asig_list:
if(bloque[1] == asig[0]):
color = '#fbf8be'
t = asig[1]
b = tk.Button(scrollable_frame, text=t, font=("", 8), wraplength=80, width=w, height=h, relief = tk.GROOVE, bg=color)
b.grid(row=j,column=i)
#a = tk.Button(scrollable_frame, text=bloques[j][1], font=("", 8), wraplength=80, width=7, height=3, relief = tk.GROOVE)
#a.grid(row=5,column=0)
buttons.append(b)
#buttons.append(a)
container.place(x=10,y=30)
canvas.pack(side="left", fill="both")
scrollbar.pack(side="right", fill="y")
b = tk.Button(contenido, text="Agregar Bloque", command = lambda: IngresarBloque(app, contenido), relief = tk.SOLID, font=("", 13, 'bold'), bd=1, padx=0)
b.place(x=80,y=510)
b["bg"] = "#fbf8be"
b["activebackground"] = "#e3e0ac"
buttons.append(b)
b = tk.Button(contenido, text="Eliminar Bloque", command = lambda: MostrarEliminarBloque(app, contenido), relief = tk.SOLID, font=("", 13, 'bold'), bd=1, padx=0)
b.place(x=350,y=510)
b["bg"] = "#fbf8be"
b["activebackground"] = "#e3e0ac"
buttons.append(b)
buttons.append(container)
buttons.append(canvas)
buttons.append(scrollbar)
buttons.append(scrollable_frame)
# Ingresar Horario
def IngresarBloque(app, contenido):
asignaturas = list(RunQuery("SELECT ASI_ID, ASI_NOM FROM ASIGNATURA WHERE ASI_EST ='1'"))
if asignaturas != []:
EliminarVentanas(ventanas)
EliminarBotones(buttons_ventana)
ventana = tk.Toplevel(app, bg="#D4E6F1")
ventana.title("Crear Bloque")
ventana.geometry("800x500")
ventana.resizable(False, False)
ventana.iconbitmap(ICON)
ventana.focus()
# Lista Asignaturas
b = tk.Label(ventana, text = ' Selecciona la asignatura del bloque a crear:', font=("", 15, 'bold'),justify="left")
b.place(x=30,y=30)
lista = tk.Listbox(ventana, height=11, width=81,font=("", 12, ""), bg = 'SystemButtonFace')
lista.place(x=30, y=85)
for k in range(len(asignaturas)-1,-1,-1):
i = asignaturas[k]
lista.insert(0,' '+ i[1])
# Lista Dia Semana
b = tk.Label(ventana, text = 'Dia de la semana: ', font=("", 13, 'bold'),justify="left")
b.place(x=30,y=320)
dia_list = list(RunQuery("SELECT DIA_NOMBRE FROM DIA WHERE DIA_ID >'0'"))
dia = ['{}'.format(*opcion) for opcion in dia_list]
opcion_dia = tk.StringVar(ventana, value = '')
nuevo_dia = tk.OptionMenu(ventana, opcion_dia, *dia)
nuevo_dia.place(x=185,y=318)
# Lista hora
b = tk.Label(ventana, text = 'Hora: ', font=("", 13, 'bold'),justify="left")
b.place(x=30, y=370)
hora = list(RunQuery("SELECT BL_ID, BL_INI, BL_FIN FROM TIPO_BLOQUE"))
hora_list = []
for k in hora:
hora_list.append([k[1], k[2]])
opcion_hora = tk.StringVar(ventana, value = '')
nuevo_hora = tk.OptionMenu(ventana, opcion_hora, *hora_list)
nuevo_hora.place(x=90, y=368)
a = tk.Button(ventana, text="Crear Bloque", command = lambda: Crearbloque(app,contenido,ventana, (lista.curselection(), opcion_dia.get(), opcion_hora.get()), asignaturas, hora), relief = tk.SOLID, font=("", 17, 'bold'), bd=1, padx=0)
a.place(x=30, y=422)
buttons_ventana.append(a)
a = tk.Button(ventana, text="Cancelar", command = ventana.destroy, relief = tk.SOLID, font=("", 17, 'bold'), bd=1, padx=10)
a.place(x=200,y=422)
ventanas.append(ventana)
ventana.mainloop()
else:
messagebox.showinfo(message="No existen asignaturas activas / creadas.", title="Mind your Study", parent=app)
return
def Crearbloque(app, contenido, ventana, parameters, asignaturas, horas):
# Validacion de asignatura
try:
asignaturas[parameters[0][0]]
except IndexError:
messagebox.showinfo(message="Debes seleccionar una asignatura.", title="Mind your Study", parent=ventana)
return
asignatura_id = asignaturas[parameters[0][0]][0]
# Validacion de dia semana
if parameters[1] != '':
dia_sem = parameters[1].translate({ord(i):None for i in "()',"})
else:
messagebox.showinfo(message="Debes ingresar un dia de semana.", title="Mind your Study", parent=ventana)
return
# Validacion de hora
if parameters[2] != '':
hora_str = parameters[2].translate({ord(i):None for i in "()',"})
else:
messagebox.showinfo(message="Debes ingresar una hora.", title="Mind your Study", parent=ventana)
return
for k in horas:
if k[1] == hora_str[0:5] and k[2] == hora_str[6:11]:
bl_id = k[0]
crear_bool = GestionAsignatura('C', (bl_id, asignatura_id, dia_sem), None, None)
if( crear_bool == -1):
m = "Ya existe un bloque en esa posicion."
messagebox.showinfo(message= m, title="Mind your Study", parent=ventana)
return
MostrarHorario(app, contenido)
m = "Se ha creado el bloque correctamente."
messagebox.showinfo(message= m, title="Mind your Study", parent=app)
# Eliminar bloque
def MostrarEliminarBloque(app, contenido):
rows = list(RunQuery("SELECT * FROM BLOQUE ORDER BY BL_DIA_SEM"))
if rows != []:
asig_list = list(RunQuery("SELECT ASI_ID, ASI_NOM FROM ASIGNATURA WHERE ASI_EST = '1'"))
bl_list = list(RunQuery("SELECT BL_ID, BL_INI FROM TIPO_BLOQUE ORDER BY BL_INI"))
EliminarBotones(buttons_ventana)
EliminarVentanas(ventanas)
ventana = tk.Toplevel(app, bg="#D4E6F1")
ventana.title("Eliminar Bloque")
ventana.geometry("800x580")
ventana.resizable(False, False)
ventana.iconbitmap(ICON)
ventana.focus()
b = tk.Label(ventana, text="Selecciona el bloque a eliminar:",font=("", 20, 'bold'),justify="left")
b.place(x=30,y=30)
lista = tk.Listbox(ventana, height=20, width=81,font=("", 13, ""), bg = 'SystemButtonFace')
lista.place(x=30, y=85)
for k in range(len(rows)-1,-1,-1):
i = rows[k]
for asig in asig_list:
if i[1] == asig[0]:
asignatura = asig[1]
for bl in bl_list:
if i[0] == bl[0]:
hora = bl[1]
lista.insert(0, i[2] + ' a las ' + hora + ': ' + asignatura)
a = tk.Button(ventana, text="Seleccionar", command= lambda: EliminarBloque(app,contenido,ventana, rows, lista.curselection()), relief = tk.SOLID, font=("", 17, 'bold'), bd=1, padx=0)
a.place(x=30,y=500)
a = tk.Button(ventana, text="Borrar todo", command= lambda: EliminarTodoBloques(app,contenido,ventana, rows), relief = tk.SOLID, font=("", 17, 'bold'), bd=1, padx=0)
a.place(x=195,y=500)
a = tk.Button(ventana, text="Cancelar", command = ventana.destroy, relief = tk.SOLID, font=("", 17, 'bold'), bd=1, padx=10)
a.place(x=355,y=500)
buttons_ventana.append(b)
buttons_ventana.append(lista)
buttons_ventana.append(a)
ventanas.append(ventana)
ventana.mainloop()
else:
messagebox.showinfo(message="No existen bloques actualmente.", title="Mind your Study", parent=app)
return
def EliminarBloque(app, contenido, ventana, rows, seleccion):
try:
rows[seleccion[0]]
except IndexError:
messagebox.showinfo(message="Debes seleccionar un bloque.", title="Mind your Study", parent=ventana)
return
respuesta = messagebox.askyesno(message="¿Desea eliminar el bloque?", title="Eliminar Bloque", parent = ventana)
if not respuesta:
return
k = rows[seleccion[0]]
GestionAsignatura('E', (k[0], k[2]), None, None)
MostrarHorario(app, contenido)
messagebox.showinfo(message="Se ha eliminado el bloque correctamente.", title="Mind your Study", parent=app)
def EliminarTodoBloques(app, contenido, ventana, rows):
respuesta = messagebox.askyesno(message="¿Deseas eliminar todos los bloques?", title="Eliminar Bloque", parent = ventana)
if not respuesta:
return
for k in rows:
GestionAsignatura('E', (k[0], k[2]), None, None)
MostrarHorario(app, contenido)
messagebox.showinfo(message="Se han eliminado todos los bloques.", title="Mind your Study", parent=app)
# Fin modulos de interfaz grafica para la seccion Horario #