forked from oli-cs/HackTheBurghX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
222 lines (172 loc) · 7.01 KB
/
main.py
File metadata and controls
222 lines (172 loc) · 7.01 KB
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
import tkinter as tk
from tkinter.font import Font
from PIL import ImageTk, Image
from suggestionAlgorithm import HouseTinder
global escapePressed
escapePressed = 0
def createGUI(data,backend):
page = tk.Tk()
page.attributes("-fullscreen", True)
# window with border are created as frames
border = tk.Frame(master=page, width=210, height=110, bg="DeepPink4")
window = tk.Frame(master=border, width=200, height=100, bg="thistle1")
# the frame that holds the image is created
imageFrame = tk.Frame(master=window)
# border and windows are packed to fit the page
border.pack(fill=tk.BOTH, expand=True, padx=30, pady=30)
window.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# image is resized into 500px by 500px aspect ratio
oldImg1 = Image.open(data[6])
img1 = ImageTk.PhotoImage(oldImg1.resize((700,500)))
# image is set to take the top left 4 grid boxes of the grid
imageFrame.grid(column=0, columnspan=4, row=0, rowspan=6, sticky='nw', padx=10, pady=10)
label1 = tk.Label(imageFrame, image = img1)
label1.pack(fill=tk.BOTH, expand=True)
# price
price = "£" + str(data[4])
text = tk.Label(window, text=price, bg="thistle1", font=Font(weight="bold", size=50))
text.grid(column=4, columnspan=4, row=0, sticky='n')
# address
address = data[5]
text2 = tk.Label(window, text=address, bg="thistle1", font=Font(size=35))
text2.grid(column=4, columnspan=4, row=1, sticky='n')
# description
description = data[7]
text3 = tk.Label(window, text=description, bg="thistle1", font=Font(size=23), wraplength=(94*7))
text3.grid(column=4, columnspan=4, row=2, rowspan=4, sticky='n')
# agency
agency = data[1]
text4 = tk.Label(window, text=agency, bg="thistle1", font=Font(size=23), padx=10)
text4.grid(column=0, columnspan=4, row=6, sticky='n')
# padding
padding = tk.Label(window, text=" ", bg="thistle1", font=Font(size=80))
padding.grid(column=0, row=7)
# bedroom icon
oldImg2 = Image.open("icons/bedroom.png")
img2 = ImageTk.PhotoImage(oldImg2.resize((100,100)))
bedroom = tk.Frame(master=window)
bedroom.grid(column=0, row=7, sticky='s')
label2 = tk.Label(bedroom, image=img2, bg="thistle1")
label2.pack(fill=tk.BOTH, expand=True)
# bedroom number
bedroomNum = str(data[2])
text5 = tk.Label(window, text=bedroomNum, bg="thistle1", font=Font(weight="bold", size=42))
text5.grid(column=1, row=7)
# bathroom icon
oldImg3 = Image.open("icons/bathroom.png")
img3 = ImageTk.PhotoImage(oldImg3.resize((100,100)))
bathroom = tk.Frame(master=window)
bathroom.grid(column=2, row=7, sticky='s')
label3 = tk.Label(bathroom, image=img3, bg="thistle1")
label3.pack(fill=tk.BOTH, expand=True)
# bathroom number
bathroomNum = str(data[3])
text6 = tk.Label(window, text=bathroomNum, bg="thistle1", font=Font(weight="bold", size=42))
text6.grid(column=3, row=7)
# left arrow
oldImg4 = Image.open("icons/left_arrow.png")
img4 = ImageTk.PhotoImage(oldImg4.resize((100,100)))
leftArrow = tk.Label(window, image=img4, bg="thistle1")
leftArrow.grid(column=5, row=6)
# dislike
text5 = tk.Label(window, text="dislike", bg="thistle1")
text5.grid(column=5, row=7, sticky='n')
# right arrow
oldImg5 = Image.open("icons/right_arrow.png")
img5 = ImageTk.PhotoImage(oldImg5.resize((100,100)))
rightArrow = tk.Label(window, image=img5, bg="thistle1")
rightArrow.grid(column=6, row=6)
# like
text5 = tk.Label(window, text="like", bg="thistle1")
text5.grid(column=6, row=7, sticky='n')
# reason text
if (backend.get_recommendation_reason() != "randomised"):
reason = tk.Label(window, text=backend.get_recommendation_reason(), bg='bisque')
reason.grid(column=5, columnspan=2, row=7, sticky='s')
# on left or right arrow key press, destroy page
def leftKey(event):
backend.append_left(data[0])
page.destroy()
def rightKey(event):
backend.append_right(data[0])
page.destroy()
# escape key
def escape(event):
global escapePressed
escapePressed = 1
page.destroy()
# detects arrow key presses
page.bind('<Left>', leftKey)
page.bind('<Right>', rightKey)
page.bind('<Escape>', escape)
page.mainloop()
return()
def end():
page = tk.Tk()
page.attributes("-fullscreen", True)
# window with border are created as frames
border = tk.Frame(master=page, width=210, height=110, bg="DeepPink4")
window = tk.Frame(master=border, width=200, height=100, bg="thistle1")
# the frame that holds the image is created
imageFrame = tk.Frame(master=window)
# border and windows are packed to fit the page
border.pack(fill=tk.BOTH, expand=True, padx=30, pady=30)
window.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# check back later text
text = tk.Label(window, text="You have viewed \n all properties in your \n area! Check back later \n for new additions.", font=Font(size=40), bg="thistle1")
text.pack(pady=50)
# logo
oldImg = Image.open("icons/logo.png")
img = ImageTk.PhotoImage(oldImg.resize((100,100)))
logo = tk.Label(window, image=img, bg="thistle1")
logo.pack(side='bottom', pady=50)
# escape key
def escape(event):
global escapePressed
escapePressed = 1
page.destroy()
page.bind('<Escape>', escape)
page.mainloop()
def titlePage():
page = tk.Tk()
page.attributes("-fullscreen", True)
# window with border are created as frames
border = tk.Frame(master=page, width=210, height=110, bg="DeepPink4")
window = tk.Frame(master=border, width=200, height=100, bg="thistle1")
# the frame that holds the image is created
imageFrame = tk.Frame(master=window)
# border and windows are packed to fit the page
border.pack(fill=tk.BOTH, expand=True, padx=30, pady=30)
window.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# title text
text = tk.Label(window, text="House Link", font=Font(weight="bold", size=80), bg='thistle1')
text.pack(pady=30)
def buttonPress():
page.destroy()
# button
button = tk.Button(window, text="Click here to start browsing!", font=Font(size=30), activebackground="bisque", command=buttonPress)
button.pack(pady=200)
# logo
oldImg = Image.open("icons/logo.png")
img = ImageTk.PhotoImage(oldImg.resize((100,100)))
logo = tk.Label(window, image=img, bg="thistle1")
logo.pack(side='bottom', pady=50)
# escape key
def escape(event):
global escapePressed
escapePressed = 1
page.destroy()
page.bind('<Escape>', escape)
page.mainloop()
def main():
global escapePressed
titlePage()
backend = HouseTinder()
createGUI(backend.get_next_house(),backend)
while escapePressed == 0:
nextHouse = backend.get_next_house()
if nextHouse != []:
createGUI(nextHouse,backend)
else:
end()
main()