-
Notifications
You must be signed in to change notification settings - Fork 1
/
movie_info_rc.py
129 lines (111 loc) · 5.56 KB
/
movie_info_rc.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
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'movie_info.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtCore, QtGui, QtWidgets
import resource_rc
import random
import client
class Ui_Form(QtWidgets.QWidget):
def __init__(self, data,main_UI=None,buttonon=True):
super(Ui_Form, self).__init__()
self.setupUi(data,main_UI,buttonon)
def setupUi(self, data,main_UI=None,buttonon=True):
self.main_UI=main_UI
self.setObjectName("Form")
self.resize(667, 522)
self.ID= data['MovieID']
self.verticalLayout_10 = QtWidgets.QVBoxLayout(self)
self.verticalLayout_10.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_10.setObjectName("verticalLayout_10")
self.movie_gridLayout = QtWidgets.QGridLayout()
self.movie_gridLayout.setObjectName("movie_gridLayout")
self.language = QtWidgets.QLabel(self)
self.language.setObjectName("language")
self.movie_gridLayout.addWidget(self.language, 0, 2, 1, 1)
self.review_num = QtWidgets.QLabel(self)
self.review_num.setObjectName("review_num")
self.movie_gridLayout.addWidget(self.review_num, 1, 0, 1, 1)
self.rate = QtWidgets.QLabel(self)
self.rate.setObjectName("rate")
self.movie_gridLayout.addWidget(self.rate, 1, 1, 1, 1)
self.genre = QtWidgets.QLabel(self)
self.genre.setObjectName("genre")
self.movie_gridLayout.addWidget(self.genre, 0, 1, 1, 1)
self.collect_widget = QtWidgets.QWidget(self)
self.collect_widget.setObjectName("collect_widget")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.collect_widget)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
spacerItem = QtWidgets.QSpacerItem(115, 20, QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem)
self.pushButton = QtWidgets.QToolButton(self.collect_widget)
self.pushButton.setText("")
self.pushButton.setCheckable(True) # Make the button checkable
self.pushButton.setChecked(buttonon) # Set the initial state
self.checked_image = QtGui.QPixmap(":/icons/icons/favor_t.png")
self.unchecked_image = QtGui.QPixmap(":/icons/icons/favor.png")
self.pushButton.toggled.connect(self.checkPrecondition)
self.Buttoninitialize()
self.pushButton.setObjectName("pushButton")
self.horizontalLayout_3.addWidget(self.pushButton)
self.movie_gridLayout.addWidget(self.collect_widget, 1, 2, 1, 1)
self.name_pushbutton = QtWidgets.QPushButton(self)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.name_pushbutton.sizePolicy().hasHeightForWidth())
self.name_pushbutton.setSizePolicy(sizePolicy)
self.name_pushbutton.setLayoutDirection(QtCore.Qt.RightToLeft)
self.name_pushbutton.setStyleSheet("\n"
"#name_pushbutton{\n"
"text-align: left;\n"
"padding-left: 20px; \n"
"}")
self.name_pushbutton.setAutoDefault(False)
self.name_pushbutton.setObjectName("name_pushbutton")
self.movie_gridLayout.addWidget(self.name_pushbutton, 0, 0, 1, 1)
self.verticalLayout_10.addLayout(self.movie_gridLayout)
self.retranslateUi(data)
###namebutton function
pages=[self.main_UI.movie_widget_layout,self.main_UI.movie_reviews_page]
self.name_pushbutton.clicked.connect(lambda:
self.main_UI.loadui_movie(pages, {"movieid":self.ID,"userid": self.main_UI.id}))
def retranslateUi(self, data):
_translate = QtCore.QCoreApplication.translate
self.setWindowTitle(_translate("Form", "Form"))
self.language.setText(_translate("Form", data['Language']))
self.review_num.setText(_translate("Form", "Review num: "+str(data['ReviewQuantity'])))
self.rate.setText(_translate("Form", "rate: "+ str(data['AverageRate'])))
self.genre.setText(_translate("Form", data['Genre']))
self.name_pushbutton.setText(_translate("Form", data['Title']))
def Buttoninitialize(self):
icon = QtGui.QIcon()
if self.pushButton.isChecked():
icon.addPixmap(self.checked_image, QtGui.QIcon.Normal, QtGui.QIcon.Off)
else:
icon.addPixmap(self.unchecked_image, QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton.setIcon(icon)
def changeImage(self,state):
icon = QtGui.QIcon()
if state:
icon.addPixmap(self.checked_image, QtGui.QIcon.Normal, QtGui.QIcon.Off)
else:
icon.addPixmap(self.unchecked_image, QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton.setIcon(icon)
def checkPrecondition(self, checked):
if not self.shouldToggle(checked):
self.pushButton.blockSignals(True)
self.pushButton.setChecked(not checked)
self.pushButton.blockSignals(False)
else:
self.changeImage(checked)
def shouldToggle(self,checked):
if(checked):
tmp_result = client.favorite_movie({"userid":self.main_UI.id,'movieid':self.ID})
else:
tmp_result = client.infavorite_movie({"userid":self.main_UI.id,'movieid':self.ID})
return tmp_result[0]