-
Notifications
You must be signed in to change notification settings - Fork 0
/
principalView.py
165 lines (138 loc) · 7.07 KB
/
principalView.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
import tkinter as ttk
from tkinter.ttk import *
from db import *
class principalView(ttk.Frame):
def __init__(self, parent):
super().__init__(parent)
self.parent = parent
self.title = ttk.Label(self, text="Revisión Ocular")
self.title.config(font=('Helvetica bold', 25))
self.title.grid(row=0, column=1, padx=10, pady=10, columnspan=4)
self.labelNIF = ttk.Label(self, text="NIF")
self.labelNIF.grid(row=2, column=2, pady=10)
self.labelNombre = ttk.Label(self, text="Nombre")
self.labelNombre.grid(row=3, column=2, pady=10)
self.labelApellidos = ttk.Label(self, text="Apellidos")
self.labelApellidos.grid(row=4, column=2, pady=10)
self.labelEdad = ttk.Label(self, text="Edad")
self.labelEdad.grid(row=5, column=2, pady=10)
self.tNIF = ttk.Text(self, height=1, width=30)
self.tNIF.grid(row=2, column=2, padx=10, pady=10, columnspan=4)
self.tNombre = ttk.Text(self, height=1, width=30)
self.tNombre.grid(row=3, column=2, padx=10, pady=10, columnspan=4)
self.tApellidos = ttk.Text(self, height=1, width=30)
self.tApellidos.grid(row=4, column=2, padx=10, pady=10, columnspan=4)
# Button
self.bRevisiones = ttk.Button(self, height=2, width=14, text="Revisiones",
command=self.revisiones_button_clicked)
self.bRevisiones.grid(row=5, column=4, padx=10, pady=20)
self.bAnyadir = ttk.Button(self, height=1, width=10, text="Añadir", command=self.anyadir_button_clicked)
self.bAnyadir.grid(row=6, column=1, padx=10, pady=20)
self.bActualizar = ttk.Button(self, height=1, width=10, text="Actualizar",
command=self.actualizar_button_clicked)
self.bActualizar.grid(row=6, column=2, padx=10, pady=20)
self.bBorrar = ttk.Button(self, height=1, width=10, text="Borrar", command=self.borrar_button_clicked)
self.bBorrar.grid(row=6, column=3, padx=10, pady=20)
self.bLimpiar = ttk.Button(self, height=1, width=10, text="Limpiar", command=self.limpiar_button_clicked)
self.bLimpiar.grid(row=6, column=4, padx=10, pady=20)
self.bSalir = ttk.Button(self, height=1, width=10, text="Salir", command=self.salir_button_clicked)
self.bSalir.grid(row=6, column=5, padx=10, pady=20)
# ListBox
self.list = ttk.Frame(self)
scroll = ttk.Scrollbar(self.list)
scroll.pack(side="right", fill="y")
self.list.listEdad = ttk.Listbox(self.list, height=3, width=15)
aux = list(range(1, 101))
self.list.listEdad.insert("end", *aux)
self.list.listEdad.pack()
self.list.grid(row=5, column=3, padx=10, pady=10)
# Datagrid
# scrollbar
self.datagrid = ttk.Frame(self)
scroll = ttk.Scrollbar(self.datagrid)
scroll.pack(side="right", fill="y")
scroll = ttk.Scrollbar(self.datagrid, orient='horizontal')
scroll.pack(side="bottom", fill="x")
self.datagrid.my_table = Treeview(self.datagrid, yscrollcommand=scroll.set, xscrollcommand=scroll.set)
self.datagrid.my_table.pack()
self.datagrid.grid(row=1, column=2, padx=10, pady=10, columnspan=3)
# define our column
self.datagrid.my_table['columns'] = ('NIF', 'NOMBRE', 'APELLIDOS', 'EDAD')
# format our column
self.datagrid.my_table.column("#0", width=0, stretch=False)
self.datagrid.my_table.column("NIF", anchor="center", width=80)
self.datagrid.my_table.column("NOMBRE", anchor="center", width=80)
self.datagrid.my_table.column("APELLIDOS", anchor="center", width=80)
self.datagrid.my_table.column("EDAD", anchor="center", width=80)
# Create Headings
self.datagrid.my_table.heading("#0", text="", anchor="center")
self.datagrid.my_table.heading("NIF", text="NIF", anchor="center")
self.datagrid.my_table.heading("NOMBRE", text="NOMBRE", anchor="center")
self.datagrid.my_table.heading("APELLIDOS", text="APELLIDOS", anchor="center")
self.datagrid.my_table.heading("EDAD", text="EDAD", anchor="center")
# Event
self.datagrid.my_table.bind("<<TreeviewSelect>>", self.selection_changed)
self.update_refresh()
self.controller = None
def update_refresh(self):
mydb = db()
query = "SELECT * FROM tclient"
rows = mydb.query(query)
self.update_datagrid(rows)
def selection_changed(self, x):
if self.controller:
if len(self.datagrid.my_table.selection()) > 0:
item = self.datagrid.my_table.selection()[0]
row = self.datagrid.my_table.item(item)['values']
self.controller.selection_changed(row)
def update_datagrid(self, rows):
for i in self.datagrid.my_table.get_children():
self.datagrid.my_table.delete(i)
for i in rows:
self.datagrid.my_table.insert('', 'end', values=(i['NIF'], i['NOMBRE'], i['APELLIDOS'], i['EDAD']))
def set_controller(self, controller):
self.controller = controller
def salir_button_clicked(self):
if self.controller:
self.controller.salir(self.parent)
def limpiar_button_clicked(self):
if self.controller:
self.controller.limpiar()
def anyadir_button_clicked(self):
try:
if self.controller:
self.controller.anyadir(self.tNIF.get("0.0", "end-1c"),
self.tNombre.get("0.0", "end-1c"),
self.tApellidos.get("0.0", "end-1c"),
self.list.listEdad.get(self.list.listEdad.curselection()[0]))
except ValueError as error:
# show an error message
self.view.show_error(error)
def borrar_button_clicked(self):
try:
if self.controller:
self.controller.borrar(self.tNIF.get("0.0", "end-1c"))
except ValueError as error:
# show an error message
self.view.show_error(error)
def revisiones_button_clicked(self):
try:
if self.controller:
mydb = db()
query = "SELECT NIF FROM tclient WHERE NIF = '"+self.tNIF.get("0.0", "end-1c")+"';"
rows = mydb.query(query)
if len(rows) > 0:
self.controller.revisiones(self.tNIF.get("0.0", "end-1c"), self.parent)
except ValueError as error:
# show an error message
self.view.show_error(error)
def actualizar_button_clicked(self):
try:
if self.controller:
self.controller.actualizar(self.tNIF.get("0.0", "end-1c"),
self.tNombre.get("0.0", "end-1c"),
self.tApellidos.get("0.0", "end-1c"),
self.list.listEdad.get(self.list.listEdad.curselection()[0]))
except ValueError as error:
# show an error message
self.view.show_error(error)