My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Thu Aug 20 01:03:28 2009

import wx
import wx.grid
import basededatos


# begin wxGlade: extracode
# end wxGlade



class IngresoDatos(wx.Frame):
def __init__(self, *args, **kwds):
self.rows = 0
self.fila = 0
#Trabaja con el checkbox
self.responsable = 0
self.parientes = 0
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.rows = 0
self.panel = wx.Panel(self, -1)
self.stTitulo = wx.StaticText(self.panel, -1, u'Alta de alumnos')
self.st_apellido = wx.StaticText(self.panel, -1, u"Apellido:")
self.txt_apellido = wx.TextCtrl(self.panel, -1, u"")
self.txt_apellido.SetFocus()
self.st_nombre = wx.StaticText(self.panel, -1, u"Nombre:")
self.txt_nombre = wx.TextCtrl(self.panel, -1, u"")
self.st_dni = wx.StaticText(self.panel, -1, u"DNI:")
self.txt_dni = wx.TextCtrl(self.panel, -1, u"")
self.st_responsable_1 = wx.StaticText(self.panel, -1, u"Responsable:")
self.txt_respnsable_1 = wx.TextCtrl(self.panel, -1, u"")
self.st_telefono = wx.StaticText(self.panel, -1, u"Teléfono:")
self.txt_telefono = wx.TextCtrl(self.panel, -1, u"")
self.st_celular = wx.StaticText(self.panel, -1, u"Celular:")
self.txt_celular = wx.TextCtrl(self.panel, -1, u"")
self.checkbox_responsable = wx.CheckBox(self.panel, -1, u"Responsable 2:")
self.txt_responsable_2 = wx.TextCtrl(self.panel, -1, u"")
self.txt_responsable_2.Enable(False)
self.st_telefono_2 = wx.StaticText(self.panel, -1, u"Teléfono:")
self.st_telefono_2.Enable(False)
self.txt_telefono_2 = wx.TextCtrl(self.panel, -1, u"")
self.txt_telefono_2.Enable(False)
self.st_celular_2 = wx.StaticText(self.panel, -1, u"Celular:")
self.st_celular_2.Enable(False)
self.txt_celular_2 = wx.TextCtrl(self.panel, -1, u"")
self.txt_celular_2.Enable(False)
self.checkbox_parientes = wx.CheckBox(self.panel, -1, u"Parientes")
self.st_rell = wx.StaticText(self.panel, -1, u"")
self.btn_agregar = wx.Button(self.panel, -1, u"Agregar", style=wx.BU_EXACTFIT)
self.btn_agregar.Enable(False)
self.btn_quitar = wx.Button(self.panel, -1, u"Quitar", style=wx.BU_EXACTFIT)
self.btn_quitar.Enable(False)
self.grid_parientes = wx.grid.Grid(self.panel, -1, size=(1, 1))
self.grid_parientes.Enable(False)
self.st_rell_2 = wx.StaticText(self.panel, -1, u"")
self.btn_cancelar = wx.Button(self.panel, wx.ID_CANCEL, u"")
self.btn_aceptar = wx.Button(self.panel,wx.ID_OK, u"")

self.__set_properties()
self.__do_layout()

self.Bind(wx.EVT_CHECKBOX, self.OnResponsables, self.checkbox_responsable)
self.Bind(wx.EVT_CHECKBOX, self.OnParientes, self.checkbox_parientes)
self.Bind(wx.EVT_BUTTON, self.OnAgregar, self.btn_agregar)
self.Bind(wx.EVT_BUTTON, self.Onquitar, self.btn_quitar)
self.Bind(wx.EVT_BUTTON, self.OnCancelar, self.btn_cancelar)
self.Bind(wx.EVT_BUTTON, self.OnAceptar, self.btn_aceptar)
# end wxGlade

def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle(u"Relaxtives - Alta de alumnos")
self.CenterOnScreen()
#Propiedad de los botones
self.btn_cancelar.SetDefault()
self.btn_aceptar.SetDefault()
self.stTitulo.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD, 0, ""))
self.SetSize((680, 480))
self.grid_parientes.CreateGrid(1, 2)
self.grid_parientes.SetRowLabelSize(0)
self.grid_parientes.SetColLabelSize(30)
self.grid_parientes.SetColLabelValue(0, u"Nombre")
self.grid_parientes.SetColLabelValue(1, u"Pariente")
self.grid_parientes.SetColSize(0,200)
self.grid_parientes.SetColSize(1,80)

