Commit 4db98d18 authored by 曹高翔's avatar 曹高翔
Browse files

Merge remote-tracking branch 'origin/gui-master' into gui-master

parents b547fb96 54035a89
......@@ -14,7 +14,9 @@ Color = {
'green': QColor(80, 160, 30),
'red': QColor(160, 0, 30),
'white': QColor(255, 255, 255),
'disabled': QColor(120, 120, 120)
'disabled': QColor(120, 120, 120),
'purple': QColor(128, 0, 128),
'darkblue': QColor(10, 40, 120)
}
Palette = {}
......@@ -23,6 +25,8 @@ Palette[QPalette.Text] = {
"green": QPalette(),
"red": QPalette(),
"gray": QPalette(),
'purple': QPalette(),
'darkblue': QPalette()
}
Palette[QPalette.Window] = {
......@@ -70,6 +74,20 @@ Palette[QPalette.Text]['gray'].setBrush(QPalette.Inactive, QPalette.Text, grayBr
grayBrush.setColor(Color['disabled'])
Palette[QPalette.Text]['gray'].setBrush(QPalette.Disabled, QPalette.Text, grayBrush)
purpleBrush = QBrush(Color['purple'])
purpleBrush.setStyle(Qt.SolidPattern)
Palette[QPalette.Text]['purple'].setBrush(QPalette.Active, QPalette.Text, purpleBrush)
Palette[QPalette.Text]['purple'].setBrush(QPalette.Inactive, QPalette.Text, purpleBrush)
purpleBrush.setColor(Color['disabled'])
Palette[QPalette.Text]['purple'].setBrush(QPalette.Disabled, QPalette.Text, purpleBrush)
darkblueBrush = QBrush(Color['darkblue'])
darkblueBrush.setStyle(Qt.SolidPattern)
Palette[QPalette.Text]['darkblue'].setBrush(QPalette.Active, QPalette.Text, darkblueBrush)
Palette[QPalette.Text]['darkblue'].setBrush(QPalette.Inactive, QPalette.Text, darkblueBrush)
darkblueBrush.setColor(Color['disabled'])
Palette[QPalette.Text]['darkblue'].setBrush(QPalette.Disabled, QPalette.Text, darkblueBrush)
class MyObject(QLabel):
defaultColor = Color['white']
hoverColor = QColor(227, 240, 255)
......@@ -315,3 +333,9 @@ else:
NewPushButton = _NewPushButton
NewProgressBar = _NewProgressBar
def ErrorDisplay(error, _ErrorTranslate, knownErrorInfo: str = "错误", unknownErrorInfo: str = "未知错误"):
errorTranslate = _ErrorTranslate(error)
if errorTranslate:
QMessageBox.critical(None, knownErrorInfo, errorTranslate, QMessageBox.Ok)
else:
QMessageBox.critical(None, unknownErrorInfo, str(error), QMessageBox.Ok)
......@@ -4,10 +4,10 @@ from PyQt5.QtWidgets import QMessageBox, QLineEdit
from loginWindow import Ui_windowLogin
from codiaclient import report_var as reportVar
from codiaclient import report_var
from codiaclient.network import *
from codiaclient.network import _acquire_verification as AcquireVerification
from codiaclient.report import Error as codiaError, error_translate as ErrorTranslate
from codiaclient.network import _acquire_verification as _AcquireVerification
from codiaclient.report import Error as codiaError, error_translate
from codiaclient.utils import cookie_decrypt as Decrypt, cookie_encrypt as Encrypt
from codiaclientgui.utils import Font, Style
......@@ -25,7 +25,7 @@ def LoginInit(callback = None):
# 初始化任务,为登陆窗口信号绑定槽函数
def BeginLogin(callback = None):
QApplication.processEvents()
reportVar["allow_error_deg"] = 1
report_var["allow_error_deg"] = 1
uiLogin.pushButtonLogin.clicked.connect(lambda: Login(callback))
# uiLogin.pushButtonLogin.setFocus()
......@@ -98,9 +98,7 @@ def Login(callback = None):
uiLogin.progressBarLogin.setValue(0)
uiLogin.progressBarLogin.show()
def ErrorRecv(e: codiaError):
errorTranslate = ErrorTranslate(e)
if errorTranslate: QMessageBox.critical(None, "登录失败", errorTranslate, QMessageBox.Ok)
else: QMessageBox.critical(None, "未知错误", str(e), QMessageBox.Ok)
ErrorDisplay(e, error_translate, "登录失败")
uiLogin.progressBarLogin.hide()
uiLogin.pushButtonLogin.setEnabled(True)
uiLogin.pushButtonLoginGoReset.setEnabled(True)
......@@ -142,12 +140,7 @@ def AcquireVerification():
try:
res = _AcquireVerification(uiLogin.lineEditResetAccount.text())[1]
except codiaError as e:
errorTranslate = ErrorTranslate(e)
if errorTranslate:
QMessageBox.critical(None, "错误", errorTranslate, QMessageBox.Ok)
else:
QMessageBox.critical(None, "未知错误", str(e), QMessageBox.Ok)
raise
ErrorDisplay(e, error_translate)
else:
if not res:
QMessageBox.critical(None, "错误", "验证码获取失败, 请重新获取。", QMessageBox.Ok)
......@@ -192,12 +185,7 @@ def Register():
res = register(username = uiLogin.lineEditRegisterUsername.text(), passwd = uiLogin.lineEditRegisterPassword.text(),
email = uiLogin.lineEditRegisterUserphone.text())
except codiaError as e:
errorTranslate = ErrorTranslate(e)
if errorTranslate:
QMessageBox.critical(None, "注册失败", errorTranslate, QMessageBox.Ok)
else:
QMessageBox.critical(None, "未知错误", str(e), QMessageBox.Ok)
raise
ErrorDisplay(e, error_translate, "注册失败")
else:
if not res:
QMessageBox.critical(None, "注册失败", "注册失败,请重试。", QMessageBox.Ok)
......@@ -226,12 +214,7 @@ def Reset():
passwd = uiLogin.lineEditResetNewPassword.text(),
passwordconfirm = uiLogin.lineEditResetCheckNewPassword.text())
except codiaError as e:
errorTranslate = ErrorTranslate(e)
if errorTranslate:
QMessageBox.critical(None, "错误", errorTranslate, QMessageBox.Ok)
else:
QMessageBox.critical(None, "未知错误", str(e), QMessageBox.Ok)
raise
ErrorDisplay(e, error_translate)
else:
QMessageBox.information(None, "成功", "密码重置成功。", QMessageBox.Ok)
ResetReturn()
......
......@@ -13,7 +13,7 @@ from codiaclient.network import get_pack, show_pack, start_pack, logined, get_ex
from codiaclient.network import submit,get_data
from codiaclient.report import Error as codiaError, error_translate
from codiaclient.requests import variables as requests_var
from codiaclientgui.utils import QPalette, Font, Palette, Style, Color
from codiaclientgui.utils import QPalette, Font, Palette, Style, Color, ErrorDisplay
from mainWindow import Ui_windowMain
variables = {
......@@ -27,7 +27,7 @@ variables = {
"exerciseInfo": None
}
translation = {
displayLanguage = {
'CPP': 'C++',
'C': 'C',
'JAVA': 'Java',
......@@ -40,6 +40,7 @@ translation = {
'runtime error': '运行时错误',
"": '未知错误'
}
dataLanguage = {val: key for key, val in displayLanguage.items()}
# 获取题包内容信息的网络通信
class _ShowPack(QThread):
......@@ -90,11 +91,7 @@ def frameExerciseInit():
def ErrorRecv(e: codiaError):
global frameExerciseInitWorking
errorTranslate = error_translate(e)
if errorTranslate:
QMessageBox.critical(None, "获取失败", errorTranslate, QMessageBox.Ok)
else:
QMessageBox.critical(None, "未知错误", str(e), QMessageBox.Ok)
ErrorDisplay(e, error_translate, "获取失败")
uiMain.progressBarPack.hide()
frameExerciseInitWorking = False
......@@ -146,29 +143,30 @@ def AddItemToQuestionList(data: dict):
def GetExerciseWidget(data: dict):
if data['viewerStatus']['passedCount'] > 0:
label_status = QLabel('已通过')
label_status.setPalette(Palette[QPalette.Text]['green'])
labelExerciseStatus = QLabel('已通过')
labelExerciseStatus.setPalette(Palette[QPalette.Text]['green'])
else:
label_status = QLabel('未通过')
label_status.setPalette(Palette[QPalette.Text]['red'])
label_name = QLabel(str(data['title']))
label_passed = QLabel(f"通过数:{data['viewerStatus']['passedCount']}")
label_submit = QLabel(f"提交数:{data['viewerStatus']['totalCount']}")
layout_main = QHBoxLayout()
layout_right = QVBoxLayout()
layout_main.addWidget(label_status)
layout_main.addWidget(label_name)
layout_right.addWidget(label_submit)
layout_right.addWidget(label_passed)
layout_main.addLayout(layout_right)
layout_main.setStretchFactor(label_status, 1)
layout_main.setStretchFactor(label_name, 3)
layout_main.setStretchFactor(layout_right, 2)
labelExerciseStatus = QLabel('未通过')
labelExerciseStatus.setPalette(Palette[QPalette.Text]['red'])
labelExerciseTitle = QLabel(str(data['title']))
labelExercisePassed = QLabel(f"通过数:{data['viewerStatus']['passedCount']}")
labelExerciseSubmit = QLabel(f"提交数:{data['viewerStatus']['totalCount']}")
layoutExerciseMain = QHBoxLayout()
layoutExerciseRight = QVBoxLayout()
layoutExerciseRight.addWidget(labelExerciseSubmit)
layoutExerciseRight.addWidget(labelExercisePassed)
layoutExerciseMain.addWidget(labelExerciseStatus)
layoutExerciseMain.addWidget(labelExerciseTitle)
layoutExerciseMain.addLayout(layoutExerciseRight)
labelExerciseStatus.setAlignment(Qt.AlignCenter)
layoutExerciseMain.setStretchFactor(labelExerciseStatus, 1)
layoutExerciseMain.setStretchFactor(labelExerciseTitle, 5)
layoutExerciseMain.setStretchFactor(layoutExerciseRight, 3)
widget = QWidget()
widget.setLayout(layout_main)
widget.setLayout(layoutExerciseMain)
return widget
......@@ -196,11 +194,7 @@ def BeginPack():
try:
start_pack(requests_var["p"])
except codiaError as e:
errorTranslate = error_translate(e)
if errorTranslate:
QMessageBox.critical(None, "错误", errorTranslate, QMessageBox.Ok)
else:
QMessageBox.critical(None, "未知错误", str(e), QMessageBox.Ok)
ErrorDisplay(e, error_translate)
else:
QMessageBox.information(None, "消息", "成功开始题包", QMessageBox.Ok)
uiMain.pushButtonExerciseBegin.hide()
......@@ -303,7 +297,7 @@ def frameQuestionInit():
str(questionInfo['viewerStatus']['passedCount']) + '/' +
str(questionInfo['viewerStatus']['totalCount']))
uiMain.comboBoxLanguage.clear()
languages = [translation[lan] for lan in variables['exerciseInfo']['supportedLanguages']]
languages = [displayLanguage[lan] for lan in variables['exerciseInfo']['supportedLanguages']]
uiMain.comboBoxLanguage.addItems(languages)
uiMain.labelSubmitStatus.setText(uiMain.labelQuestionStatus.text())
uiMain.textEditSubmit.setText(variables['exerciseInfo']['codeSnippet'])
......@@ -314,11 +308,7 @@ def frameQuestionInit():
def ErrorRecv(e: codiaError):
global frameQuestionInitWorking
errorTranslate = error_translate(e)
if errorTranslate:
QMessageBox.critical(None, "获取失败", errorTranslate, QMessageBox.Ok)
else:
QMessageBox.critical(None, "未知错误", str(e), QMessageBox.Ok)
ErrorDisplay(e, error_translate, "获取失败")
uiMain.progressBarExercise.hide()
frameQuestionInitWorking = False
......@@ -456,15 +446,10 @@ def SubmitReturn():
def SubmitCode(lang: str, code: str):
reverseTranslation = {val: key for key, val in translation.items()}
try:
submit_result = submit(requests_var['e'], requests_var['p'], reverseTranslation[lang], code)
submit_result = submit(requests_var['e'], requests_var['p'], dataLanguage[lang], code)
except codiaError as e:
rev = error_translate(e)
if rev:
QMessageBox.critical(None, '提交失败', rev, QMessageBox.Ok)
else:
QMessageBox.critical(None, '提交失败', '未知错误', QMessageBox.Ok)
ErrorDisplay(e, error_translate, "提交失败")
else:
if submit_result:
QMessageBox.information(None, '提交成功', '提交成功,请在历史记录中查看评测结果', QMessageBox.Ok)
......@@ -475,7 +460,7 @@ def SubmitCode(lang: str, code: str):
def SubmitInit():
languages = [translation[lan] for lan in variables['exerciseInfo']['supportedLanguages']]
languages = [displayLanguage[lang] for lang in variables['exerciseInfo']['supportedLanguages']]
uiMain.comboBoxLanguageSubmit.clear()
uiMain.comboBoxLanguageSubmit.addItems(languages)
uiMain.frameQuestion.hide()
......@@ -565,11 +550,7 @@ def GetPage(before=None, after=None):
UpdatePage()
def ErrorRecv(e: codiaError):
errorTranslate = error_translate(e)
if errorTranslate:
QMessageBox.critical(None, "获取失败", errorTranslate, QMessageBox.Ok)
else:
QMessageBox.critical(None, "未知错误", str(e), QMessageBox.Ok)
ErrorDisplay(e, error_translate, "获取失败")
uiMain.progressBarPack.hide()
try:
UpdatePage()
......@@ -581,7 +562,7 @@ def GetPage(before=None, after=None):
def GetPackWidget(data: dict):
widget = QWidget()
layoutPackmain = QHBoxLayout()
layoutPackMain = QHBoxLayout()
layoutPackRight = QVBoxLayout()
layoutPackRightUp = QHBoxLayout()
layoutPackRightDown = QHBoxLayout()
......@@ -642,12 +623,12 @@ def GetPackWidget(data: dict):
layoutPackRight.setStretchFactor(layoutPackRightDown, 8)
labelPackFinish.setAlignment(Qt.AlignCenter)
layoutPackmain.addWidget(labelPackFinish)
layoutPackmain.addLayout(layoutPackRight)
layoutPackmain.setStretchFactor(labelPackFinish, 1)
layoutPackmain.setStretchFactor(layoutPackRight, 8)
layoutPackMain.addWidget(labelPackFinish)
layoutPackMain.addLayout(layoutPackRight)
layoutPackMain.setStretchFactor(labelPackFinish, 1)
layoutPackMain.setStretchFactor(layoutPackRight, 8)
widget.setLayout(layoutPackmain)
widget.setLayout(layoutPackMain)
return widget
......
......@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'mainWindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
# Created by: PyQt5 UI code generator 5.15.2
#
# 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.
......@@ -142,7 +142,7 @@ class Ui_windowMain(object):
self.pushButtonSubmitBack = NewPushButton(self.frameSubmit)
self.pushButtonSubmitBack.setGeometry(QtCore.QRect(890, 630, 120, 32))
self.pushButtonSubmitBack.setObjectName("pushButtonSubmitBack")
self.pushButtonReadFromFile = QtWidgets.QPushButton(self.frameSubmit)
self.pushButtonReadFromFile = NewPushButton(self.frameSubmit)
self.pushButtonReadFromFile.setGeometry(QtCore.QRect(690, 630, 120, 32))
self.pushButtonReadFromFile.setObjectName("pushButtonReadFromFile")
self.frameHistory = QtWidgets.QFrame(self.centralwidget)
......@@ -157,7 +157,7 @@ class Ui_windowMain(object):
self.frameSubmit.raise_()
windowMain.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(windowMain)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1080, 24))
self.menubar.setGeometry(QtCore.QRect(0, 0, 1080, 26))
self.menubar.setObjectName("menubar")
windowMain.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(windowMain)
......
......@@ -471,7 +471,7 @@
<string>返回</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonReadFromFile">
<widget class="NewPushButton" name="pushButtonReadFromFile">
<property name="geometry">
<rect>
<x>690</x>
......@@ -513,7 +513,7 @@
<x>0</x>
<y>0</y>
<width>1080</width>
<height>24</height>
<height>26</height>
</rect>
</property>
</widget>
......
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