def closeEvent(self, event): """ 重写closeEvent方法,实现dialog窗体关闭时执行一些代码 :param event: close()触发的事件 :return: None """ modelutil = ModelUtil() modelutil.inittempuser()
def create_chart(self): # 创建折线视图窗口 modelutil = ModelUtil() dataTable = modelutil.get_score(self.username) chart = QChartView(self) #获取显示器高宽 screeRect = QApplication.desktop().screenGeometry() chart.setGeometry(QtCore.QRect(screeRect)) chart.setRenderHint(QPainter.Antialiasing) # 抗锯齿 chart.raise_() # qfont=QFont() # qfont.setPointSize(34) # qfont.setPixelSize(45) chart._chart = QChart(title="考试成绩折线图") # 创建折线视图 # chart._chart.setFont(qfont) # chart.setStyleSheet( # "QChartView{border:2px}" # "QChartView{border-radius:10px}" # "QChartView{font-family:宋体}" # "QChartView{word-wrap:true}" # "QChartView{font-size:25px}" # "QChartView{padding:2px 2px}") # chart._chart.setFont(qfont) # chart._chart.setBackgroundVisible(visible=False) # 背景色透明 chart._chart.setBackgroundBrush(QBrush(QColor("#FFFFFF"))) # 改变图背景色 # 图形项默认无法接收悬停事件,可以使用QGraphicsItem的setAcceptHoverEvents()函数使图形项可以接收悬停事件。 chart._chart.setAcceptHoverEvents(True) # 4条折线的坐标值 # 执行创建折线的函数 self.create_series(dataTable, chart) chart._chart.createDefaultAxes() # 创建默认的轴 chart._chart.axisY().setTickCount(11) # y1轴设置10个刻度 chart._chart.axisY().setLabelFormat("%d") chart._chart.axisY().setRange(0, 100) # 设置y1轴范围 xnum = len(dataTable[0]) - 1 chart._chart.axisX().setTickCount(xnum) # X轴设置10个刻度 # 执行定义X轴的函数 # self.customAxisX(chart._chart) chart.setChart(chart._chart)
def __init__(self): super(mywindow,self).__init__() self.currentuser=None self.setupUi(self) self.setstyle() self.action_F.triggered.connect(self.impquefrmexl) self.action_K.triggered.connect(self.addcourse) self.action_D.triggered.connect(self.deletequestion) self.action_L.triggered.connect(self.history) self.action_word_O.triggered.connect(self.exportpaper) self.pushButton.clicked.connect(self.exam) self.pushButton_2.clicked.connect(self.traintl) self.pushButton_8.clicked.connect(self.trainyzyh) self.pushButton_7.clicked.connect(self.trainfgzd) modelutil=ModelUtil() modelutil.inittempuser()
def closeEvent(self, event): """ 重写closeEvent方法,实现dialog窗体关闭时执行一些代码 :param event: close()触发的事件 :return: None """ reply = QtWidgets.QMessageBox.question( self, '本程序', "是否要退出程序?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if reply == QtWidgets.QMessageBox.Yes: modelutil = ModelUtil() modelutil.inittempuser() event.accept() else: event.ignore()
def collecttimu(self): modelutil = ModelUtil() userinstace=modelutil.getuserinstance(self.current_username) questionid = self.questionresall[self.questionnowid][0] collect=Collects() collect.collectid=questionid collect.userid=userinstace.id save_res=modelutil.save_collect(collect) self.init_collectbutton1(save_res) modelutil.session_close()
def init_collectbutton(self): modelutil = ModelUtil() userinstace = modelutil.getuserinstance(self.current_username) questionid = self.questionresall[self.questionnowid][0] collect = Collects() collect.collectid = questionid collect.userid = userinstace.id save_res = modelutil.get_collect(collect) modelutil.session_close() if not save_res: # QMessageBox.information(self,'提示','此题已收藏') self.pushButton_6.setText('收藏') else: # QMessageBox.information(self, '提示', '此题已收藏') self.pushButton_6.setText('已收藏')
def jishuadefen(self): Session = sessionmaker(bind=engine) session = Session() yemian = "" xzyemian = '' pdyemian = '' mxzyemian = '' jdyemian = '' tihao = 1 xzdaduitishu = 0 pddaduitishu = 0 mxzdaduitishu = 0 jddaduitishu = 0 for que in self.questionidlist: usrans = session.query(tempuserans).filter( tempuserans.question_id == que[0]).first() # rightans=session.query(question).filter(and_(question.id==usrans.question_id),(question.questionType=='xz')).first() rightans = session.query(question).filter( question.id == que[0]).first() if rightans.questionType == 'xz': useranss = '' if usrans is not None: if rightans.answer == usrans.userans: xzdaduitishu += 1 useranss = usrans.userans xzyemian += str( tihao ) + ':' + rightans.content + '正确答案(%s)' % rightans.answer + '我的答案(%s)' % useranss + '\n' xzyemian = "<font color='black'>" + xzyemian + "</font><br>" else: xzyemian += str( tihao ) + ':' + rightans.content + '正确答案(%s)' % rightans.answer + '我的答案(%s)' % useranss + '\n' xzyemian = "<font color='red'>" + xzyemian + "</font><br>" else: xzyemian += str( tihao ) + ':' + rightans.content + '正确答案(%s)' % rightans.answer + '我的答案(%s)' % useranss + '\n' xzyemian = "<font color='red'>" + xzyemian + "</font><br>" xzyemian += "<font color='black'>" + rightans.choice_a + "</font><br>" xzyemian += "<font color='black'>" + rightans.choice_b + "</font><br>" xzyemian += "<font color='black'>" + rightans.choice_c + "</font><br>" xzyemian += "<font color='black'>" + rightans.choice_d + "</font><br>" xzyemian += "<font color='black'>" + rightans.choice_e + "</font><br>" xzyemian += "<font color='black'>" + rightans.choice_f + "</font><br>" elif rightans.questionType == 'pd': useranss = '' if usrans is not None: if rightans.answer == usrans.userans: pddaduitishu += 1 useranss = usrans.userans pdyemian += str( tihao ) + ':' + rightans.content + '正确答案(%s)' % rightans.answer + '我的答案(%s)' % useranss + '\n' pdyemian = "<font color='black'>" + pdyemian + "</font><br>" else: pdyemian += str( tihao ) + ':' + rightans.content + '正确答案(%s)' % rightans.answer + '我的答案(%s)' % useranss + '\n' pdyemian = "<font color='red'>" + pdyemian + "</font><br>" else: pdyemian += str( tihao ) + ':' + rightans.content + '正确答案(%s)' % rightans.answer + '我的答案(%s)' % useranss + '\n' pdyemian = "<font color='red'>" + pdyemian + "</font><br>" elif rightans.questionType == 'mxz': useranss = '' if usrans is not None: if rightans.answer == usrans.userans: mxzdaduitishu += 1 useranss = usrans.userans mxzyemian += str( tihao ) + ':' + rightans.content + '正确答案(%s)' % rightans.answer + '我的答案(%s)' % useranss + '\n' mxzyemian = "<font color='black'>" + mxzyemian + "</font><br>" else: mxzyemian += str( tihao ) + ':' + rightans.content + '正确答案(%s)' % rightans.answer + '我的答案(%s)' % useranss + '\n' mxzyemian = "<font color='red'>" + mxzyemian + "</font><br>" else: mxzyemian += str( tihao ) + ':' + rightans.content + '正确答案(%s)' % rightans.answer + '我的答案(%s)' % useranss + '\n' mxzyemian = "<font color='red'>" + mxzyemian + "</font><br>" mxzyemian += "<font color='black'>" + rightans.choice_a + "</font><br>" mxzyemian += "<font color='black'>" + rightans.choice_b + "</font><br>" mxzyemian += "<font color='black'>" + rightans.choice_c + "</font><br>" mxzyemian += "<font color='black'>" + rightans.choice_d + "</font><br>" mxzyemian += "<font color='black'>" + rightans.choice_e + "</font><br>" mxzyemian += "<font color='black'>" + rightans.choice_f + "</font><br>" elif rightans.questionType == 'jd': useranss = '' if usrans is not None: if rightans.answer == usrans.userans: jddaduitishu += 1 useranss = usrans.userans jdyemian += str( tihao ) + rightans.content + '正确答案(%s)' % rightans.answer + '我的答案(%s)' % useranss + '\n' jdyemian = "<font color='black'>" + jdyemian + "</font><br>" else: jdyemian += str( tihao ) + ':' + rightans.content + '正确答案(%s)' % rightans.answer + '我的答案(%s)' % useranss + '\n' jdyemian = "<font color='red'>" + jdyemian + "</font><br>" else: jdyemian += str( tihao ) + ':' + rightans.content + '正确答案(%s)' % rightans.answer + '我的答案(%s)' % useranss + '\n' jdyemian = "<font color='red'>" + jdyemian + "</font><br>" # yemian+=rightans.content+'正确答案(%s)'% rightans.answer+'我的答案(%s)'%usrans.userans+'\n' # yemian+=question.choice_a+'\n' # yemian += question.choice_a + '\n' # yemian += question.choice_a + '\n' # yemian += question.choice_a + '\n' tihao += 1 from model.question import PaperList paperset = session.query(PaperList).filter( PaperList.course_name == self.course).first() xzfen = paperset.single_choice_score pdfen = paperset.judgment_score mxzfen = paperset.multiple_choice_score jdfen = paperset.jd_choice_score xzdaduitishufen = xzfen * xzdaduitishu pddaduitishufen = pdfen * pddaduitishu mxzdaduitishufen = mxzfen * mxzdaduitishu jddaduitishufen = jdfen * jddaduitishu zhongfen = xzdaduitishufen + pddaduitishufen + mxzdaduitishufen + jddaduitishufen zhongfenstr = "<font size='6' color='red'>" + '总分:' + str( zhongfen) + "</font><br>" xzcuotistr = "<font size='4' color='red'>" + '选择题数:%s ' % paperset.single_choice_num + '答对题数:%s' % xzdaduitishu + "</font><br>" pdcuotistr = "<font size='4' color='red'>" + '选择题数:%s ' % paperset.judgment + '答对题数:%s' % pddaduitishu + "</font><br>" mxzcuotistr = "<font size='4' color='red'>" + '选择题数:%s ' % paperset.multiple_choice_num + '答对题数:%s' % mxzdaduitishu + "</font><br>" jdcuotistr = "<font size='4' color='red'>" + '选择题数:%s ' % paperset.jd_choice_num + '答对题数:%s' % jddaduitishu + "</font><br>" yemian = zhongfenstr + xzcuotistr + xzyemian + pdcuotistr + pdyemian + mxzcuotistr + mxzyemian + jdcuotistr + jdyemian # yemian =zhongfenstr+ xzyemian + pdyemian + mxzyemian + jdyemian # self.textBrowser.setHtml("<font color='red'>hell</font>") self.textBrowser.setHtml(yemian) session.close() #写入得分 if zhongfen > 0: modelutil = ModelUtil() modelutil.save_score(self.curentusername, zhongfen, self.course) modelutil.session_close()