#----------------------------------------------------------------------------------------
#Conectar a la base de datos
base = basededatos.conectando('relaxtives','relaxtives')
c = base.cursor()
#----------------------------------------------------------------------------------------
# Crear la GridCellChoiceEditor con una lista en blanco. Los artículos serán
# agregados más tarde, en tiempo de ejecución. "allowOthers" permite al usuario
# crear nuevos elementos de selección sobre la marcha.
tChoiceEditor = wx.grid.GridCellChoiceEditor([u"Conviviente",u"Hermano/a",u"Sobrino/a",u"Tío/a",u'Primo/a'] , allowOthers=True)
#Pedir nombres ordenados alfabeticamente
c.execute('''select id_alumno, apellidos, nombres, documento from alumnos order by apellidos''')
self.q = c.fetchall()
c.close()
#lista = []
StrAlum = [("%d %s %s %s" % tuple(a)) for a in self.q]
#tChoiceEditor2(self, u'Estudiantes que cumplen el criterio de búsqueda:', u'Modificación de estudiantes', StrAlum)

tChoiceEditor2 = wx.grid.GridCellChoiceEditor(StrAlum, allowOthers=True)
#Asignar a los editores de la célula de la primera fila y segunda columna(fila 0).
self.grid_parientes.SetCellEditor(0, 1, tChoiceEditor)
self.grid_parientes.SetCellEditor(0, 0, tChoiceEditor2)
#lista
self.grid_parientes.list = [u"Conviviente ",u"Hermano/a ",u"Sobrino/a",u"Tío/a",u'Primo/a']
# Mostrar el tercer elemento de la lista en la celda ChoiceEditor
#en este caso esta vacia, asi que no aparecera nada
self.grid_parientes.SetCellValue(0, 1, self.grid_parientes.list[0][11])
# end wxGlade

