-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
336 lines (282 loc) · 12.8 KB
/
main.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
import sys
from PyQt5 import QtWidgets
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QDialog, QApplication, QListWidget, QListWidgetItem
from PyQt5.uic import loadUi
from models.aggregator import *
class WelcomeScreen(QDialog):
def __init__(self):
super(WelcomeScreen, self).__init__()
loadUi("UI/welcomescreen.ui", self)
self.login.clicked.connect(self.goto_login)
self.create.clicked.connect(self.goto_create)
@staticmethod
def goto_login():
login = LoginScreen()
widget.addWidget(login)
widget.setCurrentIndex(widget.currentIndex() + 1)
@staticmethod
def goto_create():
create = CreateAccScreen()
widget.addWidget(create)
widget.setCurrentIndex(widget.currentIndex() + 1)
class LoginScreen(QDialog):
def __init__(self):
super(LoginScreen, self).__init__()
loadUi("UI/login.ui", self)
self.passwordfield.setEchoMode(QtWidgets.QLineEdit.Password)
self.login.clicked.connect(self.login_function)
self.back.clicked.connect(self.goto_welcome_screen)
def login_function(self):
user = self.emailfield.text()
password = self.passwordfield.text()
if len(user) == 0 or len(password) == 0:
self.error.setText("Please input all fields.")
else:
if aggregator.login(user, password):
self.goto_choice_of_action()
print("Successfully logged in.")
self.error.setText("")
else:
self.error.setText("Invalid username or password")
def goto_choice_of_action(self):
choice_of_action = ChoiceOfAction()
self.login.clicked.connect(self.goto_choice_of_action)
widget.addWidget(choice_of_action)
widget.setCurrentIndex(widget.currentIndex() + 1)
@staticmethod
def goto_welcome_screen():
aggregator.user.set_login('')
welcome_screen = WelcomeScreen()
widget.addWidget(welcome_screen)
widget.setCurrentIndex(widget.currentIndex() + 1)
class ChoiceOfAction(QDialog):
def __init__(self):
super(ChoiceOfAction, self).__init__()
loadUi("UI/choiceofaction.ui", self)
self.listFilms.clicked.connect(self.display_list_films)
self.listTv.clicked.connect(self.display_list_tv)
self.logout.clicked.connect(self.goto_welcome_screen)
def display_list_films(self):
list_films = ListFilms()
self.listFilms.clicked.connect(self.display_list_films)
widget.addWidget(list_films)
widget.setCurrentIndex(widget.currentIndex() + 1)
def display_list_tv(self):
list_tv = ListTv()
self.listTv.clicked.connect(self.display_list_tv)
widget.addWidget(list_tv)
widget.setCurrentIndex(widget.currentIndex() + 1)
@staticmethod
def goto_welcome_screen():
aggregator.user.set_login('')
welcome_screen = WelcomeScreen()
widget.addWidget(welcome_screen)
widget.setCurrentIndex(widget.currentIndex() + 1)
class ListFilms(QDialog, QListWidget):
def __init__(self):
super(ListFilms, self).__init__()
self.resize(1200, 800)
self.setStyleSheet('font-size: 40px')
loadUi("UI/films.ui", self)
content_list = aggregator.get_content_list()
list_films = content_list.list_films
self.listFilms.setViewMode(QListWidget.IconMode)
self.listFilms.setResizeMode(QListWidget.Adjust)
self.listFilms.setSpacing(10)
icon_size = QSize()
icon_size.setHeight(150)
icon_size.setWidth(150)
self.listFilms.setIconSize(icon_size)
self.listFilms.setMovement(QListWidget.Static)
for film in list_films:
item = QListWidgetItem(film.name)
item.setIcon(QIcon(aggregator.parse_image(film.url)))
item.setSizeHint(QSize(200, 200))
self.listFilms.addItem(item)
self.addRating.clicked.connect(self.add_sel_rating)
self.removeRating.clicked.connect(self.del_sel_rating)
self.listFilms.itemDoubleClicked.connect(self.launch_more_info)
self.back.clicked.connect(self.goto_choice_of_action)
@staticmethod
def goto_choice_of_action():
choice_of_action = ChoiceOfAction()
widget.addWidget(choice_of_action)
widget.setCurrentIndex(widget.currentIndex() + 1)
def add_sel_rating(self):
rating = self.spinRating.text()
film = self.listFilms.selectedItems()
if len(film) > 0:
film = film[0]
aggregator.edit_user_rating_film(film.text(), rating)
def del_sel_rating(self):
film = self.listFilms.selectedItems()
if len(film) > 0:
film = film[0]
aggregator.remove_user_rating_film(film.text())
def launch_more_info(self, item):
content_list = aggregator.get_content_list()
list_films = content_list.list_films
for film in list_films:
if film.name == item.text():
pop = MoreInfoForFilm(film, self)
pop.show()
class MoreInfoForFilm(QDialog):
def __init__(self, film, parent):
super().__init__(parent)
loadUi("UI/moreInfoForFilm.ui", self)
self.name_film.setText(film.name)
self.year.setText(str(film.year))
self.country.setText(film.country)
self.director.setText(film.director)
self.duration.setText(str(film.duration) + ' min')
self.genre.setText(film.genre)
self.budget.setText(str(film.budget) + ' $$$')
self.rating.setText(str(film.rating))
self.description.setText(film.description)
self.average_rating.setText(str(aggregator.average_rating_film(film.name)))
self.number_rating.setText(str(aggregator.number_user_rating_film(film.name)))
self.my_rating.setText(str(aggregator.get_user_rating_film(film.name)))
image = QPixmap(aggregator.parse_image(film.url))
self.image.setPixmap(image.scaledToWidth(312))
self.add_rating.clicked.connect(self.add_rating_film)
self.remove_rating.clicked.connect(self.del_rating_film)
def add_rating_film(self):
rating = self.spinRating.text()
if len(rating) > 0:
aggregator.edit_user_rating_film(self.name_film.text(), rating)
self.average_rating.setText(str(aggregator.average_rating_film(self.name_film.text())))
self.number_rating.setText(str(aggregator.number_user_rating_film(self.name_film.text())))
self.my_rating.setText(str(aggregator.get_user_rating_film(self.name_film.text())))
def del_rating_film(self):
aggregator.remove_user_rating_film(self.name_film.text())
self.average_rating.setText(str(aggregator.average_rating_film(self.name_film.text())))
self.number_rating.setText(str(aggregator.number_user_rating_film(self.name_film.text())))
self.my_rating.setText(str(aggregator.get_user_rating_film(self.name_film.text())))
class ListTv(QDialog, QListWidget):
def __init__(self):
super(ListTv, self).__init__()
self.resize(1200, 800)
self.setStyleSheet('font-size: 40px')
loadUi("UI/tv.ui", self)
content_list = aggregator.get_content_list()
list_tv = content_list.list_tv_shows
self.listTv.setViewMode(QListWidget.IconMode)
self.listTv.setResizeMode(QListWidget.Adjust)
self.listTv.setSpacing(10)
icon_size = QSize()
icon_size.setHeight(150)
icon_size.setWidth(150)
self.listTv.setIconSize(icon_size)
self.listTv.setMovement(QListWidget.Static)
for tv in list_tv:
item = QListWidgetItem(tv.name)
item.setIcon(QIcon(aggregator.parse_image(tv.url)))
item.setSizeHint(QSize(200, 200))
self.listTv.addItem(item)
self.addRating.clicked.connect(self.add_sel_rating)
self.removeRating.clicked.connect(self.del_sel_rating)
self.listTv.itemDoubleClicked.connect(self.launch_more_info)
self.back.clicked.connect(self.goto_choice_of_action)
@staticmethod
def goto_choice_of_action():
choice_of_action = ChoiceOfAction()
widget.addWidget(choice_of_action)
widget.setCurrentIndex(widget.currentIndex() + 1)
def add_sel_rating(self):
rating = self.spinRating.text()
tv = self.listTv.selectedItems()
if len(tv) > 0:
tv = tv[0]
aggregator.edit_user_rating_tv_show(tv.text(), rating)
def del_sel_rating(self):
tv = self.listTv.selectedItems()
if len(tv) > 0:
tv = tv[0]
aggregator.remove_user_rating_tv_show(tv.text())
def launch_more_info(self, item):
content_list = aggregator.get_content_list()
list_tv = content_list.list_tv_shows
for tv in list_tv:
if tv.name == item.text():
pop = MoreInfoForTv(tv, self)
pop.show()
class MoreInfoForTv(QDialog):
def __init__(self, tv, parent):
super().__init__(parent)
loadUi("UI/moreInfoForTv.ui", self)
self.name_tv.setText(tv.name)
self.year.setText(str(tv.year))
self.country.setText(tv.country)
self.director.setText(tv.director)
self.number_seasons.setText(str(tv.number_seasons))
self.genre.setText(tv.genre)
self.number_episodes.setText(str(tv.number_episodes))
self.rating.setText(str(tv.rating))
self.description.setText(tv.description)
self.average_rating.setText(str(aggregator.average_rating_tv_show(tv.name)))
self.number_rating.setText(str(aggregator.number_user_rating_tv_show(tv.name)))
self.my_rating.setText(str(aggregator.get_user_rating_tv(tv.name)))
image = QPixmap(aggregator.parse_image(tv.url))
self.image.setPixmap(image.scaledToWidth(312))
self.add_rating.clicked.connect(self.add_rating_tv)
self.remove_rating.clicked.connect(self.del_rating_tv)
def add_rating_tv(self):
rating = self.spinRating.text()
if len(rating) > 0:
aggregator.edit_user_rating_tv_show(self.name_tv.text(), rating)
self.average_rating.setText(str(aggregator.average_rating_tv_show(self.name_tv.text())))
self.number_rating.setText(str(aggregator.number_user_rating_tv_show(self.name_tv.text())))
self.my_rating.setText(str(aggregator.get_user_rating_tv(self.name_tv.text())))
def del_rating_tv(self):
aggregator.remove_user_rating_tv_show(self.name_tv.text())
self.average_rating.setText(str(aggregator.average_rating_tv_show(self.name_tv.text())))
self.number_rating.setText(str(aggregator.number_user_rating_tv_show(self.name_tv.text())))
self.my_rating.setText(str(aggregator.get_user_rating_tv(self.name_tv.text())))
class CreateAccScreen(QDialog):
def __init__(self):
super(CreateAccScreen, self).__init__()
loadUi("UI/createacc.ui", self)
self.passwordfield.setEchoMode(QtWidgets.QLineEdit.Password)
self.confirmpasswordfield.setEchoMode(QtWidgets.QLineEdit.Password)
self.signup.clicked.connect(self.signup_function)
self.back.clicked.connect(self.goto_welcome_screen)
def signup_function(self):
user = self.emailfield.text()
password = self.passwordfield.text()
confirm_password = self.confirmpasswordfield.text()
if len(user) == 0 or len(password) == 0 or len(confirm_password) == 0:
self.error.setText("Please fill in all inputs.")
elif password != confirm_password:
self.error.setText("Passwords do not match.")
else:
if aggregator.signup(user, password):
self.goto_login()
print("Successfully signup in.")
else:
self.error.setText("User with this name is already registered")
def goto_login(self):
login = LoginScreen()
self.signup.clicked.connect(self.goto_login)
widget.addWidget(login)
widget.setCurrentIndex(widget.currentIndex() + 1)
@staticmethod
def goto_welcome_screen():
aggregator.user.set_login('')
welcome_screen = WelcomeScreen()
widget.addWidget(welcome_screen)
widget.setCurrentIndex(widget.currentIndex() + 1)
# main
aggregator = Aggregator()
app = QApplication(sys.argv)
welcome = WelcomeScreen()
widget = QtWidgets.QStackedWidget()
widget.addWidget(welcome)
widget.setFixedHeight(800)
widget.setFixedWidth(1200)
widget.show()
try:
sys.exit(app.exec_())
except:
print("Exiting")