def __init__(self): super().__init__() QApplication.setStyle('Fusion') #窗口风格 self.sql = ConnetSQL() self.detail = movDetails() self.log = logIn() self.cf = ItemBaseCf() self.initUI()
def __init__(self): super().__init__() QApplication.setStyle('Fusion') #窗口风格 self.sql = ConnetSQL() self.detail = movDetails() self.log = logIn() self.sign = signIn() self.cf = recMov() self.modify = modifyInfo() self.initUI()
def __init__(self): super().__init__() self.initUI() self.sql = ConnetSQL()
class movDetails(QWidget): def __init__(self): super().__init__() self.initUI() self.sql = ConnetSQL() #初始化界面 def initUI(self): self.resize(550, 700) self.setWindowFlag(Qt.FramelessWindowHint) # 设置无框 palette = QPalette() #设置背景色 palette.setColor(palette.Background, QColor(178, 223, 219)) self.setPalette(palette) self.initCon() self.initLayout() self.initConsum() #添加控件 def initCon(self): self.posterLabel = QLabel(self) self.posterLabel.setScaledContents(True) self.titleLable = QLabel(self) self.englishNameLable = QLabel(self) self.directorLabel = QLabel('导演:/', self) self.starLabel = QLabel('演员:/', self) self.typeLabel = QLabel('类型:/', self) self.placeLabel = QLabel('地区:/', self) self.scoreLabel = QLabel('评分:/', self) self.yearLabel = QLabel('上映时间:/', self) self.timelongLabel = QLabel('片长:/', self) self.introLabel = QLabel('简介:/', self) self.markLine = QLineEdit(self) self.markLine.setPlaceholderText('输入评分(0-10)') self.markButton = QPushButton('√', self) self.closeButton = QPushButton('<', self) #完善控件功能 def initConsum(self): self.closeButton.clicked.connect(self.closePage) self.markButton.clicked.connect(self.markMov) #布局 def initLayout(self): self.initLabel() self.posterLabel.setGeometry(20, 70, 231, 350) self.titleLable.setGeometry(260, 60, 280, 100) self.englishNameLable.setGeometry(265, 145, 250, 30) self.directorLabel.setGeometry(265, 175, 250, 30) self.starLabel.setGeometry(265, 202, 250, 30) self.typeLabel.setGeometry(265, 235, 250, 30) self.placeLabel.setGeometry(265, 265, 250, 30) self.scoreLabel.setGeometry(265, 295, 250, 30) self.yearLabel.setGeometry(265, 325, 250, 30) self.timelongLabel.setGeometry(265, 355, 250, 30) self.introLabel.setGeometry(35, 430, 475, 250) self.markLine.setGeometry(265, 390, 125, 25) self.markButton.setGeometry(395, 390, 50, 25) self.closeButton.setGeometry(20, 20, 50, 25) #设置标签字体 def initLabel(self): fontTitle = QFont() fontTitle.setBold(True) fontTitle.setPointSize(18) self.titleLable.setFont(fontTitle) font = QFont() font.setPointSize(11) self.englishNameLable.setFont(font) self.directorLabel.setFont(font) self.starLabel.setFont(font) self.typeLabel.setFont(font) self.placeLabel.setFont(font) self.scoreLabel.setFont(font) self.yearLabel.setFont(font) self.timelongLabel.setFont(font) self.introLabel.setWordWrap(True) self.titleLable.setWordWrap(True) #改变标签内容 def resetLabe(self, id): movDet = self.sql.movID_get_details(id) #获取电影详细信息 id = int(id) poster = './poster/' + str(id) + '.jpg' self.posterLabel.setPixmap(QPixmap(poster)) title = movDet['moviename'] self.titleLable.setText("<font color=%s>%s</font>" % ('#00796B', title)) english = movDet['englishname'] self.englishNameLable.setText("<font color=%s>%s</font>" % ('#00796B', english)) dire = '导演:' + movDet['director'] self.directorLabel.setText("<font color=%s>%s</font>" % ('#4DB6AC', dire)) star = '演员:' + movDet['star'] self.starLabel.setText("<font color=%s>%s</font>" % ('#4DB6AC', star)) type = '类型:' + movDet['type1'] + ' ' + movDet['type2'] + ' ' + movDet[ 'type3'] self.typeLabel.setText("<font color=%s>%s</font>" % ('#4DB6AC', type)) place = '地区:' + movDet['place'] self.placeLabel.setText("<font color=%s>%s</font>" % ('#4DB6AC', place)) score = '评分:' + str(movDet['score']) self.scoreLabel.setText("<font color=%s>%s</font>" % ('#4DB6AC', score)) year = '上映时间:' + str(movDet['years']) self.yearLabel.setText("<font color=%s>%s</font>" % ('#4DB6AC', year)) timelong = '片长:' + str(movDet['timelong']) self.timelongLabel.setText("<font color=%s>%s</font>" % ('#4DB6AC', timelong)) intro = ' 简介:' + movDet['introduction'] self.introLabel.setText("<font color=%s>%s</font>" % ('#00897B', intro)) #显示详细页面 def showDet(self, id): self.resetLabe(id) self.show() self.raise_() #关闭页面 def closePage(self): self.close() #评分 def markMov(self): pass #判断鼠标左键是否被按下,如果按下则将flag设为True并获取当前的位置 def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.m_flag = True self.m_Position = event.globalPos() - self.pos() # 获取鼠标相对窗口的位置 event.accept() self.setCursor(QCursor(Qt.ClosedHandCursor)) # 更改鼠标图标 #判断鼠标是否移动并且左键被按下,若移动了计算移动的距离在移动窗口 def mouseMoveEvent(self, QMouseEvent): if Qt.LeftButton and self.m_flag: self.move(QMouseEvent.globalPos() - self.m_Position) # 更改窗口位置 QMouseEvent.accept() #若鼠标释放了则将flag设为False def mouseReleaseEvent(self, QMouseEvent): self.m_flag = False self.setCursor(QCursor(Qt.ArrowCursor))
def __init__(self): super().__init__() self.initUI() self.sql = ConnetSQL() self.getComment = movComment()
class modifyInfo(QWidget): def __init__(self): super().__init__() self.sql = ConnetSQL() self.initUI() def initUI(self): self.resize(480, 400) self.setWindowFlag(Qt.FramelessWindowHint) # 设置无框 palette = QPalette() #设置背景色 palette.setColor(palette.Background, QColor(0, 77, 64)) self.setPalette(palette) self.initCon() self.initLayout() self.initConsum() def initCon(self): self.closeButton = QPushButton('<', self) self.changePwdLabel = QLabel(self) self.changePwdLabel.setText("<font color=%s>%s</font>" % ('#ffffff', '修改密码')) self.changePwfLine_1 = QLineEdit(self) self.changePwfLine_1.setPlaceholderText('输入原始密码') self.changePwfLine_2 = QLineEdit(self) self.changePwfLine_2.setPlaceholderText('输入新密码') self.changePwfLine_3 = QLineEdit(self) self.changePwfLine_3.setPlaceholderText('重复新密码') self.changePwdBt = QPushButton('修改', self) # 表示密码输入 self.changePwfLine_1.setEchoMode(QLineEdit.Password) self.changePwfLine_2.setEchoMode(QLineEdit.Password) self.changePwfLine_3.setEchoMode(QLineEdit.Password) self.changePwdBt.setEnabled(False) def initLayout(self): self.changePwdBt.setGeometry(20, 20, 50, 25) self.vLayout = QVBoxLayout() self.vLayout.addStretch(5) self.vLayout.addWidget(self.changePwdLabel) self.vLayout.addStretch(1) self.vLayout.addWidget(self.changePwfLine_1) self.vLayout.addStretch(1) self.vLayout.addWidget(self.changePwfLine_2) self.vLayout.addStretch(1) self.vLayout.addWidget(self.changePwfLine_3) self.vLayout.addStretch(2) self.vLayout.addWidget(self.changePwdBt) self.vLayout.addStretch(6) self.layout = QHBoxLayout() self.layout.addStretch(1) self.layout.addLayout(self.vLayout) self.layout.addStretch(1) self.setLayout(self.layout) def initConsum(self): self.closeButton.clicked.connect(self.closePage) #文本信息改变时检查输入 self.changePwfLine_1.textChanged.connect(self.check_input) self.changePwfLine_2.textChanged.connect(self.check_input) self.changePwfLine_3.textChanged.connect(self.check_input) self.changePwdBt.clicked.connect(self.check_pwd) #检查输入 def check_input(self): #同时有输入时检查密码是否匹配,再检查输入密码是否相同,结果都为真时执行修改 if self.changePwfLine_1.text() and self.changePwfLine_2.text( ) and self.changePwfLine_3.text(): self.changePwdBt.setEnabled(True) else: self.changePwdBt.setEnabled(False) #检查插入信息正确性 def check_pwd(self): if self.sql.match_userID(self.userid, self.changePwfLine_1.text()): if self.changePwfLine_2.text() == self.changePwfLine_3.text(): self.changePwd() QMessageBox.information(self, 'Info', '密码修改成功') self.close() else: QMessageBox.critical(self, 'wrong', '两次输入密码不匹配') else: QMessageBox.critical(self, 'wrong', '原密码输入错误') self.changePwfLine_1.clear() def changePwd(self): id = self.userid pwd = self.changePwfLine_2.text() self.sql.changePwd(id, pwd) #获取用户id信息,打开修改信息界面 def modify(self, id): self.userid = id self.show() #关闭页面 def closePage(self): self.close() #判断鼠标左键是否被按下,如果按下则将flag设为True并获取当前的位置 def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.m_flag = True self.m_Position = event.globalPos() - self.pos() # 获取鼠标相对窗口的位置 event.accept() self.setCursor(QCursor(Qt.ClosedHandCursor)) # 更改鼠标图标 #判断鼠标是否移动并且左键被按下,若移动了计算移动的距离在移动窗口 def mouseMoveEvent(self, QMouseEvent): if Qt.LeftButton and self.m_flag: self.move(QMouseEvent.globalPos() - self.m_Position) # 更改窗口位置 QMouseEvent.accept() #若鼠标释放了则将flag设为False def mouseReleaseEvent(self, QMouseEvent): self.m_flag = False self.setCursor(QCursor(Qt.ArrowCursor))
class mainUI(QTabWidget): def __init__(self): super().__init__() QApplication.setStyle('Fusion') #窗口风格 self.sql = ConnetSQL() self.detail = movDetails() self.log = logIn() self.sign = signIn() self.cf = recMov() self.modify = modifyInfo() self.initUI() #初始化 def initUI(self): self.tab_class = QWidget() self.tab_homepage = QWidget() self.addTab(self.tab_class, '分类搜索') #添加窗口 self.addTab(self.tab_homepage, '个人主页') self.tab_classUI() #初始化 self.tab_homepageUI() self.setWindowTitle('电影推荐系统') self.resize(1200, 750) palette = QPalette() # 设置背景色 palette.setColor(palette.Background, QColor(0, 77, 64)) self.setPalette(palette) #分类界面 def tab_classUI(self): self.initClass() self.last_page.setEnabled(False) #初始化分类界面 def initClass(self): self.classCon() self.classLayout() self.classConsum() #添加分类界面控件 def classCon(self): self.class_search = QLineEdit() self.class_search_bt = QPushButton('搜索') self.class_search.setPlaceholderText('输入电影名称') genres = [ '剧情', '喜剧', '动作', '爱情', '科幻', '动画', '悬疑', '惊悚', '恐怖', '音乐', '传记', '奇幻', '冒险', '武侠' ] #实例化QComBox对象 self.genres_label = QLabel('类型:') self.cb_gen = QComboBox() for i in range(len(genres)): #添加选项 self.cb_gen.addItem(genres[i]) regions = ['中国大陆', '香港', '美国', '英国', '法国', '日本', '韩国'] self.region_label = QLabel('地区:') self.cb_region = QComboBox() for i in range(len(regions)): self.cb_region.addItem(regions[i]) age = ['2019年', '2010年代', '00年代', '90年代', '80年代', '70年代', '更早'] self.age_label = QLabel('年代:') self.cb_age = QComboBox() for i in range(len(age)): self.cb_age.addItem(age[i]) #图片标签 self.movPosterLabel_1 = QLabel() self.movPosterLabel_2 = QLabel() self.movPosterLabel_3 = QLabel() self.movPosterLabel_4 = QLabel() self.movPosterLabel_5 = QLabel() self.movPosterLabel_6 = QLabel() #自适应大小 self.movPosterLabel_1.setScaledContents(True) self.movPosterLabel_2.setScaledContents(True) self.movPosterLabel_3.setScaledContents(True) self.movPosterLabel_4.setScaledContents(True) self.movPosterLabel_5.setScaledContents(True) self.movPosterLabel_6.setScaledContents(True) #电影名标签 self.movTitleLabel_1 = QLabel() self.movTitleLabel_2 = QLabel() self.movTitleLabel_3 = QLabel() self.movTitleLabel_4 = QLabel() self.movTitleLabel_5 = QLabel() self.movTitleLabel_6 = QLabel() #导演 self.movDirectorLabel_1 = QLabel() self.movDirectorLabel_2 = QLabel() self.movDirectorLabel_3 = QLabel() self.movDirectorLabel_4 = QLabel() self.movDirectorLabel_5 = QLabel() self.movDirectorLabel_6 = QLabel() #电影评分 self.movScoreLabel_1 = QLabel() self.movScoreLabel_2 = QLabel() self.movScoreLabel_3 = QLabel() self.movScoreLabel_4 = QLabel() self.movScoreLabel_5 = QLabel() self.movScoreLabel_6 = QLabel() #添加按钮显示电影详细信息 self.detBt_1 = QPushButton('详细信息') self.detBt_2 = QPushButton('详细信息') self.detBt_3 = QPushButton('详细信息') self.detBt_4 = QPushButton('详细信息') self.detBt_5 = QPushButton('详细信息') self.detBt_6 = QPushButton('详细信息') #改变页数 self.last_page = QPushButton('上一页') self.next_page = QPushButton('下一页') self.transVar() #初始页面 #改变类型把信息传到标签中的变量 def transVar(self): self.setMovLabelVar() #重新获取电影信息 self.resetLabel() #获取电影信息,设置标签的值 def setMovLabelVar(self): self.match_mov() #获取匹配的电影id,再根据电影id获取详细信息放在列表 self.curMov = 0 self.evalue() #设置标签变量列表 #重置标签内容 def resetLabel(self): #海报 self.movPosterLabel_1.setPixmap(QPixmap(self.movPoster[0])) self.movPosterLabel_2.setPixmap(QPixmap(self.movPoster[1])) self.movPosterLabel_3.setPixmap(QPixmap(self.movPoster[2])) self.movPosterLabel_4.setPixmap(QPixmap(self.movPoster[3])) self.movPosterLabel_5.setPixmap(QPixmap(self.movPoster[4])) self.movPosterLabel_6.setPixmap(QPixmap(self.movPoster[5])) #片名 self.movTitleLabel_1.setText(self.movTitle[0]) self.movTitleLabel_2.setText(self.movTitle[1]) self.movTitleLabel_3.setText(self.movTitle[2]) self.movTitleLabel_4.setText(self.movTitle[3]) self.movTitleLabel_5.setText(self.movTitle[4]) self.movTitleLabel_6.setText(self.movTitle[5]) #导演 self.movDirectorLabel_1.setText(self.movDirector[0]) self.movDirectorLabel_2.setText(self.movDirector[1]) self.movDirectorLabel_3.setText(self.movDirector[2]) self.movDirectorLabel_4.setText(self.movDirector[3]) self.movDirectorLabel_5.setText(self.movDirector[4]) self.movDirectorLabel_6.setText(self.movDirector[5]) #评分 self.movScoreLabel_1.setText(self.movScore[0]) self.movScoreLabel_2.setText(self.movScore[1]) self.movScoreLabel_3.setText(self.movScore[2]) self.movScoreLabel_4.setText(self.movScore[3]) self.movScoreLabel_5.setText(self.movScore[4]) self.movScoreLabel_6.setText(self.movScore[5]) #详情按钮 if self.movTitle[0] == '': self.detBt_1.setVisible(False) else: self.detBt_1.setVisible(True) if self.movTitle[1] == '': self.detBt_2.setVisible(False) else: self.detBt_2.setVisible(True) if self.movTitle[2] == '': self.detBt_3.setVisible(False) else: self.detBt_3.setVisible(True) if self.movTitle[3] == '': self.detBt_4.setVisible(False) else: self.detBt_4.setVisible(True) if self.movTitle[4] == '': self.detBt_5.setVisible(False) else: self.detBt_5.setVisible(True) if self.movTitle[5] == '': self.detBt_6.setVisible(False) else: self.detBt_6.setVisible(True) #改变列表值 def evalue(self): self.movPoster = [] # 海报 self.movTitle = [] # 电影名称 self.movDirector = [] # 导演 self.movScore = [] # 评分 #为列表赋值 for i in range(6): if self.curMov >= self.movNum: self.movPoster.append('') self.movTitle.append('') self.movDirector.append('') self.movScore.append('') else: #获取电影详细信息 movDetails = self.sql.movID_get_details( self.get_movID[self.curMov]) poster = './poster/' + str( self.get_movID[self.curMov]) + '.jpg' title = '片名:' + movDetails['moviename'] direc = '导演:' + movDetails['director'] score = '评分:' + str(movDetails['score']) self.movPoster.append(poster) self.movTitle.append(title) self.movDirector.append(direc) self.movScore.append(score) self.curMov += 1 self.last_page.setEnabled(False) #初始化分类界面布局 def classLayout(self): #搜索栏 self.search_hbox = QHBoxLayout() self.search_hbox.addStretch(5) self.search_hbox.addWidget(self.class_search) self.search_hbox.addWidget(self.class_search_bt) self.search_hbox.addStretch(1) #贴上三个QComBox self.type_hbox = QHBoxLayout() self.type_hbox.addStretch(1) self.type_hbox.addWidget(self.genres_label) self.type_hbox.addWidget(self.cb_gen) self.type_hbox.addStretch(2) self.type_hbox.addWidget(self.region_label) self.type_hbox.addWidget(self.cb_region) self.type_hbox.addStretch(2) self.type_hbox.addWidget(self.age_label) self.type_hbox.addWidget(self.cb_age) self.type_hbox.addStretch(4) #两个hbox分别存放三部电影 self.movies_hbox1 = QHBoxLayout() self.movies_hbox2 = QHBoxLayout() #六个电影标签 self.mov_hbox1 = QHBoxLayout() self.mov_hbox2 = QHBoxLayout() self.mov_hbox3 = QHBoxLayout() self.mov_hbox4 = QHBoxLayout() self.mov_hbox5 = QHBoxLayout() self.mov_hbox6 = QHBoxLayout() #电影标签模块左右布局,海报+电影信息 #电影信息垂直布局 self.mov_info_1 = QVBoxLayout() self.mov_info_2 = QVBoxLayout() self.mov_info_3 = QVBoxLayout() self.mov_info_4 = QVBoxLayout() self.mov_info_5 = QVBoxLayout() self.mov_info_6 = QVBoxLayout() #添加电影信息到每个布局 self.mov_info_1.addWidget(self.movTitleLabel_1) self.mov_info_1.addWidget(self.movDirectorLabel_1) self.mov_info_1.addWidget(self.movScoreLabel_1) self.mov_info_1.addWidget(self.detBt_1) self.mov_info_2.addWidget(self.movTitleLabel_2) self.mov_info_2.addWidget(self.movDirectorLabel_2) self.mov_info_2.addWidget(self.movScoreLabel_2) self.mov_info_2.addWidget(self.detBt_2) self.mov_info_3.addWidget(self.movTitleLabel_3) self.mov_info_3.addWidget(self.movDirectorLabel_3) self.mov_info_3.addWidget(self.movScoreLabel_3) self.mov_info_3.addWidget(self.detBt_3) self.mov_info_4.addWidget(self.movTitleLabel_4) self.mov_info_4.addWidget(self.movDirectorLabel_4) self.mov_info_4.addWidget(self.movScoreLabel_4) self.mov_info_4.addWidget(self.detBt_4) self.mov_info_5.addWidget(self.movTitleLabel_5) self.mov_info_5.addWidget(self.movDirectorLabel_5) self.mov_info_5.addWidget(self.movScoreLabel_5) self.mov_info_5.addWidget(self.detBt_5) self.mov_info_6.addWidget(self.movTitleLabel_6) self.mov_info_6.addWidget(self.movDirectorLabel_6) self.mov_info_6.addWidget(self.movScoreLabel_6) self.mov_info_6.addWidget(self.detBt_6) #电影标签布局加入电影海报和电影信息 self.mov_hbox1.addWidget(self.movPosterLabel_1) self.mov_hbox1.addLayout(self.mov_info_1) self.mov_hbox2.addWidget(self.movPosterLabel_2) self.mov_hbox2.addLayout(self.mov_info_2) self.mov_hbox3.addWidget(self.movPosterLabel_3) self.mov_hbox3.addLayout(self.mov_info_3) self.mov_hbox4.addWidget(self.movPosterLabel_4) self.mov_hbox4.addLayout(self.mov_info_4) self.mov_hbox5.addWidget(self.movPosterLabel_5) self.mov_hbox5.addLayout(self.mov_info_5) self.mov_hbox6.addWidget(self.movPosterLabel_6) self.mov_hbox6.addLayout(self.mov_info_6) #六个电影布局添分别添加到两个movies_hbox self.movies_hbox1.addLayout(self.mov_hbox1) self.movies_hbox1.addLayout(self.mov_hbox2) self.movies_hbox1.addLayout(self.mov_hbox3) self.movies_hbox2.addLayout(self.mov_hbox4) self.movies_hbox2.addLayout(self.mov_hbox5) self.movies_hbox2.addLayout(self.mov_hbox6) #页数变换 self.page_hbox = QHBoxLayout() self.page_hbox.addStretch(3) self.page_hbox.addWidget(self.last_page) self.page_hbox.addWidget(self.next_page) self.page_hbox.addStretch(1) #贴上按分类搜索出来的电影 self.class_vbox = QVBoxLayout() self.class_vbox.addLayout(self.search_hbox) self.class_vbox.addLayout(self.type_hbox) self.class_vbox.addLayout(self.movies_hbox1) self.class_vbox.addLayout(self.movies_hbox2) self.class_vbox.addLayout(self.page_hbox) self.tab_class.setLayout(self.class_vbox) #完善分类界面控件功能 def classConsum(self): self.class_search_bt.clicked.connect( self.search_movName) #searchButton连接到earch_movName方法获取相关电影ID self.cb_gen.currentTextChanged.connect(self.match_gen) #选项发生改变时发射信号 self.cb_region.currentTextChanged.connect(self.match_reg) self.next_page.clicked.connect(self.nextPage) #点击触发槽函数 self.last_page.clicked.connect(self.lastPage) #详情 self.detBt_1.clicked.connect( lambda: self.showDet(self.get_movID[self.curMov - 6], 0)) self.detBt_2.clicked.connect( lambda: self.showDet(self.get_movID[self.curMov - 5], 0)) self.detBt_3.clicked.connect( lambda: self.showDet(self.get_movID[self.curMov - 4], 0)) self.detBt_4.clicked.connect( lambda: self.showDet(self.get_movID[self.curMov - 3], 0)) self.detBt_5.clicked.connect( lambda: self.showDet(self.get_movID[self.curMov - 2], 0)) self.detBt_6.clicked.connect( lambda: self.showDet(self.get_movID[self.curMov - 1], 0)) #重新获取类型 def match_gen(self, i): self.gen = self.cb_gen.currentText() self.transVar() #重新获取地区 def match_reg(self): self.reg = self.cb_region.currentText() self.transVar() #获取匹配QComBox所选类型的电影id列表 def match_mov(self): self.gen = self.cb_gen.currentText() self.reg = self.cb_region.currentText() gen_list = self.sql.genresSearch(self.gen) #包含所选类型的电影ID列表 reg_list = self.sql.regionSearch(self.reg) #包含所选地区类型的电影ID列表 self.get_movID = [x for x in gen_list if x in reg_list] #所选类型和地区的电影ID列表 self.movNum = len(self.get_movID) #电影数量 self.sortMov() #显示下一页 def nextPage(self): self.evalue() self.resetLabel() self.last_page.setEnabled(True) if self.curMov >= self.movNum: self.next_page.setEnabled(False) #显示上一页 def lastPage(self): self.curMov -= 12 self.evalue() self.resetLabel() self.next_page.setEnabled(True) if self.curMov < 12: self.last_page.setEnabled(False) #搜素电影 def search_movName(self): self.get_movID = self.sql.movName_get_movID( self.class_search.text()) #获取包含所搜索的名字的电影ID 列表 self.curMov = 0 self.movNum = len(self.get_movID) self.sortMov() self.evalue() self.resetLabel() self.last_page.setEnabled(False) if self.movNum <= 6: self.next_page.setEnabled(False) #显示详细页面 def showDet(self, movid, flag): self.detail.showDet(movid, flag) #将获得的电影ID列表按评分排序 def sortMov(self): scoreDict = {} for i in range(self.movNum): score = self.sql.getScore(self.get_movID[i]) scoreDict[self.get_movID[i]] = score self.get_movID = sorted(scoreDict, key=scoreDict.__getitem__, reverse=True) #获取对应movieID列表 def selecGenres(self): pass #个人主页初始化 def tab_homepageUI(self): self.homeageCon() self.homepageLayout() self.homepageConsum() self.setLabelFalse() #初始不显示海报标签等 #添加个人主页控件 def homeageCon(self): self.TitleLabel = QLabel() #给...的最佳推荐 self.lineLabel = QLabel() #分割线 self.logIn_button = QPushButton('登录') self.signIn_button = QPushButton('注册') self.userLine = QLineEdit() self.pwdLine = QLineEdit() self.pwdLine.setEchoMode(QLineEdit.Password) self.userLine.setPlaceholderText('输入账号') self.pwdLine.setPlaceholderText('输入密码') #电影海报和点击查看详情按钮 self.poster_1 = QLabel() self.poster_2 = QLabel() self.poster_3 = QLabel() self.det_bt_1 = QPushButton('查看详情') self.det_bt_2 = QPushButton('查看详情') self.det_bt_3 = QPushButton('查看详情') #翻页按钮 self.last_bt = QPushButton('上一页') self.next_bt = QPushButton('下一页') #修改信息和退出登录按钮 self.modify_bt = QPushButton('修改信息') self.signOut_bt = QPushButton('退出登录') #初始化个人主页布局 def homepageLayout(self): fontTitle = QFont() fontTitle.setBold(True) #加粗 fontTitle.setPointSize(30) #字体大小 self.TitleLabel.setFont(fontTitle) #大标签的字体 self.TitleLabel.setText("<font color=%s>%s</font>" % ('#005500', '为你推荐')) self.lineLabel.setText("<font color=%s>%s</font>" % ( '#005500', '--------------------------------------------------------------------------------------------------------------' )) self.title_hbox = QHBoxLayout() self.title_hbox.addStretch(1) self.title_hbox.addWidget(self.TitleLabel) self.title_hbox.addStretch(3) self.title_hbox.addWidget(self.modify_bt) self.title_hbox.addWidget(self.signOut_bt) self.title_hbox.addWidget(self.userLine) self.title_hbox.addWidget(self.pwdLine) self.title_hbox.addWidget(self.logIn_button) self.title_hbox.addWidget(self.signIn_button) #分别存放三部电影的信息 self.hp_mov_vbox_1 = QVBoxLayout() self.hp_mov_vbox_2 = QVBoxLayout() self.hp_mov_vbox_3 = QVBoxLayout() #电影内容 self.hp_mov_vbox_1.addStretch(1) self.hp_mov_vbox_1.addWidget(self.poster_1) self.hp_mov_vbox_1.addWidget(self.det_bt_1) self.hp_mov_vbox_1.addStretch(1) self.hp_mov_vbox_2.addStretch(1) self.hp_mov_vbox_2.addWidget(self.poster_2) self.hp_mov_vbox_2.addWidget(self.det_bt_2) self.hp_mov_vbox_2.addStretch(1) self.hp_mov_vbox_3.addStretch(1) self.hp_mov_vbox_3.addWidget(self.poster_3) self.hp_mov_vbox_3.addWidget(self.det_bt_3) self.hp_mov_vbox_3.addStretch(1) self.movHbox = QHBoxLayout() #电影添加到横向布局 self.movHbox.addStretch(1) self.movHbox.addLayout(self.hp_mov_vbox_1) self.movHbox.addStretch(1) self.movHbox.addLayout(self.hp_mov_vbox_2) self.movHbox.addStretch(1) self.movHbox.addLayout(self.hp_mov_vbox_3) self.movHbox.addStretch(1) self.hp_page_hbox = QHBoxLayout() self.hp_page_hbox.addStretch(3) self.hp_page_hbox.addWidget(self.last_bt) self.hp_page_hbox.addWidget(self.next_bt) self.hp_page_hbox.addStretch(1) self.hp_layout = QVBoxLayout() self.hp_layout.addLayout(self.title_hbox) self.hp_layout.addWidget(self.lineLabel) self.hp_layout.addStretch(1) self.hp_layout.addLayout(self.movHbox) self.hp_layout.addStretch(1) self.hp_layout.addLayout(self.hp_page_hbox) self.hp_layout.addStretch(1) self.tab_homepage.setLayout(self.hp_layout) #完善个人主页控件功能 def homepageConsum(self): self.logIn_button.clicked.connect(self.toLog) self.signIn_button.clicked.connect(self.signIn) self.det_bt_1.clicked.connect( lambda: self.showDet(self.user_rec_movid[self.curRec - 3], 1)) self.det_bt_2.clicked.connect( lambda: self.showDet(self.user_rec_movid[self.curRec - 2], 1)) self.det_bt_3.clicked.connect( lambda: self.showDet(self.user_rec_movid[self.curRec - 1], 1)) self.last_bt.clicked.connect(self.last_recPage) self.next_bt.clicked.connect(self.next_recPage) self.modify_bt.clicked.connect(self.showModify) self.signOut_bt.clicked.connect(self.signOut) #检查输入 self.userLine.textChanged.connect(self.check_input) self.pwdLine.textChanged.connect(self.check_input) #检查输入 def check_input(self): if self.userLine.text() and self.pwdLine.text(): self.logIn_button.setEnabled(True) else: self.logIn_button.setEnabled(False) #登录 def toLog(self): userid = self.userLine.text() pwd = self.pwdLine.text() if self.sql.match_userID(userid, pwd): self.user_id = userid userid = int(userid) if userid <= 200 and userid >= 1: self.recmov(userid) else: self.recToNew() else: QMessageBox.critical(self, 'wrong', '用户名或密码错误') self.userLine.clear() self.pwdLine.clear() def recToNew(self): type = self.sql.getNewType(self.user_id) self.setLabelTrue() rec = self.sql.genresSearch(type) self.user_rec_movid = self.sortRecMov(rec) self.recmovNum = 21 self.curRec = 0 self.evalueRecList() self.resetHPmov() #按评分排序,获取前21部电影 def sortRecMov(self, rec): mov = {} for i in range(len(rec)): mov[rec[i]] = self.sql.getScore(rec[i]) mov = sorted(mov, key=mov.__getitem__, reverse=True) return mov[:21] def signIn(self): self.sign.show() #将登录前标签设置不显示 def setLabelFalse(self): self.poster_1.setVisible(False) self.poster_2.setVisible(False) self.poster_3.setVisible(False) self.det_bt_1.setVisible(False) self.det_bt_2.setVisible(False) self.det_bt_3.setVisible(False) self.modify_bt.setVisible(False) self.signOut_bt.setVisible(False) self.last_bt.setVisible(False) self.next_bt.setVisible(False) self.logIn_button.setVisible(True) self.signIn_button.setVisible(True) self.userLine.setVisible(True) self.pwdLine.setVisible(True) #初始登录按钮不可用,通过文本框变化判断 self.logIn_button.setEnabled(False) #登录后显示电影信息标签 def setLabelTrue(self): self.poster_1.setVisible(True) self.poster_2.setVisible(True) self.poster_3.setVisible(True) self.det_bt_1.setVisible(True) self.det_bt_2.setVisible(True) self.det_bt_3.setVisible(True) self.last_bt.setVisible(True) self.next_bt.setVisible(True) self.modify_bt.setVisible(True) self.signOut_bt.setVisible(True) self.logIn_button.setVisible(False) self.signIn_button.setVisible(False) self.last_bt.setEnabled(False) self.userLine.setVisible(False) self.pwdLine.setVisible(False) #登录成功后login类调用该函数以显示推荐电影 def recmov(self, userid): # 根据userid,获取推荐电影列表 self.setLabelTrue() # 显示信息标签,隐藏登录注册按钮 rec = self.cf.recmov(userid) self.user_rec_movid = [] for i in range(len(rec)): self.user_rec_movid.append(rec[i][0]) self.recmovNum = len(self.user_rec_movid) # 为用户推荐的电影数量 self.curRec = 0 # 当前推荐列表索引 #重置标签列表,并更换标签的值 self.evalueRecList() self.resetHPmov() #推荐电影后重置标签内容 def resetHPmov(self): self.poster_1.setPixmap(QPixmap(self.rec_poster[0])) self.poster_2.setPixmap(QPixmap(self.rec_poster[1])) self.poster_3.setPixmap(QPixmap(self.rec_poster[2])) #重置标签内容 def evalueRecList(self): self.rec_poster = [] #存放海报标签,初始化变量 for i in range(3): if self.curRec >= self.recmovNum: self.rec_poster.append('') else: n = self.user_rec_movid[self.curRec] n = int(n) poster = './poster/' + str(n) + '.jpg' self.rec_poster.append(poster) self.curRec += 1 #上一页 def last_recPage(self): self.curRec -= 6 self.evalueRecList() self.resetHPmov() self.next_bt.setEnabled(True) if self.curRec < 6: self.last_bt.setEnabled(False) #下一页 def next_recPage(self): self.evalueRecList() self.resetHPmov() self.last_bt.setEnabled(True) #点击下一页后设置上一页按钮可使用 if self.curRec > 18: self.next_bt.setEnabled(False) def showModify(self): self.modify.modify(self.user_id) def signOut(self): self.setLabelFalse()
class logIn(QWidget): def __init__(self): super().__init__() self.initUI() self.signIn = signIn() self.sql = ConnetSQL() def initUI(self): self.resize(480,400) self.setWindowFlag(Qt.FramelessWindowHint) # 设置无框 palette = QPalette() # 设置背景色 palette.setColor(palette.Background, QColor(0, 77, 64)) self.setPalette(palette) self.initCon() self.initLayout() self.initConsum() def initCon(self): self.back_bt = QPushButton('<', self) self.user_line = QLineEdit(self) self.pwd_line = QLineEdit(self) self.login_bt = QPushButton('登录', self) self.signin_bt = QPushButton('注册', self) self.user_line.setPlaceholderText('输入账号') # 完善文本框 self.pwd_line.setPlaceholderText('输入密码') def initLayout(self): self.signin_bt.setGeometry(70,20,50,25) self.back_bt.setGeometry(20, 20, 50, 25) layout = QVBoxLayout() layout.addStretch(6) layout.addWidget(self.user_line) layout.addStretch(1) layout.addWidget(self.pwd_line) layout.addStretch(2) layout.addWidget(self.login_bt) layout.addStretch(6) hLayout = QHBoxLayout() hLayout.addStretch(1) hLayout.addLayout(layout) hLayout.addStretch(1) self.setLayout(hLayout) def initConsum(self): self.back_bt.clicked.connect(self.close) self.signin_bt.clicked.connect(self.openSignIn) #文本框的信号变化连接槽函数,判断是否两个框都有内容 self.user_line.textChanged.connect(self.check_input) self.pwd_line.textChanged.connect(self.check_input) self.login_bt.clicked.connect(self.check_login) self.pwd_line.setEchoMode(QLineEdit.Password) #表示密码输入 def openSignIn(self): self.signIn.show() #检查文本框输入 def check_input(self): if self.user_line.text() and self.pwd_line.text(): self.login_bt.setEnabled(True) else: self.login_bt.setEnabled(False) #检查用户密码是否匹配 def check_login(self): id = self.user_line.text() pwd = self.pwd_line.text() if self.sql.match_userID(id,pwd): QMessageBox.information(self,'Info','登陆成功') self.flag = True self.close() else: QMessageBox.critical(self,'wrong','账号或密码错误') self.user_line.clear() self.pwd_line.clear() # 判断鼠标左键是否被按下,如果按下则将flag设为True并获取当前的位置 def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.m_flag = True self.m_Position = event.globalPos() - self.pos() # 获取鼠标相对窗口的位置 event.accept() self.setCursor(QCursor(Qt.ClosedHandCursor)) # 更改鼠标图标 # 判断鼠标是否移动并且左键被按下,若移动了计算移动的距离在移动窗口 def mouseMoveEvent(self, QMouseEvent): if Qt.LeftButton and self.m_flag: self.move(QMouseEvent.globalPos() - self.m_Position) # 更改窗口位置 QMouseEvent.accept() # 若鼠标释放了则将flag设为False def mouseReleaseEvent(self, QMouseEvent): self.m_flag = False self.setCursor(QCursor(Qt.ArrowCursor))
class signIn(QWidget): def __init__(self): super().__init__() self.sql = ConnetSQL() self.initUI() def initUI(self): self.resize(480, 400) self.setWindowFlag(Qt.FramelessWindowHint) # 设置无框 palette = QPalette() # 设置背景色 palette.setColor(palette.Background, QColor(0, 77, 64)) self.setPalette(palette) self.initCon() self.initLayout() self.initConsum() def initCon(self): self.back_bt = QPushButton('<', self) self.user_line = QLineEdit(self) self.pwd_line = QLineEdit(self) self.pwd2_line = QLineEdit(self) self.signin_bt = QPushButton('注册', self) self.signin_bt.setEnabled(False) self.user_line.setPlaceholderText('输入账号') # 完善文本框 self.pwd_line.setPlaceholderText('输入密码') self.pwd2_line.setPlaceholderText('再次输入密码') self.pwd_line.setEchoMode(QLineEdit.Password) self.pwd2_line.setEchoMode(QLineEdit.Password) self.typeLabel = QLabel(self) self.typeLabel.setText("<font color=%s>%s</font>" % ('#ffffff', '选择喜欢的类型')) genres = [ '剧情', '喜剧', '动作', '爱情', '科幻', '动画', '悬疑', '惊悚', '恐怖', '音乐', '传记', '奇幻', '冒险', '武侠' ] self.type = '剧情' self.type_cb = QComboBox() self.type_cb.addItems(genres) def initLayout(self): self.back_bt.setGeometry(20, 20, 50, 25) layout = QVBoxLayout() layout.addStretch(6) layout.addWidget(self.user_line) layout.addStretch(1) layout.addWidget(self.pwd_line) layout.addStretch(1) layout.addWidget(self.pwd2_line) layout.addStretch(2) layout.addWidget(self.typeLabel) layout.addStretch(1) layout.addWidget(self.type_cb) layout.addStretch(2) layout.addWidget(self.signin_bt) layout.addStretch(6) hLayout = QHBoxLayout() hLayout.addStretch(1) hLayout.addLayout(layout) hLayout.addStretch(1) self.setLayout(hLayout) def initConsum(self): self.back_bt.clicked.connect(self.close) self.signin_bt.clicked.connect(self.signIn) #检查输入 self.user_line.textChanged.connect(self.check_input) self.pwd_line.textChanged.connect(self.check_input) self.pwd2_line.textChanged.connect(self.check_input) self.type_cb.currentTextChanged.connect(self.changeType) #改变喜欢类型 def changeType(self): self.type = self.type_cb.currentText() def check_input(self): if self.user_line.text() and self.pwd_line.text( ) and self.pwd2_line.text(): self.signin_bt.setEnabled(True) else: self.signin_bt.setEnabled(False) def signIn(self): id = self.user_line.text() pwd_1 = self.pwd_line.text() pwd_2 = self.pwd2_line.text() if self.sql.isExistUserID(id): QMessageBox.critical(self, 'wrong', '用户名已存在') self.user_line.clear() else: if pwd_1 == pwd_2: self.sql.signIn(id, pwd_2, self.type) QMessageBox.information(self, 'info', '注册成功') self.close() else: QMessageBox.critical(self, 'wrong', '两次密码输入不一致') self.pwd_line.clear() self.pwd2_line.clear() # 判断鼠标左键是否被按下,如果按下则将flag设为True并获取当前的位置 def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.m_flag = True self.m_Position = event.globalPos() - self.pos() # 获取鼠标相对窗口的位置 event.accept() self.setCursor(QCursor(Qt.ClosedHandCursor)) # 更改鼠标图标 # 判断鼠标是否移动并且左键被按下,若移动了计算移动的距离在移动窗口 def mouseMoveEvent(self, QMouseEvent): if Qt.LeftButton and self.m_flag: self.move(QMouseEvent.globalPos() - self.m_Position) # 更改窗口位置 QMouseEvent.accept() # 若鼠标释放了则将flag设为False def mouseReleaseEvent(self, QMouseEvent): self.m_flag = False self.setCursor(QCursor(Qt.ArrowCursor))
class movComment(QWidget): def __init__(self): super().__init__() self.sql = ConnetSQL() self.initUI() def initUI(self): self.resize(550, 700) self.setWindowFlag(Qt.FramelessWindowHint) # 设置无框 palette = QPalette() #设置背景色 palette.setColor(palette.Background, QColor(178, 223, 219)) self.setPalette(palette) self.initCon() self.initLayout() self.initConsum() def initCon(self): self.comment_1 = QLabel(self) self.comment_2 = QLabel(self) self.comment_3 = QLabel(self) self.comment_4 = QLabel(self) self.comment_5 = QLabel(self) self.title = QLabel(self) self.setTitleFont() self.closeButton = QPushButton('<', self) self.lastPage = QPushButton('<前页', self) self.nextPage = QPushButton('后页>', self) self.lastPage.setEnabled(False) def initLayout(self): self.vLayout = QVBoxLayout() self.vLayout.addStretch(1) self.vLayout.addWidget(self.title) self.vLayout.addStretch(1) self.vLayout.addWidget(self.comment_1) self.vLayout.addStretch(1) self.vLayout.addWidget(self.comment_2) self.vLayout.addStretch(1) self.vLayout.addWidget(self.comment_3) self.vLayout.addStretch(1) self.vLayout.addWidget(self.comment_4) self.vLayout.addStretch(1) self.vLayout.addWidget(self.comment_5) self.vLayout.addStretch(2) self.setLayout(self.vLayout) self.comment_1.setWordWrap(True) self.comment_2.setWordWrap(True) self.comment_3.setWordWrap(True) self.comment_4.setWordWrap(True) self.comment_5.setWordWrap(True) self.closeButton.setGeometry(20, 20, 50, 25) self.lastPage.setGeometry(400, 650, 50, 25) self.nextPage.setGeometry(455, 650, 50, 25) def initConsum(self): self.closeButton.clicked.connect(self.close) self.nextPage.clicked.connect(self.next) self.lastPage.clicked.connect(self.last) #后页 def next(self): self.lastPage.setEnabled(True) self.nextPage.setEnabled(False) self.setComment(5) def last(self): self.lastPage.setEnabled(False) self.nextPage.setEnabled(True) self.setComment(0) #设置标签变量 def setComment(self, flag): if len(self.comments) == 10: self.title.setText("<font color=%s>%s</font>" % ('#00897B', '电影短评')) self.comment_1.setText("<font color=%s>%s</font>" % ('#00897B', self.comments[flag])) self.comment_2.setText("<font color=%s>%s</font>" % ('#00897B', self.comments[flag + 1])) self.comment_3.setText("<font color=%s>%s</font>" % ('#00897B', self.comments[flag + 2])) self.comment_4.setText("<font color=%s>%s</font>" % ('#00897B', self.comments[flag + 3])) self.comment_5.setText("<font color=%s>%s</font>" % ('#00897B', self.comments[flag + 4])) else: self.comment_1.setText('') self.comment_2.setText('') self.comment_3.setText('') self.comment_4.setText('') self.comment_5.setText('') #字体 def setTitleFont(self): titleFont = QFont() titleFont.setBold(True) titleFont.setPointSize(18) self.title.setFont(titleFont) #获取电影id显示评论 def getComment(self, id): self.comments = self.sql.getComment(id) #获取评论列表 self.setComment(0) #设置标签变量 self.show() def closePage(self): self.close() #判断鼠标左键是否被按下,如果按下则将flag设为True并获取当前的位置 def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.m_flag = True self.m_Position = event.globalPos() - self.pos() # 获取鼠标相对窗口的位置 event.accept() self.setCursor(QCursor(Qt.ClosedHandCursor)) # 更改鼠标图标 #判断鼠标是否移动并且左键被按下,若移动了计算移动的距离在移动窗口 def mouseMoveEvent(self, QMouseEvent): if Qt.LeftButton and self.m_flag: self.move(QMouseEvent.globalPos() - self.m_Position) # 更改窗口位置 QMouseEvent.accept() #若鼠标释放了则将flag设为False def mouseReleaseEvent(self, QMouseEvent): self.m_flag = False self.setCursor(QCursor(Qt.ArrowCursor))