def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_2 = wx.BoxSizer(wx.VERTICAL)
sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
sizer_5 = wx.BoxSizer(wx.VERTICAL)
sizer_7 = wx.BoxSizer(wx.HORIZONTAL)
sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
sizer_2.Add(sizer_8, 0 ,wx.ALIGN_CENTER_HORIZONTAL, 0)
grid_sizer_1 = wx.FlexGridSizer(10, 2, 5, 5)
grid_sizer_1.Add(self.st_apellido, 0, 0, 0)
grid_sizer_1.Add(self.txt_apellido, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.st_nombre, 0, 0, 0)
grid_sizer_1.Add(self.txt_nombre, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.st_dni, 0, 0, 0)
grid_sizer_1.Add(self.txt_dni, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.st_responsable_1, 0, 0, 0)
grid_sizer_1.Add(self.txt_respnsable_1, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.st_telefono, 0, 0, 0)
grid_sizer_1.Add(self.txt_telefono, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.st_celular, 0, 0, 0)
grid_sizer_1.Add(self.txt_celular, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.checkbox_responsable, 0, 0, 0)
grid_sizer_1.Add(self.txt_responsable_2, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.st_telefono_2, 0, 0, 0)
grid_sizer_1.Add(self.txt_telefono_2, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.st_celular_2, 0, 0, 0)
grid_sizer_1.Add(self.txt_celular_2, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.checkbox_parientes, 0, 0, 0)
grid_sizer_1.Add(self.st_rell, 0, 0, 0)
grid_sizer_1.AddGrowableCol(1)
#Agegado de titulo
#sizer_8.Add(self.stTitulo, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 10)
sizer_8.Add(self.stTitulo, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
#----------------------
sizer_3.Add(grid_sizer_1, 1, wx.LEFT|wx.TOP|wx.EXPAND, 30)
sizer_6.Add(self.btn_agregar, 0, wx.ALIGN_BOTTOM, 0)
sizer_6.Add(self.btn_quitar, 0, wx.ALIGN_BOTTOM, 0)
sizer_5.Add(sizer_6, 0, wx.LEFT|wx.TOP|wx.EXPAND, 30)
sizer_7.Add(self.grid_parientes, 1, wx.EXPAND, 0)
sizer_7.Add(self.st_rell_2, 0, wx.LEFT, 30)
sizer_5.Add(sizer_7, 1, wx.LEFT|wx.EXPAND, 25)
sizer_3.Add(sizer_5, 1, wx.EXPAND, 0)
sizer_2.Add(sizer_3, 1, wx.EXPAND, 0)
sizer_4.Add(self.btn_cancelar, 0, wx.TOP|wx.BOTTOM, 30)
sizer_4.Add(self.btn_aceptar, 0, wx.ALL, 30)
sizer_2.Add(sizer_4, 0, wx.ALIGN_RIGHT, 0)
self.panel.SetSizer(sizer_2)
sizer_1.Add(self.panel, 1, wx.EXPAND, 0)
self.SetSizer(sizer_1)
self.Layout()
self.Center()
# end wxGlade

def OnResponsables(self, event): # wxGlade: MyFrame.<event_handler>
self.responsable += 1
#Si el numero es impar
if self.responsable %2 != 0:
#Habilitar
self.txt_responsable_2.Enable(True)
self.st_telefono_2.Enable(True)
self.txt_telefono_2.Enable(True)
self.st_celular_2.Enable(True)
self.txt_celular_2.Enable(True)
else:
#si el numero es par desabilitar
self.txt_responsable_2.Enable(False)
self.st_telefono_2.Enable(False)
self.txt_telefono_2.Enable(False)
self.st_celular_2.Enable(False)
self.txt_celular_2.Enable(False)
event.Skip()



def OnParientes(self, event): # wxGlade: MyFrame.<event_handler>
self.parientes += 1
#Si el numero es impar
if self.parientes %2 != 0:
#Habilitar
self.btn_agregar.Enable(True)
self.btn_quitar.Enable(True)
self.grid_parientes.Enable(True)

else:
#desactivar
self.btn_agregar.Enable(False)
self.btn_quitar.Enable(False)
self.grid_parientes.Enable(False)

event.Skip()
def OnAgregar(self, event): # wxGlade: MyFrame.<event_handler>
self.fila += 1
self.grid_parientes.AppendRows()
self.grid_parientes.MakeCellVisible(self.rows, 0)
self.grid_parientes.ForceRefresh()
#----------------------------------------------------------------------------------------
#Conectar a la base de datos
base = basededatos.conectando('relaxtives','relaxtives')
c = base.cursor()
#----------------------------------------------------------------------------------------
tChoiceEditor = wx.grid.GridCellChoiceEditor([u"Conviviente ",u"Hermano/a",u"Sobrino/a",u"Tío/a",u'Primo/a'] , allowOthers=True)
#Pedir nombres ordenados alfabeticamente
c.execute('''select id_alumno, apellidos, nombres, documento from alumnos order by apellidos''')
self.q = c.fetchall()
c.close()
#lista = []

StrAlum = [("%d %s %s %s" % tuple(a)) for a in self.q]

tChoiceEditor2 = wx.grid.GridCellChoiceEditor(StrAlum, allowOthers=True)
#Asignar a los editores de la célula de la primera fila y segunda columna(fila 0).
self.grid_parientes.SetCellEditor(self.fila, 1, tChoiceEditor)
# Mostrar el quinto espacio de la primera celda del ChoiceEditor
#en este caso esta vacio, asi que no aparecera nada
self.grid_parientes.SetCellEditor(self.fila, 0, tChoiceEditor2)
self.grid_parientes.SetCellValue(self.fila, 1, self.grid_parientes.list[0][11])
self.grid_parientes.SetCellValue(self.fila, 0, self.grid_parientes.list[0][11])
self.rows += 1
event.Skip()

def Onquitar(self, event): # wxGlade: MyFrame.<event_handler>
if self.rows > 0: #1:
self.grid_parientes.DeleteRows(self.rows)
self.grid_parientes.ForceRefresh()
self.rows -= 1
#Cuando quito una fila tambien debe quitar self.fila
self.fila -= 1
event.Skip()

def OnCancelar(self, event): # wxGlade: MyFrame.<event_handler>
self.Close()
event.Skip()

def OnAceptar(self, event): # wxGlade: MyFrame.<event_handler>
#Se toma los valores
ingr_apellido = self.txt_apellido.GetValue().upper()
ingr_nombre = self.txt_nombre.GetValue().title()
ingr_dni = self.txt_dni.GetValue()
ingr_responsable_1 = self.txt_respnsable_1.GetValue().title()
ingr_tel = self.txt_telefono.GetValue()
ingr_cel = self.txt_celular.GetValue()
ingr_responsable_2 = self.txt_responsable_2.GetValue().title()
ingr_tel_2 = self.txt_telefono_2.GetValue()
ingr_cel_2 = self.txt_celular_2.GetValue()
#Conectar a la base de datos
base = basededatos.conectando('relaxtives','relaxtives')
c = base.cursor()
c.execute(''' insert into alumnos(apellidos, nombres, documento, responsable_1, te_resp_1, celu_resp_1, responsable_2, te_resp_2, celu_resp_2) values(%s, %s, %s, %s, %s, %s, %s, %s, %s)''', (ingr_apellido, ingr_nombre, ingr_dni, ingr_responsable_1, ingr_tel, ingr_cel, ingr_responsable_2, ingr_tel_2, ingr_cel_2))
#Evaluacion si hay datos en la grilla, si hay datos pasa al for e ingresa los datos a la tabla parientes
if self.checkbox_parientes.IsChecked():

#Grid, se recorren las celdas de a una tomando su valor
filas = self.rows + 1
for listar in range(filas):
col = 0
#La variable nombre es el dato que se encuentra en la primer columna
nombre = self.grid_parientes.GetCellValue(listar, col)
nombre = nombre.split()
#Toma el valor de apellido y pregunta a la db cual es su id
c.execute('''SELECT id_alumno FROM alumnos WHERE apellidos = %s and nombres = %s and documento = %s and responsable_1 = %s ''', (ingr_apellido, ingr_nombre, ingr_dni, ingr_responsable_1))
qApellido = c.fetchall()
col = 1
#La variable parentezco es el dato que se encuentra en la segunda columna
parentezco = self.grid_parientes.GetCellValue(listar, col)
#Evalua si se ingresa dato, la variable nombre
if nombre == []:
pariente = ' '
else:
pariente = nombre[0]
alumno = qApellido[0][0]
#Se ingresa a la db
c = base.cursor()
c.execute(''' insert into parientes(alumno, pariente, parentezco) values(%s,%s,%s)''', (alumno, pariente,parentezco))
#evalua si es tio
if parentezco == u'Tío/a':
parentezco = u'Sobrino/a'
c.execute(''' insert into parientes(alumno, pariente, parentezco) values(%s,%s,%s)''', (pariente, alumno, parentezco))
elif parentezco == u'Sobrino/a':
parentezco = u'Tío/a'
c.execute(''' insert into parientes(alumno, pariente, parentezco) values(%s,%s,%s)''', (pariente, alumno, parentezco))
else:
c.execute(''' insert into parientes(alumno, pariente, parentezco) values(%s,%s,%s)''', (pariente, alumno,parentezco))
c.close()

dgl = wx.MessageDialog(self,u'Tus Datos Fueron Ingresados Correctamente',u'Ingreso de datos',wx.OK | wx.ICON_INFORMATION)
dgl.ShowModal()
dgl.Destroy()
self.Close()
event.Skip()
# end of class MyFrame

if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = IngresoDatos(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()

Change log

r305 by dantesanfe3 on Nov 18, 2009   Diff
arreglo grilla
Go to: 
Project members, sign in to write a code review

Older revisions

r296 by dantesanfe3 on Oct 27, 2009   Diff
agregado ingresar parientes
r289 by dantesanfe3 on Oct 26, 2009   Diff
agrege upper
r252 by dantesanfe3 on Oct 14, 2009   Diff
correccion grilla
All revisions of this file

File info

Size: 15537 bytes, 320 lines

File properties

svn:executable
*
Powered by Google Project Hosting