-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathShowView.py
118 lines (95 loc) · 3.48 KB
/
ShowView.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
import tkinter as tk
from tkinter import ttk
from views.View import View
"""
View responsible for showing registered customers.
"""
class ShowView(tk.Tk, View):
#-----------------------------------------------------------------------
# Constants
#-----------------------------------------------------------------------
PAD = 10
THEADER = [
"Id", "First name", "Last name", "Zipcode", "Price paid"
]
#-----------------------------------------------------------------------
# Constructor
#-----------------------------------------------------------------------
"""
@param controller Controller of this view
"""
def __init__(self, controller):
super().__init__()
self.title("Show Customers")
self.showController = controller
self._make_mainFrame()
self._make_title()
self._show_customers()
#-----------------------------------------------------------------------
# Methods
#-----------------------------------------------------------------------
"""
Creates view's frame.
"""
def _make_mainFrame(self):
self.frame_main = ttk.Frame(self)
self.frame_main.pack(padx=self.PAD, pady=self.PAD)
"""
Sets view's title.
"""
def _make_title(self):
title = ttk.Label(self.frame_main, text="Customers Manager - Show", font=("Helvetica", 20))
title.pack(padx=self.PAD, pady=self.PAD)
"""
Displays customers on screen.
"""
def _show_customers(self):
customers = self.showController.getCustomers()
frame_customers = tk.Frame(self.frame_main)
frame_customers.pack(fill="x")
self.frame_customers = frame_customers
data_frame = tk.Frame(frame_customers)
data_frame.pack()
# Show header
lbl = ttk.Label(data_frame, text="Action")
lbl.grid(row=0, column=0, padx=self.PAD, pady=self.PAD)
j = 1
for caption in self.THEADER:
lbl = ttk.Label(data_frame, text=caption)
lbl.grid(row=0, column=j, padx=self.PAD, pady=self.PAD)
j += 1
# Show data
for index,values in enumerate(customers):
j = 1
index += 1
frame_actions = tk.Frame(data_frame)
frame_actions.grid(row=index, column=0, padx=self.PAD, pady=5)
# Make edit button
btn_edit = ttk.Button(frame_actions, text="Edit", command=lambda id=values[0]: self.showController.btnEdit(id))
btn_edit.pack(side="left")
# Make delete button
btn_exc = ttk.Button(frame_actions, text="Delete", command=lambda id=values[0]: self.showController.btnDel())
btn_exc.pack(side="left")
# Put customer data on screen
for item in values:
lbl = tk.Label(data_frame, text=item)
lbl.grid(row=index, column=j, padx=self.PAD, pady=5)
j += 1
btn = ttk.Button(frame_customers, text="Update data", command=self.update)
btn.pack()
"""
Refreshes view.
"""
def update(self):
self.frame_customers.destroy()
self._show_customers()
"""
@Overrite
"""
def main(self):
self.mainloop()
"""
@Overrite
"""
def close(self):
return