LISHUZUOXUN_yangjiang/LSZXPagesManagerLibrary/score_page.py

230 lines
9.2 KiB
Python

# coding: gb2312
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt, QTimer
from LSZXPagesManagerLibrary.consensus import *
from LSZXPagesManagerLibrary.pop_message_dialog import PopDialogMessage
from LSZXPagesManagerLibrary.pop_synchronization_dialog import PopDialogSynchronization
from LSZXPagesManagerLibrary.score_page_layout_define import ScorePageLayoutDefine
from PureBackend.global_execrise_backend import GEB
class ScorePage(ScorePageLayoutDefine):
def __init__(self):
super(ScorePage, self).__init__()
# 预加载geb模块
self.eb = GEB().get_geb()
# 班级列表
self.class_list = ['所有']
# 批次列表
self.batch_list = []
self.batch = None
self.class_data = None
self.name = None
self.header_type_table = None
# 清空所有成绩按钮
self.clear_score_button.clicked.connect(self.clear_score_button_action)
# Excel导出成绩按钮
self.excel_export_score_button.clicked.connect(self.excel_export_score_button_action)
# 成绩同步按钮
self.score_synchronization_button.clicked.connect(self.score_synchronization_button_action)
# 成绩同步加载进度条弹窗
self.pop_dialog_synchronization = PopDialogSynchronization(self)
self.pop_dialog_synchronization.connect(self.synchronization_button_action)
# 信息弹窗
self.message_pop_windows = PopDialogMessage(self)
self.message_pop_windows.connect(self.message_pop_commit)
# 表格渲染方法
data = self.eb.get_score(_class=self.class_data, batch=self.batch, name=self.name)
self.table_function(data)
# 获取班级列表
self.get_class_list()
# 获取批次列表
self.get_batch_list()
# 获取并设置进度定时器
self.status_num = 0
self.timer_get_processing = QTimer()
self.timer_get_processing.timeout.connect(self.get_synchronization_processing)
# self.timer_get_processing.start(1000)
# 获取班级下拉框变化
self.class_combobox.currentIndexChanged.connect(self.class_combobox_changed)
# 获取批次下拉框变化
self.batch_combobox.currentIndexChanged.connect(self.batch_combobox_changed)
# 获取姓名输入框内容事件
self.name_editbox.textChanged.connect(self.get_name_value)
# 获取班级列表
def get_class_list(self):
self.class_list = ['所有']
response_data = self.eb.get_all_class()
self.class_list += response_data
for item in self.class_list:
self.class_combobox.addItem(item)
def get_batch_list(self):
self.batch_list = self.eb.get_all_batch()
self.batch = self.batch_list[-1]
for item in reversed(self.batch_list):
self.batch_combobox.addItem(item)
def table_function(self, data=None):
# 表格渲染
self.header_type_table = HEADER_TYPE_TABLE
column_names = ['姓名', '编号', '班级', '仰卧起坐个数', '仰卧起坐成绩', '引体向上个数', '引体向上成绩',
'30*2蛇形跑时间', '30*2蛇形跑成绩', '长跑时间',
'长跑成绩', '俯卧撑个数', '俯卧撑成绩', '曲臂悬垂时间', '曲臂悬垂成绩', '最终得分']
self.table_widget.setColumnCount(len(column_names))
self.table_widget.setHorizontalHeaderLabels(column_names)
# 设置表头样式
header = self.table_widget.horizontalHeader()
header.setStyleSheet("""
QHeaderView::section {
background-color: #f5f7fa;
border-top: none;
border-left: none;
border-right: 1px solid #d8d8d8;
border-bottom: 1px solid #d8d8d8;
font: 600 18px 'Microsoft YaHei UI';
padding: 0 4px;
}
""")
# 设置行数并填充数据
self.table_widget.setRowCount(len(data))
for row_index, row_data in enumerate(data):
for col_index, col_name in enumerate(column_names):
if col_name == self.header_type_table[NAME]:
value = row_data['name']
elif col_name == self.header_type_table[ID]:
value = str(row_data['id'])
elif col_name == self.header_type_table[CLASS]:
value = row_data['class']
elif col_name == self.header_type_table[SITUP_COUNT]:
value = str(row_data['situp_count'])
elif col_name == self.header_type_table[SITUP_SCORE]:
value = str(row_data['situp_score'])
elif col_name == self.header_type_table[PULLUP_COUNT]:
value = str(row_data['pullup_count'])
elif col_name == self.header_type_table[PULLUP_SCORE]:
value = str(row_data['pullup_score'])
elif col_name == self.header_type_table[RUN_BF_COUNT]:
value = str(row_data['run_bf_count'])
elif col_name == self.header_type_table[RUN_BF_SCORE]:
value = str(row_data['run_bf_score'])
elif col_name == self.header_type_table[RUNNING_COUNT]:
value = str(row_data['running_count'])
elif col_name == self.header_type_table[RUNNING_SCORE]:
value = str(row_data['running_score'])
elif col_name == self.header_type_table[PUSHUP_COUNT]:
value = str(row_data['pushup_count'])
elif col_name == self.header_type_table[PUSHUP_SCORE]:
value = str(row_data['pushup_score'])
elif col_name == self.header_type_table[HANGING_COUNT]:
value = str(row_data['hanging_count'])
elif col_name == self.header_type_table[HANGING_SCORE]:
value = str(row_data['hanging_score'])
elif col_name == self.header_type_table[FINAL_SCORE]:
value = str(row_data['final_score'])
else:
value = ""
item = QTableWidgetItem(value)
item.setTextAlignment(Qt.AlignCenter) # 设置文字居中
self.table_widget.setItem(row_index, col_index, item)
# 双击时不能对表格内容进行修改
self.table_widget.setEditTriggers(QAbstractItemView.NoEditTriggers)
# 自动调整列宽以适应内容
self.table_widget.resizeColumnsToContents()
# 表格行高
self.table_widget.verticalHeader().setDefaultSectionSize(50)
def clear_score_button_action(self):
# print("点击清空所有成绩按钮")
self.message_pop_windows.show("是否确认清除所有人的成绩?")
def message_pop_commit(self):
self.eb.delete_all_score()
data = self.eb.get_score(_class=self.class_data, batch=self.batch, name=self.name)
self.table_function(data)
# print("点击弹窗确认按钮")
# 导出人员成绩
def excel_export_score_button_action(self):
folder = QFileDialog.getExistingDirectory(self, "选择文件夹")
if folder:
self.eb.get_score_xlsx(folder)
def score_synchronization_button_action(self):
# 启动定时器
self.start_get_processing()
self.pop_dialog_synchronization.show()
# 开启数据同步
self.eb.waiting_score_synchronization()
# 更新
self.get_class_list()
self.get_batch_list()
data = self.eb.get_score(_class=self.class_data, batch=self.batch, name=self.name)
self.table_function(data)
# print("点击成绩同步按钮")
def synchronization_button_action(self):
self.eb.stop_data_synchronization()
# print('点击取消同步按钮')
def start_get_processing(self):
self.timer_get_processing.start(50)
def stop_get_processing(self):
self.timer_get_processing.stop()
# 获取同步进度进度
def get_synchronization_processing(self):
processing_data = self.eb.get_synchronization_processing()
task_had_done = processing_data['task_had_done']
task_num = processing_data['task_number']
status = processing_data['status']
if task_num > 0:
processing = int((task_had_done / task_num) * 100)
else:
processing = 0
self.pop_dialog_synchronization.circle_percentage.set_data(processing)
if status == 2 or status == 0:
self.status_num += 1
if self.status_num >= 3:
self.stop_get_processing()
self.pop_dialog_synchronization.close()
self.status_num = 0
# 搜索班级
def class_combobox_changed(self):
self.class_data = self.class_combobox.currentText()
if self.class_data == "所有":
self.class_data = None
data = self.eb.get_score(_class=self.class_data, batch=self.batch, name=self.name)
self.table_function(data)
# 搜索批次
def batch_combobox_changed(self):
self.batch = self.batch_combobox.currentText()
data = self.eb.get_score(_class=self.class_data, batch=self.batch, name=self.name)
self.table_function(data)
# 搜索姓名
def get_name_value(self):
self.name = self.name_editbox.text()
data = self.eb.get_score(_class=self.class_data, batch=self.batch, name=self.name)
self.table_function(data)