Commit 014fd0d3 authored by Zheng Yile's avatar Zheng Yile
Browse files

修改变量名使其符合命名规则;修改文件结构;优化图形界面显示

parent 84f26d1f
......@@ -2,13 +2,16 @@ from datetime import datetime, timedelta
from re import search
from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QHBoxLayout, QLabel, QVBoxLayout
from PyQt5.QtWidgets import QListWidgetItem, QWidget, QListWidget
from PyQt5.QtWidgets import QMessageBox
import functionWindow
from mainWindow import Ui_windowMain
from codiaclient import net_var
from codiaclient.network import get_pack, show_pack, logined
from codiaclientgui.utils import Font, Palette
from codiaclient.network import get_pack, show_pack
variables = {
"page_number": 0,
......@@ -17,143 +20,144 @@ variables = {
"has_next": True,
}
# 打开做题界面
def MainInit(callback = None):
global windowMain
windowMain = QMainWindow()
uiMain = Ui_windowMain()
loginUserNickname = logined()[1]
verified = bool(net_var["me"]["verified"])
uiMain.setupUi(windowMain)
BeginMain(uiMain, loginUserNickname, verified)
from codiaclientgui.utils import Font
windowMain.setFont(Font["main"])
def functionWindow_init(UI: functionWindow.Ui_functionWindow, nickname = "UNDEFINED", verified=True):
windowMain.show()
callback and callback()
def BeginMain(uiMain: Ui_windowMain, nickname = "UNDEFINED", verified = True):
if verified:
status_bar_label = QLabel(f"当前用户: {nickname}")
labelStatusbarUser = QLabel(f"当前用户: {nickname}")
else:
status_bar_label = QLabel(f"当前用户: {nickname}(未验证)")
labelStatusbarUser = QLabel(f"当前用户: {nickname}(未验证)")
QMessageBox.information(None, "消息", "当前账号功能受限,请尽快完成联系方式验证。", QMessageBox.Ok)
status_bar_label.setFont(Font["status"])
UI.statusbar.addWidget(status_bar_label)
UI.pushButton_next.clicked.connect(lambda: nextPage(UI))
UI.pushButton_last.clicked.connect(lambda: previousPage(UI))
nextPage(UI)
UI.exerciseFrame.hide()
UI.packFrame.show()
def nextPage(UI: functionWindow.Ui_functionWindow):
UI.pushButton_next.setEnabled(False)
UI.pushButton_last.setEnabled(False)
try: pack_list = get_pack(before = variables['last_pack_pid'])
labelStatusbarUser.setFont(Font["status"])
uiMain.statusbar.addWidget(labelStatusbarUser)
uiMain.pushButtonPackNext.clicked.connect(lambda: NextPage(uiMain))
uiMain.pushButtonPackPrevious.clicked.connect(lambda: PreviousPage(uiMain))
NextPage(uiMain)
uiMain.frameExercise.hide()
uiMain.framePack.show()
# 在翻页后更新页面
def UpdatePage(uiMain: Ui_windowMain, packInfo):
variables["has_next"] = packInfo["pageInfo"]["hasPreviousPage"]
packList = packInfo["nodes"]
variables["last_pack_pid"] = packList[0]["id"]
variables["first_pack_pid"] = packList[-1]["id"]
uiMain.pushButtonPackNext.setEnabled(variables["has_next"])
uiMain.pushButtonPackPrevious.setEnabled(variables["page_number"] > 1)
uiMain.labelPackPage.setText("第 {} 页".format(variables["page_number"]))
for i in range(0, uiMain.listWidgetPack.count()): uiMain.listWidgetPack.takeItem(0)
for dic in packList: AddItemToPackList(uiMain.listWidgetPack, dic)
# 下一页,时间更早
def NextPage(uiMain: Ui_windowMain):
uiMain.pushButtonPackNext.setEnabled(False)
uiMain.pushButtonPackPrevious.setEnabled(False)
try: packInfo = get_pack(before = variables["last_pack_pid"])
except codiaError as e:
errorTranslate = error_translate(e)
if errorTranslate:
QMessageBox.critical(None, "获取失败", errorTranslate, QMessageBox.Ok)
else:
QMessageBox.critical(None, "未知错误", str(e), QMessageBox.Ok)
raise
if errorTranslate: QMessageBox.critical(None, "获取失败", errorTranslate, QMessageBox.Ok)
else: QMessageBox.critical(None, "未知错误", str(e), QMessageBox.Ok)
return False
variables['page_number'] += 1
variables['has_next'] = pack_list['pageInfo']['hasPreviousPage']
pack_list = pack_list['nodes']
variables['last_pack_pid'] = pack_list[0]['id']
variables['first_pack_pid'] = pack_list[-1]['id']
UI.pushButton_next.setEnabled(bool(variables['has_next']))
UI.pushButton_last.setEnabled(variables['page_number'] != 1)
UI.label_page.setText('第 {} 页'.format(variables['page_number']))
for i in range(0, UI.listWidget_packs.count()): UI.listWidget_packs.takeItem(0)
for dic in pack_list: add_item_to_pack_list(UI.listWidget_packs, dic)
def previousPage(UI: functionWindow.Ui_functionWindow):
UI.pushButton_next.setEnabled(False)
UI.pushButton_last.setEnabled(False)
try: pack_list = get_pack(after = variables['first_pack_pid'])
variables["page_number"] += 1
UpdatePage(uiMain, packInfo)
# 上一页,时间更近
def PreviousPage(uiMain: Ui_windowMain):
uiMain.pushButtonPackNext.setEnabled(False)
uiMain.pushButtonPackPrevious.setEnabled(False)
try: packInfo = get_pack(after = variables["first_pack_pid"])
except codiaError as e:
errorTranslate = error_translate(e)
if errorTranslate:
QMessageBox.critical(None, "获取失败", errorTranslate, QMessageBox.Ok)
else:
QMessageBox.critical(None, "未知错误", str(e), QMessageBox.Ok)
raise
if errorTranslate: QMessageBox.critical(None, "获取失败", errorTranslate, QMessageBox.Ok)
else: QMessageBox.critical(None, "未知错误", str(e), QMessageBox.Ok)
return False
variables['page_number'] -= 1
variables['has_next'] = pack_list['pageInfo']['hasPreviousPage']
pack_list = pack_list['nodes']
variables['last_pack_pid'] = pack_list[0]['id']
variables['first_pack_pid'] = pack_list[-1]['id']
UI.pushButton_next.setEnabled(bool(variables['has_next']))
UI.pushButton_last.setEnabled(variables['page_number'] != 1)
UI.label_page.setText('第 {} 页'.format(variables['page_number']))
for i in range(0, UI.listWidget_packs.count()): UI.listWidget_packs.takeItem(0)
for dic in pack_list: add_item_to_pack_list(UI.listWidget_packs, dic)
def get_pack_widget(data: dict):
variables["page_number"] -= 1
UpdatePage(uiMain, packInfo)
def GetPackWidget(data: dict):
widget = QWidget()
layout_main = QHBoxLayout()
layout_right = QVBoxLayout()
layout_right_up = QHBoxLayout()
layout_right_down = QHBoxLayout()
layoutPackmain = QHBoxLayout()
layoutPackRight = QVBoxLayout()
layoutPackRightUp = QHBoxLayout()
layoutPackRightDown = QHBoxLayout()
if data["codingExercises"]:
total = data["codingExercises"]["totalCount"]
has_done = data["codingExercises"]["viewerPassedCount"]
if total == has_done:
label_finish = QLabel("已完成")
label_finish.setPalette(Palette["green"])
labelPackFinish = QLabel("已完成")
labelPackFinish.setPalette(Palette["green"])
else:
label_finish = QLabel("未完成")
label_finish.setPalette(Palette["red"])
label_has_done_total = QLabel(f"已完成/总计: {has_done}/{total}")
labelPackFinish = QLabel("未完成")
labelPackFinish.setPalette(Palette["red"])
labelPackHasDoneDivTotal = QLabel(f"已完成/总计: {has_done}/{total}")
if data["due"]:
end = (datetime.strptime(search(r"^[^.]*", data["due"].replace("T", " ")).group(), "%Y-%m-%d %H:%M:%S")
+ timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S")
else:
end = "无限制"
endTime = (datetime.strptime(search(r"^[^.]*", data["due"].replace("T", " ")).group(), "%Y-%m-%d %H:%M:%S")
+ timedelta(hours = 8)).strftime("%Y-%m-%d %H:%M:%S")
else: endTime = "无限制"
if data["createdAt"]:
start = (datetime.strptime(search(r"^[^.]*", data["createdAt"].replace("T", " ")).group(),
"%Y-%m-%d %H:%M:%S")
+ timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S")
else:
start = "无限制"
beginTime = (datetime.strptime(search(r"^[^.]*", data["createdAt"].replace("T", " ")).group(), "%Y-%m-%d %H:%M:%S")
+ timedelta(hours = 8)).strftime("%Y-%m-%d %H:%M:%S")
else: beginTime = "无限制"
else:
end = ""
start = ""
label_finish = QLabel("无权限")
label_finish.setPalette(Palette["gray"])
label_has_done_total = QLabel("")
endTime = ""
beginTime = ""
labelPackFinish = QLabel("无权限")
labelPackFinish.setPalette(Palette["gray"])
labelPackHasDoneDivTotal = QLabel("")
widget.setEnabled(False)
label_name = QLabel(data["name"])
label_start = QLabel("开始时间")
label_end = QLabel("截止时间")
label_start_time = QLabel(start)
label_end_time = QLabel(end)
layout_right_up.addWidget(label_name)
layout_right_up.addWidget(label_start)
layout_right_up.addWidget(label_end)
layout_right_up.setStretchFactor(label_name, 4)
layout_right_up.setStretchFactor(label_start, 4)
layout_right_up.setStretchFactor(label_end, 4)
layout_right_down.addWidget(label_has_done_total)
layout_right_down.addWidget(label_start_time)
layout_right_down.addWidget(label_end_time)
layout_right_down.setStretchFactor(label_has_done_total, 4)
layout_right_down.setStretchFactor(label_start_time, 4)
layout_right_down.setStretchFactor(label_end_time, 4)
layout_right.addLayout(layout_right_up)
layout_right.addLayout(layout_right_down)
layout_right.setStretchFactor(layout_right_up, 12)
layout_right.setStretchFactor(layout_right_down, 12)
layout_main.addWidget(label_finish)
layout_main.addLayout(layout_right)
layout_main.setStretchFactor(label_finish, 1)
layout_main.setStretchFactor(layout_right, 12)
widget.setLayout(layout_main)
labelPackName = QLabel(data["name"])
labelPackBegin = QLabel("开始时间")
labelPackBeginTime = QLabel(beginTime)
labelPackEnd = QLabel("截止时间")
labelPackEndTime = QLabel(endTime)
layoutPackRightUp.addWidget(labelPackName)
layoutPackRightUp.addWidget(labelPackBegin)
layoutPackRightUp.addWidget(labelPackEnd)
layoutPackRightUp.setStretchFactor(labelPackName, 4)
layoutPackRightUp.setStretchFactor(labelPackBegin, 4)
layoutPackRightUp.setStretchFactor(labelPackEnd, 4)
layoutPackRightDown.addWidget(labelPackHasDoneDivTotal)
layoutPackRightDown.addWidget(labelPackBeginTime)
layoutPackRightDown.addWidget(labelPackEndTime)
layoutPackRightDown.setStretchFactor(labelPackHasDoneDivTotal, 4)
layoutPackRightDown.setStretchFactor(labelPackBeginTime, 4)
layoutPackRightDown.setStretchFactor(labelPackEndTime, 4)
layoutPackRight.addLayout(layoutPackRightUp)
layoutPackRight.addLayout(layoutPackRightDown)
layoutPackRight.setStretchFactor(layoutPackRightUp, 12)
layoutPackRight.setStretchFactor(layoutPackRightDown, 12)
layoutPackmain.addWidget(labelPackFinish)
layoutPackmain.addLayout(layoutPackRight)
layoutPackmain.setStretchFactor(labelPackFinish, 1)
layoutPackmain.setStretchFactor(layoutPackRight, 12)
widget.setLayout(layoutPackmain)
return widget
def add_item_to_pack_list(pack_list: QListWidget, data: dict):
def AddItemToPackList(packList: QListWidget, data: dict):
item = QListWidgetItem()
item.setSizeHint(QSize(651, 68))
widget = get_pack_widget(data)
pack_list.addItem(item)
pack_list.setItemWidget(item, widget)
item.setSizeHint(QSize(1060, 69))
widget = GetPackWidget(data)
packList.addItem(item)
packList.setItemWidget(item, widget)
......@@ -18,14 +18,16 @@ import sys
if sys.platform == 'win32':
Font['main'].setFamily("Microsoft YaHei")
Font['main'].setPointSize(10)
Font['status'].setFamily("FangSong")
Font['main'].setPointSize(9)
Font['status'].setFamily("KaiTi")
Font['status'].setPointSize(10)
# Font['status'].setBold(True)
# Font['status'].setWeight(75)
elif sys.platform == 'darwin':
Font['main'].setFamily(".AppleSystemUIFont")
Font['main'].setPointSize(13)
Font['status'].setFamily(".AppleSystemUIFont")
Font['main'].setPointSize(12)
pass
Font['status'].setPointSize(13)
else:
Font['main'].setFamily("Microsoft YaHei")
Font['main'].setPointSize(13)
......
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'functionWindow.ui'
#
# 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.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_functionWindow(object):
def setupUi(self, functionWindow):
functionWindow.setObjectName("functionWindow")
functionWindow.resize(1000, 720)
functionWindow.setMaximumSize(QtCore.QSize(1000, 720))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("favicon.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
functionWindow.setWindowIcon(icon)
functionWindow.setDockNestingEnabled(False)
self.centralwidget = QtWidgets.QWidget(functionWindow)
self.centralwidget.setObjectName("centralwidget")
self.packFrame = QtWidgets.QFrame(self.centralwidget)
self.packFrame.setGeometry(QtCore.QRect(0, 0, 1000, 720))
self.packFrame.setMaximumSize(QtCore.QSize(1000, 720))
self.packFrame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.packFrame.setFrameShadow(QtWidgets.QFrame.Raised)
self.packFrame.setObjectName("packFrame")
self.listWidget_packs = QtWidgets.QListWidget(self.packFrame)
self.listWidget_packs.setGeometry(QtCore.QRect(0, 0, 750, 600))
self.listWidget_packs.setObjectName("listWidget_packs")
self.pushButton_pack_OK = QtWidgets.QPushButton(self.packFrame)
self.pushButton_pack_OK.setGeometry(QtCore.QRect(810, 240, 113, 32))
self.pushButton_pack_OK.setObjectName("pushButton_pack_OK")
self.pushButton_next = QtWidgets.QPushButton(self.packFrame)
self.pushButton_next.setGeometry(QtCore.QRect(810, 330, 113, 32))
self.pushButton_next.setObjectName("pushButton_next")
self.pushButton_last = QtWidgets.QPushButton(self.packFrame)
self.pushButton_last.setGeometry(QtCore.QRect(810, 420, 113, 32))
self.pushButton_last.setObjectName("pushButton_last")
self.label_page = QtWidgets.QLabel(self.packFrame)
self.label_page.setGeometry(QtCore.QRect(810, 150, 113, 32))
self.label_page.setAlignment(QtCore.Qt.AlignCenter)
self.label_page.setObjectName("label_page")
self.exerciseFrame = QtWidgets.QFrame(self.centralwidget)
self.exerciseFrame.setGeometry(QtCore.QRect(0, 0, 1000, 720))
self.exerciseFrame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.exerciseFrame.setFrameShadow(QtWidgets.QFrame.Raised)
self.exerciseFrame.setObjectName("exerciseFrame")
self.pushButton_questionlist_OK = QtWidgets.QPushButton(self.exerciseFrame)
self.pushButton_questionlist_OK.setGeometry(QtCore.QRect(810, 240, 113, 32))
self.pushButton_questionlist_OK.setObjectName("pushButton_questionlist_OK")
self.pushButton_questionlist_Back = QtWidgets.QPushButton(self.exerciseFrame)
self.pushButton_questionlist_Back.setGeometry(QtCore.QRect(810, 420, 113, 32))
self.pushButton_questionlist_Back.setObjectName("pushButton_questionlist_Back")
self.listWidget_questions = QtWidgets.QListWidget(self.exerciseFrame)
self.listWidget_questions.setGeometry(QtCore.QRect(0, 0, 750, 600))
self.listWidget_questions.setObjectName("listWidget_questions")
self.pushButton_Beginpack = QtWidgets.QPushButton(self.exerciseFrame)
self.pushButton_Beginpack.setGeometry(QtCore.QRect(810, 150, 113, 32))
self.pushButton_Beginpack.setObjectName("pushButton_Beginpack")
self.exerciseFrame.raise_()
self.packFrame.raise_()
functionWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(functionWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1000, 24))
self.menubar.setObjectName("menubar")
functionWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(functionWindow)
self.statusbar.setObjectName("statusbar")
functionWindow.setStatusBar(self.statusbar)
self.retranslateUi(functionWindow)
QtCore.QMetaObject.connectSlotsByName(functionWindow)
def retranslateUi(self, functionWindow):
_translate = QtCore.QCoreApplication.translate
functionWindow.setWindowTitle(_translate("functionWindow", "题包列表"))
self.pushButton_pack_OK.setText(_translate("functionWindow", "确认"))
self.pushButton_next.setText(_translate("functionWindow", "下一页"))
self.pushButton_last.setText(_translate("functionWindow", "上一页"))
self.label_page.setText(_translate("functionWindow", "第 1 页"))
self.pushButton_questionlist_OK.setText(_translate("functionWindow", "确认"))
self.pushButton_questionlist_Back.setText(_translate("functionWindow", "返回"))
self.pushButton_Beginpack.setText(_translate("functionWindow", "开始题包"))
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>functionWindow</class>
<widget class="QMainWindow" name="functionWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1000</width>
<height>720</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>1000</width>
<height>720</height>
</size>
</property>
<property name="windowTitle">
<string>题包列表</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>favicon.ico</normaloff>favicon.ico</iconset>
</property>
<property name="dockNestingEnabled">
<bool>false</bool>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QFrame" name="packFrame">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1000</width>
<height>720</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>1000</width>
<height>720</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QListWidget" name="listWidget_packs">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>750</width>
<height>600</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_pack_OK">
<property name="geometry">
<rect>
<x>810</x>
<y>240</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>确认</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_next">
<property name="geometry">
<rect>
<x>810</x>
<y>330</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>下一页</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_last">
<property name="geometry">
<rect>
<x>810</x>
<y>420</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>上一页</string>
</property>
</widget>
<widget class="QLabel" name="label_page">
<property name="geometry">
<rect>
<x>810</x>
<y>150</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>第 1 页</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
<widget class="QFrame" name="exerciseFrame">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1000</width>
<height>720</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QPushButton" name="pushButton_questionlist_OK">
<property name="geometry">
<rect>
<x>810</x>
<y>240</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>确认</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_questionlist_Back">
<property name="geometry">
<rect>
<x>810</x>
<y>420</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>返回</string>
</property>
</widget>
<widget class="QListWidget" name="listWidget_questions">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>750</width>
<height>600</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_Beginpack">
<property name="geometry">
<rect>
<x>810</x>
<y>150</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>开始题包</string>
</property>
</widget>
</widget>
<zorder>exerciseFrame</zorder>
<zorder>packFrame</zorder>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1000</width>
<height>24</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>loginWindow</class>
<widget class="QMainWindow" name="loginWindow">
<class>windowLogin</class>
<widget class="QMainWindow" name="windowLogin">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>