LISHUZUOXUN_yangjiang/LSZXPagesLibrary/running_score.py

202 lines
8.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# coding: gb2312
from PyQt5.QtWidgets import *
from LSZXPagesLibrary.consensus import *
from LSZXPagesLibrary.pop_message_dialog import PopDialogMessage
from LSZXPagesLibrary.running_score_layout_define import RunningScoreLayoutDefine
from LSZXPagesLibrary.tool import format_time
from PureBackend.global_execrise_backend import GEB
class RunningScore(RunningScoreLayoutDefine):
def __init__(self):
super(RunningScore, self).__init__()
self.eb = GEB().get_geb()
self.person_list = None
self.selected_person_id = ""
self.labels = []
# 注册返回界面的按钮
self.back_home_button.clicked.connect(self.back_home)
# 提交成绩响应动作
self.stop_test_button.clicked.connect(self.stop)
self.revoke_update_button.clicked.connect(self.withdraw_fix_score)
self.commit_update_button.clicked.connect(self.fix_score)
# 弹窗
self.message_pop_windows = PopDialogMessage(self)
# 确定结束考试弹窗
self.stop_exercise_pop_windows = PopDialogMessage(self)
# 弹窗
self.message_pop_windows.connect(self.message_pop_commit)
# 确定结束考试弹窗
self.stop_exercise_pop_windows.connect(self.stop_exercise_pop_commit)
def fix_score(self):
self.eb.fix_score(self.selected_person_id)
# 确认成绩的考生列表
self.person_list = self.eb.get_running_all_score()
self.clear_summary()
self.redraw_person_list()
def withdraw_fix_score(self):
self.eb.fix_withdraw(self.selected_person_id)
# 确认成绩的考生列表
self.person_list = self.eb.get_running_all_score()
self.clear_summary()
self.redraw_person_list()
def back_home(self):
# 返回首页时弹窗提示
self.message_pop_windows.show("此操作将直接结束考试,并且成绩作废,是否继续?")
# 弹窗点击了确定按钮事件
def message_pop_commit(self):
self.clear_summary()
# 跳转
self.jump2(HOME_PAGE)
def stop(self):
# 返回首页时弹窗提示
self.stop_exercise_pop_windows.show("此操作将结束考试,并提交成绩,是否继续?")
# 弹窗点击了确定按钮事件
def stop_exercise_pop_commit(self):
self.clear_summary()
# 提交考试成绩
self.eb.update_running_score()
pkg = {
EXERCISE_TYPE: self.data[EXERCISE_TYPE],
PERSON_LIST: [
{
IS_CHOOSE: False,
NAME: score["name"],
ID: score["id"],
SCORE: int(score['running_score']),
COUNT: format_time(score['running_count']),
CLASS: score['class'],
BAND_ID: score["band_id"]
}
for score in self.eb.get_all_score()
]
}
self.jump2(RUNNING_PICK_UP, pkg)
def refresh(self) -> None:
exercise_type = self.data.get(EXERCISE_TYPE)
if exercise_type:
exercise_name = EXERCISE_TYPE_TABLE[exercise_type]
self.title_label.setText(exercise_name)
# 确认成绩的考生列表
self.person_list = self.data.get(PERSON_LIST)
self.clear_summary()
self.redraw_person_list()
# 清除所有结算信息
def clear_summary(self):
scroll_round_widget = self.init_scroll_round_widget()
self.scroll_round_area.setWidget(scroll_round_widget)
self.round_tips_label.setText("长跑详情:")
self.score_abnormal_label.setText("成绩可能存在异常,请核对!")
# 清除旧的记录
self.labels = []
def redraw_person_list(self):
column_num = 6
row_num = 6
scroll_widget = QWidget()
scroll_widget.setStyleSheet("border:none;")
scroll_layout = QVBoxLayout(scroll_widget)
row_layout = QHBoxLayout()
for index, item in enumerate(self.person_list):
card_widget = self.create_person_card(item)
row_layout.addWidget(card_widget)
self.labels.append(card_widget)
index += 1
if index % column_num == 0:
scroll_layout.addLayout(row_layout)
row_layout = QHBoxLayout()
if row_layout.count() > 0:
for _ in range(column_num - row_layout.count()):
# 空白框
empty_box = QLabel()
row_layout.addWidget(empty_box)
scroll_layout.addLayout(row_layout)
if scroll_layout.count() < row_num:
for _ in range(row_num - scroll_layout.count()):
# 空白框
empty_box = QLabel()
empty_box.setFrameShape(QFrame.Box)
empty_box.setLineWidth(0)
# 增加到布局中
row_layout = QHBoxLayout()
row_layout.addWidget(empty_box)
scroll_layout.addStretch()
scroll_layout.addLayout(row_layout)
self.scroll_area.setWidget(scroll_widget)
# 每个考生的卡片样式
def create_person_card(self, item):
# 如果done是True代表考生已完成考试成绩没有异常显示蓝色
if item["done"]:
self.card_widget = self.init_card_widget_widget()
round_score_name = self.init_round_score_name_label_widget()
round_score_id = self.init_round_score_id_label_widget()
round_score_name.setText(item["name"])
# 否则就是为完成考试,分两种情况,判断成绩是否发生修改
else:
# 未完成考试的成绩被修改成功,显示蓝色,并在名字后面添加※号标记
if item["fix"]:
self.card_widget = self.init_card_widget_widget()
round_score_name = self.init_round_score_name_label_widget()
round_score_id = self.init_round_score_id_label_widget()
round_score_name.setText(item["name"] + "")
# 未完成考试的成绩没有修改,显示黄色
else:
self.card_widget = self.init_unfinished_card_widget_widget()
round_score_name = self.init_round_unfinished_score_name_label_widget()
round_score_id = self.init_round_unfinished_score_id_label_widget()
round_score_name.setText(item["name"])
round_score_time = self.init_round_score_time_label_widget()
round_score_grade = self.init_round_score_grade_label_widget()
bottom_layout = QHBoxLayout()
bottom_layout.addWidget(round_score_time)
bottom_layout.addWidget(round_score_grade)
round_score_id.setText('编号:' + item["id"])
round_score_time.setText('用时:' + format_time(item["total_time"]))
round_score_grade.setText('成绩:' + str(item["score"]))
person_card_layout = QVBoxLayout(self.card_widget)
person_card_layout.addWidget(round_score_name)
person_card_layout.addWidget(round_score_id)
person_card_layout.addLayout(bottom_layout)
self.card_widget.mousePressEvent = lambda event, lbl=self.card_widget: self.on_label_clicked(event, lbl)
return self.card_widget
# 点击考生卡片后获取考生长跑详情包括考生姓名ID圈数每圈用时
def on_label_clicked(self, event, label):
index = self.labels.index(label)
person_name = self.person_list[index]["name"]
# 获得该人员ID
self.selected_person_id = self.person_list[index]["id"]
self.round_tips_label.setText(person_name + "(编号:" + self.selected_person_id + ")长跑详情:")
self.score_abnormal_label.setText(person_name + "(编号:" + self.selected_person_id + ")的成绩可能存在异常,请核对!")
# 考生长跑详情,圈数+圈时
scroll_round_widget = self.init_scroll_round_widget()
row_round_layout = QVBoxLayout(scroll_round_widget)
row_round_num = 10
for item in self.eb.get_round_time(self.selected_person_id):
round_time_label = self.init_round_time_label_widget()
round_time_label.setText(item["name"] + ":" + item["time"])
row_round_layout.addWidget(round_time_label)
if row_round_layout.count() < row_round_num:
for _ in range(row_round_num - row_round_layout.count()):
# 空白框
empty_box = QLabel()
empty_box.setStyleSheet("border:none")
row_round_layout.addWidget(empty_box)
self.scroll_round_area.setWidget(scroll_round_widget)