166 lines
6.0 KiB
Python
166 lines
6.0 KiB
Python
# coding: gb2312
|
||
import threading
|
||
|
||
from PyQt5.QtWidgets import *
|
||
from LSZXPagesLibrary.consensus import *
|
||
from LSZXPagesLibrary.pop_message_dialog import PopDialogMessage
|
||
from LSZXPagesLibrary.running_config_layout_define import RunningConfigPageLayoutDefine
|
||
from PureBackend.global_execrise_backend import GEB
|
||
|
||
|
||
class RunningConfigPage(RunningConfigPageLayoutDefine):
|
||
|
||
def __init__(self):
|
||
super(RunningConfigPage, self).__init__()
|
||
self.eb = GEB().get_geb()
|
||
|
||
self.person_list = None
|
||
# 返回上一页
|
||
self.back_pre_button.clicked.connect(self.back_pre_button_action)
|
||
# 注册返回界面的按钮
|
||
self.back_home_button.clicked.connect(self.back_home)
|
||
# 注册长跑考试界面(有很多个圆圈记录考试ing的数据)响应动作
|
||
self.start_button.clicked.connect(self.start_button_action)
|
||
# 语音播报缓存
|
||
self.is_sound_report = False
|
||
# 语音播报
|
||
self.sound_checkbox.clicked.connect(self.sound_reaction)
|
||
# 圈数缓存
|
||
self.round_num = 3
|
||
# 圈数加减动作
|
||
self.round_down_button.clicked.connect(self.round_down_button_action)
|
||
self.round_add_button.clicked.connect(self.round_up_button_action)
|
||
# 最小圈时缓存
|
||
self.round_time = 60
|
||
# 最小圈时加减动作
|
||
self.round_time_down_button.clicked.connect(self.round_time_down_button_action)
|
||
self.round_time_add_button.clicked.connect(self.round_time_up_button_action)
|
||
|
||
# 弹窗
|
||
self.message_pop_windows = PopDialogMessage(self)
|
||
self.message_pop_windows.connect(self.message_pop_commit)
|
||
|
||
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.round_num_widget.setText(f"{self.round_num}圈")
|
||
self.round_time_widget.setText(f"{self.round_time}秒")
|
||
self.sound_checkbox.setChecked(self.is_sound_report)
|
||
# 重新生成人员列表
|
||
self.person_list = self.data.get(PERSON_LIST)
|
||
self.redraw_person_list()
|
||
|
||
def back_pre_button_action(self):
|
||
self.back2page(RUNNING_PICK_UP)
|
||
|
||
# 返回首页时弹窗提示
|
||
def back_home(self):
|
||
self.message_pop_windows.show("此操作将放弃考试, 是否继续?")
|
||
|
||
# 弹窗点击了确定按钮事件
|
||
def message_pop_commit(self):
|
||
# 跳转
|
||
self.jump2(HOME_PAGE)
|
||
|
||
def start_button_action(self):
|
||
# 设置是否语音播报
|
||
if not self.eb.voice_play(self.is_sound_report):
|
||
return
|
||
# 设置长跑的圈时圈数
|
||
if not self.eb.set_running_config(round_num=self.round_num, min_round_time=self.round_time):
|
||
return
|
||
# 将人员加入到考试名单中
|
||
ids = [person[ID] for person in self.person_list]
|
||
if not self.eb.running_set_bands(ids=ids):
|
||
return
|
||
# 启动考试
|
||
threading.Thread(target=self.eb.start_running, daemon=True).start()
|
||
# 页面跳转
|
||
pkg = {
|
||
EXERCISE_TYPE: self.data[EXERCISE_TYPE],
|
||
PERSON_LIST: self.person_list
|
||
}
|
||
self.jump2(RUNNING_TEST_PAGE, pkg)
|
||
|
||
def sound_reaction(self):
|
||
self.is_sound_report = not self.is_sound_report
|
||
self.sound_checkbox.setChecked(self.is_sound_report)
|
||
|
||
def round_down_button_action(self):
|
||
self.round_num = int(self.round_num) - 1
|
||
if self.round_num <= 0:
|
||
self.round_num = 0
|
||
self.round_num_widget.setText("终点检测模式\n(到达即结束)")
|
||
else:
|
||
self.round_num_widget.setText(f"{self.round_num}圈")
|
||
|
||
def round_up_button_action(self):
|
||
self.round_num = int(self.round_num) + 1
|
||
self.round_num_widget.setText(f"{self.round_num}圈")
|
||
|
||
def round_time_down_button_action(self):
|
||
self.round_time = int(self.round_time) - 10
|
||
if self.round_time <= 20:
|
||
self.round_time = 20
|
||
self.round_time_widget.setText(f"{self.round_time}秒")
|
||
|
||
def round_time_up_button_action(self):
|
||
self.round_time = int(self.round_time) + 10
|
||
self.round_time_widget.setText(f"{self.round_time}秒")
|
||
|
||
# 确认参加考试的考生相关信息卡片(一个widget)
|
||
def create_person_card(self, item):
|
||
card_widget = self.init_person_card_widget()
|
||
name_label = self.init_name_label_widget()
|
||
id_label = self.init_id_label_widget()
|
||
name_label.setText(item["name"])
|
||
id_label.setText('编号:' + item["id"])
|
||
person_card_layout = QVBoxLayout(card_widget)
|
||
person_card_layout.addWidget(name_label, 50)
|
||
person_card_layout.addWidget(id_label, 50)
|
||
return card_widget
|
||
|
||
# 重新绘制人员信息
|
||
def redraw_person_list(self):
|
||
column_num = 8
|
||
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)
|
||
|
||
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()
|
||
empty_box.setFrameShape(QFrame.Box)
|
||
empty_box.setLineWidth(0)
|
||
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)
|
||
|