Commit 3ac382d4 authored by Zheng Yile's avatar Zheng Yile
Browse files

增加获取历史记录的多线程和进度条

parent 9bedc96c
......@@ -48,7 +48,7 @@ toDisplay = {
toData = {val: key for key, val in toDisplay.items()}
class MyThread(QThread):
infoSignal = pyqtSignal(dict)
infoSignal = pyqtSignal([dict], [list])
errorSignal = pyqtSignal(codiaError)
def __init__(self, *args, RunMethod, **kargs):
......@@ -66,7 +66,7 @@ class MyThread(QThread):
except codiaError as e:
self.errorSignal.emit(e)
else:
self.infoSignal.emit(self.Info)
self.infoSignal[type(self.Info)].emit(self.Info)
# 获取题包内容信息的多线程
......@@ -308,12 +308,14 @@ def BeginMain(callback=None):
uiMain.progressBarPack.hide()
uiMain.progressBarExercise.hide()
uiMain.progressBarSubmit.hide()
uiMain.progressBarHistory.hide()
uiMain.frameQuestion.hide()
uiMain.frameHistory.hide()
uiMain.frameSubmit.hide()
uiMain.progressBarPack.setStyleSheet(Style["progressBar"])
uiMain.progressBarExercise.setStyleSheet(Style["progressBar"])
uiMain.progressBarSubmit.setStyleSheet(Style["progressBar"])
uiMain.progressBarHistory.setStyleSheet(Style["progressBar"])
uiMain.textEditSubmit.setTabStopWidth(uiMain.textEditSubmit.font().pointSize() * 2)
codeFont = QFont()
codeFont.setFamily('Consolas')
......@@ -352,23 +354,37 @@ def HistoryReturn():
uiMain.frameHistory.hide()
uiMain.frameQuestion.show()
def GetHistory(eid, pid, cnt, InfoRecv=lambda: None, ErrorRecv=lambda: None):
global threadGetHistory # extremely essential!
threadGetHistory = MyThread(RunMethod=lambda: get_data(eid=eid, pid=pid, codecnt=cnt))
threadGetHistory.infoSignal[list].connect(InfoRecv)
threadGetHistory.errorSignal.connect(ErrorRecv)
uiMain.progressBarHistory.setValue(90)
threadGetHistory.start()
def frameHistoryInit():
totalCount = variables['exerciseListInfo'][variables['currentExerciseRow']]['viewerStatus']['totalCount']
try:
results = get_data(requests_var['e'], requests_var['p'], totalCount)
except codiaError as e:
ErrorDisplay(e, error_translate, "获取失败")
return
results.reverse()
variables['submitHistory'] = results
uiMain.progressBarHistory.setValue(0)
uiMain.listWidgetPackHistory.clear()
for data in results:
AddItemToHistoryList(data)
uiMain.progressBarHistory.show()
uiMain.frameQuestion.hide()
uiMain.frameHistory.show()
def historyInfoRecv(historyInfo):
uiMain.progressBarHistory.setValue(95)
historyInfo.reverse()
variables['submitHistory'] = historyInfo
uiMain.listWidgetPackHistory.clear()
for data in historyInfo:
AddItemToHistoryList(data)
uiMain.progressBarHistory.hide()
def ErrorRecv(e: codiaError):
ErrorDisplay(e, error_translate, "获取失败")
uiMain.progressBarHistory.hide()
GetHistory(eid=requests_var['e'], pid=requests_var['p'], cnt=totalCount, InfoRecv = historyInfoRecv, ErrorRecv=ErrorRecv)
def AddItemToHistoryList(data: dict):
item = QListWidgetItem()
......
......@@ -155,6 +155,11 @@ class Ui_windowMain(object):
self.frameHistory.setFrameShape(QtWidgets.QFrame.NoFrame)
self.frameHistory.setFrameShadow(QtWidgets.QFrame.Raised)
self.frameHistory.setObjectName("frameHistory")
self.progressBarHistory = NewProgressBar(self.frameHistory)
self.progressBarHistory.setGeometry(QtCore.QRect(180, 9, 720, 12))
self.progressBarHistory.setProperty("value", 0)
self.progressBarHistory.setTextVisible(False)
self.progressBarHistory.setObjectName("progressBarHistory")
self.listWidgetPackHistory = NewListWidget(self.frameHistory)
self.listWidgetPackHistory.setGeometry(QtCore.QRect(28, 30, 1024, 531))
self.listWidgetPackHistory.setMaximumSize(QtCore.QSize(1280, 768))
......
......@@ -516,6 +516,22 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="NewProgressBar" name="progressBarHistory">
<property name="geometry">
<rect>
<x>180</x>
<y>9</y>
<width>720</width>
<height>12</height>
</rect>
</property>
<property name="value">
<number>0</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
</widget>
<widget class="NewListWidget" name="listWidgetPackHistory">
<property name="geometry">
<rect>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment