-
Notifications
You must be signed in to change notification settings - Fork 0
/
VentanaExtra.py
161 lines (125 loc) · 5.69 KB
/
VentanaExtra.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
# -*- coding: cp1252 -*-
import Tkinter
from Tkinter import *
import tkMessageBox
import ttk
import Pmw
from SearchCriteria import askDb
class Demo:
def __init__(self, parent, tipo, consultaAdd, consultaDele, consultaEdit, consultaLista,foreignFun):
#
#Grupo de Creacion
#
self.consultaInsert = consultaAdd
self.consultaDelet = consultaDele
self.consultaEdit = consultaEdit
self.consultaLista = consultaLista
self.updateFun = foreignFun;
self.tipo = tipo
self.groupcrear = Pmw.Group(parent,
tag_pyclass = Tkinter.Button,
tag_text='Crear')
self.groupcrear.configure(tag_command = self.groupcrear.toggle)
self.groupcrear.pack(fill = 'both', expand = 1, padx = 6, pady = 6)
self.nuevo= Label(self.groupcrear.interior(),
text="Nuevo "+tipo+" :").grid(row=0,column=0,sticky=W,
padx=5, pady=5)
self.createVar = StringVar()
self.crearentry = Entry(self.groupcrear.interior(), width= 25, textvariable = self.createVar)
self.crearentry.grid(row=0,column=1)
self.buttoncrear = Button(self.groupcrear.interior(),text="Crear",
command= self.crear).grid(row=1,column=2,sticky=E,
padx=5, pady=5)
#Grupo de Borrado
#
self.groupborrar = Pmw.Group(parent,
tag_pyclass = Tkinter.Button,
tag_text='Borrar')
self.groupborrar.configure(tag_command = self.groupborrar.toggle)
self.groupborrar.pack(fill = 'both', expand = 1, padx = 6, pady = 6)
self.itemaborrar= Label(self.groupborrar.interior(),
text=tipo+" a borrar :").grid(row=0,column=0,sticky=W,
padx=5, pady=5)
self.deleteVar = StringVar()
self.itemCombo = ttk.Combobox(self.groupborrar.interior(),
textvariable=self.deleteVar,
state='readonly')
self.itemCombo['values'] = ()
self.itemCombo.grid(row=0,column=1,sticky=W, padx=5, pady=5)
self.buttonborrar = Button(self.groupborrar.interior(),text="Borrar",
command= self.borrar).grid(row=1,column=2,sticky=E,
padx=5, pady=5)
#
#Grupo de Editar
#
self.groupeditar = Pmw.Group(parent,
tag_pyclass = Tkinter.Button,
tag_text='Editar')
self.groupeditar.configure(tag_command = self.groupeditar.toggle)
self.groupeditar.pack(fill = 'both', expand = 1, padx = 6, pady = 6)
self.itemaeditar= Label(self.groupeditar.interior(),
text=tipo+" a editar :").grid(row=0,column=0,sticky=W,
padx=5, pady=5)
self.updateVar = StringVar()
self.newUpdateVar = StringVar()
self.itemCombo1 = ttk.Combobox(self.groupeditar.interior(),
postcommand=self.update,
textvariable=self.updateVar,
state='readonly')
self.itemCombo1.grid(row=0,column=1,sticky=W, padx=5, pady=5)
self.nuevo= Label(self.groupeditar.interior(),
text="Nuevo "+tipo+" :").grid(row=1,column=0,sticky=W,
padx=5, pady=5)
self.editarentry = Entry(self.groupeditar.interior(),
textvariable=self.newUpdateVar).grid(row=1,column=1)
self.buttoneditar = Button(self.groupeditar.interior(),text="Editar",
command= self.editar).grid(row=2,column=2,sticky=E,
padx=5, pady=5)
self.update()
def crear(self):
print "Se esta creando"
params = (str(self.createVar.get()),)
askDb(self.consultaInsert,params)
self.update()
def borrar(self):
result = tkMessageBox.askquestion("Borrar", "Estas completamente seguro?", icon='warning')
if result == 'yes':
print "Se esta borrando"
print str(self.deleteVar.get())
test = str(self.deleteVar.get()).split(",")
if len(test) > 1:
nombreViejo = test[1]
else:
nombreViejo = test[0]
params = (nombreViejo,)
askDb(self.consultaDelet,params)
self.update()
else:
print "No voy a borrar"
def editar(self):
print "Se esta editando"
test = str(self.updateVar.get()).split(",")
if len(test) > 1:
nombreViejo = test[1]
else:
nombreViejo = test[0]
nombreNuevo = str(self.newUpdateVar.get())
params = (nombreNuevo,nombreViejo,)
askDb(self.consultaEdit,params)
self.update()
def update(self):
print "Actualizando lista de entidades "+str(self.tipo)
params = ('',)
lista = askDb(self.consultaLista,params)
listaOut = []
for elem in lista:
if (len(elem) > 1):
listaOut.append(str(elem[0])+","+str(elem[1]))
else:
listaOut.append(str(elem[0]))
self.itemCombo['values'] = tuple(listaOut)
self.itemCombo1['values'] = tuple(listaOut)
if len(lista) > 0:
self.itemCombo1.current(0)
self.itemCombo.current(0)
self.updateFun()