-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
277 lines (229 loc) · 12.8 KB
/
controller.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
from datetime import datetime
from tkinter import END, W, commondialog
from setuptools import Command
from model import Model
from view import View
class Controller:
def __init__(self,root):
self.root = root
self.model = Model()
self.view = View(self.root)
self.model.create_tables()
#self.view.ch1_top_btn_on.config(command=self.ch1_btn_on_click)
self.view.section_list_tree.bind("<ButtonRelease-1>",self.section_click)
self.view.plot_tree.bind("<ButtonRelease-1>",self.plot_click)
self.view.record_tree.bind("<ButtonRelease-1>",self.record_click)
self.view.section_add_button.config(command=self.add_new_section)
self.view.section_edit_button.config(command=self.edit_section_name)
self.view.plot_add_button.config(command=self.add_plot)
self.view.plot_edit_button.config(command=self.edit_plot)
self.view.deceased_add_button.config(command=self.add_deceased)
self.view.deceased_edit_button.config(command=self.edit_deceased)
self.view.display_section_names(self.model.get_section_names())
def section_click(self,event):
self.view.deceased_add_button["state"] = "disabled"
#Check to see if ALL was clicked and if so, we want to show the section but if they click a section that isn't all, we want to show which section
self.selected = self.view.section_list_tree.focus()
values = list(self.view.section_list_tree.item(self.selected,'values'))
if len(values)>0:
#Update the edit box
self.view.section_edit_entry.delete(0,END)
self.view.section_edit_entry.insert(END,values[1])
if values[1] == "All":
self.view.section_edit_button["state"] = "disabled"
self.view.plot_add_button["state"] = "disabled"
self.view.plot_tree.column("section", anchor=W, width=40,stretch=1)
self.view.plot_tree.column("section_owner", anchor=W, width=110)
else:
self.view.section_edit_button["state"] = "normal"
self.view.plot_add_button["state"] = "normal"
self.view.plot_tree.column("section", anchor=W, width=0,stretch=0)
self.view.plot_tree.column("section_owner", anchor=W, width=150)
self.view.plot_tree.delete(*self.view.plot_tree.get_children())
self.view.record_tree.delete(*self.view.record_tree.get_children())
self.view.display_plot_owners(self.model.query_plot_owners(values[1]))
#Update the plot entry information
self.view.plot_add_entry_section["state"] = "normal"
self.view.plot_add_entry_section.delete(0,END)
self.view.plot_add_entry_section.insert(END,values[1])
self.view.plot_add_entry_section["state"] = "disabled"
self.view.deceased_add_entry_sname.delete(0,END)
def add_new_section(self):
input_name = self.view.section_add_entry.get().capitalize()
valid_name = True
if not input_name:
valid_name = False
self.view.create_messagebox("Can't have empty names.")
if valid_name == True:
for item in self.model.get_section_names():
if input_name == item[1]:
self.view.create_messagebox("Duplicate Plot Name: Please enter a different name.")
valid_name = False
break
if valid_name == True:
self.model.create_section(input_name)
self.refresh_section()
def edit_section_name(self):
input_name = self.view.section_add_entry.get()
selected = self.view.section_list_tree.focus()
values = list(self.view.section_list_tree.item(selected,'values'))
if input_name== "All" or input_name in self.model.get_section_names():
self.view.create_messagebox("Duplicate Section Name: Please enter a different name.")
elif ' ' in input_name:
self.view.create_messagebox("Section must not contain whitespace.")
else:
self.model.update_section_name(values[0],values[1],self.view.section_edit_entry.get())
self.refresh_section()
#Clear the edit entry.
self.view.section_edit_entry.delete(0,END)
self.view.section_edit_button["state"] = "disabled"
#Clear the Plot List
self.view.plot_tree.delete(*self.view.plot_tree.get_children())
#Clear the Plot Section Add
self.view.plot_add_entry_section["state"] = "normal"
self.view.plot_add_entry_section.delete(0,END)
self.view.plot_add_entry_section["state"] = "disabled"
def add_plot(self):
input_section = self.view.plot_add_entry_section.get()
input_name = self.view.plot_add_entry_owner.get()
input_plot_number = self.view.plot_add_entry_number.get()
check_num = False
check_plot = False
if input_plot_number.isdigit():
#check to see if a plot number already exists:
if len(self.model.query_plot(input_section,input_plot_number)) == 0:
check_plot = True
else:
self.view.create_messagebox("Plot Number must be a whole number.")
if check_plot == True and len(input_name) > 0:
self.model.create_plot(input_name,input_section,input_plot_number)
self.view.plot_tree.delete(*self.view.plot_tree.get_children())
self.view.display_plot_owners(self.model.query_plot_owners(input_section))
#Clear the box after entered.
self.view.plot_add_entry_owner.delete(0,END)
self.view.plot_add_entry_number.delete(0,END)
else:
self.view.create_messagebox("Unable to create plot. Check Plot Owner has been entered.")
def edit_plot(self):
input_section = self.view.plot_edit_entry_section.get()
input_name = self.view.plot_edit_entry_owner.get()
input_number = self.view.plot_edit_entry_number.get()
selected = self.view.plot_tree.focus()
values = self.view.plot_tree.item(selected,'values')
if not self.model.query_plot(input_section,input_number):
self.model.update_plot(values[0],input_name,input_section,input_number)
self.refresh_plots()
self.view.plot_edit_button["state"] = "disabled"
self.view.plot_edit_entry_owner.delete(0,END)
self.view.plot_edit_entry_number.delete(0,END)
else:
self.view.create_messagebox("Plot with that Section & Number already exists.")
def add_deceased(self):
#Plot Information:
selected = self.view.plot_tree.focus()
values = self.view.plot_tree.item(selected,'values')
input_fname = self.view.deceased_add_entry_fname.get()
input_sname = self.view.deceased_add_entry_sname.get()
input_date = self.view.deceased_add_entry_date.get()
if len(input_fname) and len(input_sname) and len(input_date) > 0:
if self.check_date(input_date):
self.model.create_deceased(values[0],input_fname,input_sname,input_date)
self.refresh_deceased()
self.view.deceased_add_entry_fname.delete(0,END)
self.view.deceased_add_entry_date.delete(0,END)
else:
pass
#messagebox.showerror("Error", "Date Format Error: Make sure date is: YYYY-MM-DD. Example: 2010,12,20")
else:
self.view.create_messagebox("Error", "All boxes must be filled.")
def edit_deceased(self):
input_fname = self.view.deceased_edit_entry_fname.get()
input_sname = self.view.deceased_edit_entry_sname.get()
input_date = self.view.deceased_edit_entry_date.get()
selected = self.view.record_tree.focus()
values = self.view.record_tree.item(selected,'values')
self.model.update_deceased(values[0],input_fname,input_sname,input_date)
self.refresh_deceased()
self.view.deceased_edit_button["state"] = "disabled"
self.view.deceased_edit_entry_fname.delete(0,END)
self.view.deceased_edit_entry_sname.delete(0,END)
self.view.deceased_edit_entry_date.delete(0,END)
def section_click(self,event):
self.view.deceased_add_button["state"] = "disabled"
#Check to see if ALL was clicked and if so, we want to show the section but if they click a section that isn't all, we want to show which section
selected = self.view.section_list_tree.focus()
values = list(self.view.section_list_tree.item(selected,'values'))
if len(values)>0:
#Update the edit box
self.view.section_edit_entry.delete(0,END)
self.view.section_edit_entry.insert(END,values[1])
if values[1] == "All":
self.view.section_edit_button["state"] = "disabled"
self.view.plot_add_button["state"] = "disabled"
self.view.plot_tree.column("section", anchor=W, width=40,stretch=1)
self.view.plot_tree.column("section_owner", anchor=W, width=110)
else:
self.view.section_edit_button["state"] = "normal"
self.view.plot_add_button["state"] = "normal"
self.view.plot_tree.column("section", anchor=W, width=0,stretch=0)
self.view.plot_tree.column("section_owner", anchor=W, width=150)
self.view.plot_tree.delete(*self.view.plot_tree.get_children())
self.view.record_tree.delete(*self.view.record_tree.get_children())
self.view.display_plot_owners(self.model.query_plot_owners(values[1]))
#Update the plot entry information
self.view.plot_add_entry_section["state"] = "normal"
self.view.plot_add_entry_section.delete(0,END)
self.view.plot_add_entry_section.insert(END,values[1])
self.view.plot_add_entry_section["state"] = "disabled"
def plot_click(self,event):
selected = self.view.plot_tree.focus()
values = self.view.plot_tree.item(selected,'values')
if len(values) > 0:
#Change Plot display
self.view.plot_edit_entry_owner.delete(0,END)
self.view.plot_edit_entry_owner.insert(END, values[1])
self.view.plot_edit_entry_section.delete(0,END)
self.view.plot_edit_entry_section.insert(END, values[2])
self.view.plot_edit_entry_number.delete(0,END)
self.view.plot_edit_entry_number.insert(END, values[3])
self.view.plot_edit_button["state"] = "normal"
#Change Deceased Display
self.view.deceased_add_entry_plot["state"] = "normal"
self.view.deceased_add_entry_plot.delete(0,END)
self.view.deceased_add_entry_plot.insert(END,values[1])
self.view.deceased_add_entry_plot["state"] = "disabled"
self.view.deceased_add_button["state"] = "normal"
#Clear the input boxes.
self.view.record_tree.delete(*self.view.record_tree.get_children())
self.view.display_deceased_records(self.model.query_deceased_by_id(values[0]))
self.view.deceased_add_entry_sname.delete(0,END)
#self.load_image()
def record_click(self,event):
selected = self.view.record_tree.focus()
values = self.view.record_tree.item(selected,'values')
if len(values) > 0:
self.view.deceased_edit_entry_fname.delete(0,END)
self.view.deceased_edit_entry_sname.delete(0,END)
self.view.deceased_edit_entry_date.delete(0,END)
self.view.deceased_edit_entry_fname.insert(END,values[2])
self.view.deceased_edit_entry_sname.insert(END,values[3])
self.view.deceased_edit_entry_date.insert(END,values[4])
self.view.deceased_edit_button["state"] = "normal"
def refresh_section(self):
self.view.section_list_tree.delete(*self.view.section_list_tree.get_children())
self.view.display_section_names(self.model.get_section_names())
def refresh_plots(self):
selected = self.view.section_list_tree.focus()
values = list(self.view.section_list_tree.item(selected,'values'))
self.view.plot_tree.delete(*self.view.plot_tree.get_children())
self.view.display_plot_owners(self.model.query_plot_owners(values[1]))
def refresh_deceased(self):
selected = self.view.plot_tree.focus()
values = list(self.view.plot_tree.item(selected,'values'))
self.view.record_tree.delete(*self.view.record_tree.get_children())
self.view.display_deceased_records(self.model.query_deceased_by_id(values[0]))
def check_date(self,input_date):
try:
return bool(datetime.strptime(input_date, "%Y/%m/%d"))
except ValueError:
return False