306 lines
10 KiB
Python
306 lines
10 KiB
Python
|
from PyQt5.QtWidgets import *
|
|||
|
from PyQt5.QtCore import Qt
|
|||
|
|
|||
|
|
|||
|
class PopSummaryDialog:
|
|||
|
|
|||
|
def __init__(self, parent):
|
|||
|
super().__init__()
|
|||
|
self.num_label_text = None
|
|||
|
self.run_ahead_text = None
|
|||
|
self.runaround_count_text = None
|
|||
|
self.add_action = None
|
|||
|
self.down_action = None
|
|||
|
self.cancel_action = None
|
|||
|
self.commit_action = None
|
|||
|
self.pole_num = 0
|
|||
|
self.parent = parent
|
|||
|
|
|||
|
desktop = QDesktopWidget()
|
|||
|
self.screenRect = desktop.availableGeometry()
|
|||
|
self.dialog = QDialog(
|
|||
|
flags=Qt.CustomizeWindowHint | Qt.WindowCloseButtonHint | Qt.WindowStaysOnTopHint
|
|||
|
) # 设置无图标和标题
|
|||
|
self.dialog.setStyleSheet("background-color:#ffffff;")
|
|||
|
self.dialog.setContentsMargins(0, 0, 0, 0)
|
|||
|
# 设置对话框的宽度为屏幕的35%,高度为屏幕的70%
|
|||
|
self.dialog.setFixedSize(int(self.screenRect.width() * 0.45), int(self.screenRect.height() * 0.55))
|
|||
|
|
|||
|
# 标题"请确认人员测试是否有扣分项"
|
|||
|
self.title_label = self._init_title_label()
|
|||
|
|
|||
|
# 总用时
|
|||
|
self.run_second_title = self._init_run_second_title()
|
|||
|
self.run_second_num = self._init_run_second_num()
|
|||
|
|
|||
|
self.run_second_layout = QHBoxLayout()
|
|||
|
self.run_second_layout.addWidget(self.run_second_title, 40)
|
|||
|
self.run_second_layout.addWidget(self.run_second_num, 60)
|
|||
|
|
|||
|
# 抢跑秒数
|
|||
|
self.run_ahead_title = self._init_run_ahead_title()
|
|||
|
self.run_ahead_num = self._init_run_ahead_num()
|
|||
|
|
|||
|
self.run_ahead_layout = QHBoxLayout()
|
|||
|
self.run_ahead_layout.addWidget(self.run_ahead_title, 40)
|
|||
|
self.run_ahead_layout.addWidget(self.run_ahead_num, 60)
|
|||
|
|
|||
|
# 撞杆标题
|
|||
|
self.pole_title = self._init_pole_title()
|
|||
|
|
|||
|
# 撞杆的减号,数值,加号区域
|
|||
|
self.down_button = self._init_down_button_widget()
|
|||
|
self.num_label = self._init_num_label_widget()
|
|||
|
self.add_button = self._init_add_button_widget()
|
|||
|
|
|||
|
self.down_button.clicked.connect(self.down_button_action)
|
|||
|
self.add_button.clicked.connect(self.add_button_action)
|
|||
|
|
|||
|
self.button_layout = QHBoxLayout()
|
|||
|
self.button_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
self.button_layout.addWidget(self.down_button, 35)
|
|||
|
self.button_layout.addWidget(self.num_label, 30)
|
|||
|
self.button_layout.addWidget(self.add_button, 35)
|
|||
|
# 创建一个widget,用于设置撞杆按钮区域的边框
|
|||
|
self.button_label_widget = self._init_button_label_widget()
|
|||
|
self.button_label_widget.setLayout(self.button_layout)
|
|||
|
self.main_widget_layout = QVBoxLayout()
|
|||
|
self.main_widget_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
self.main_widget_layout.addWidget(self.button_label_widget)
|
|||
|
|
|||
|
self.pole_layout = QHBoxLayout()
|
|||
|
self.pole_layout.addWidget(self.pole_title, 40)
|
|||
|
self.pole_layout.addLayout(self.main_widget_layout, 60)
|
|||
|
|
|||
|
self.config_layout = QVBoxLayout()
|
|||
|
self.config_layout.addLayout(self.run_second_layout, 35)
|
|||
|
self.config_layout.addLayout(self.run_ahead_layout, 35)
|
|||
|
self.config_layout.addLayout(self.pole_layout, 30)
|
|||
|
|
|||
|
# 取消按钮、确认按钮
|
|||
|
self.cancel_btn = self._init_cancel_button()
|
|||
|
self.commit_btn = self._init_commit_button()
|
|||
|
|
|||
|
self.cancel_btn.clicked.connect(self.cancel_button_action)
|
|||
|
self.commit_btn.clicked.connect(self.commit_button_action)
|
|||
|
|
|||
|
self.btn_layout = QHBoxLayout()
|
|||
|
self.btn_layout.addWidget(self.cancel_btn, 50)
|
|||
|
self.btn_layout.addWidget(self.commit_btn, 50)
|
|||
|
# 总布局
|
|||
|
self.main_layout = QVBoxLayout()
|
|||
|
self.main_layout.addWidget(self.title_label, 10)
|
|||
|
self.main_layout.addLayout(self.config_layout, 50)
|
|||
|
self.main_layout.addLayout(self.btn_layout, 40)
|
|||
|
|
|||
|
self.dialog.setLayout(self.main_layout)
|
|||
|
|
|||
|
# 添加遮罩层,设置parent,确保遮罩层在父页面中显示
|
|||
|
self.overlay = QWidget(self.parent)
|
|||
|
self.overlay.setStyleSheet("background-color: rgba(0, 0, 0, 0.5);")
|
|||
|
self.overlay.resize(self.screenRect.width(), self.screenRect.height())
|
|||
|
self.overlay.hide()
|
|||
|
|
|||
|
def set_runaround_count(self, runaround_count):
|
|||
|
self.runaround_count_text = runaround_count
|
|||
|
self.run_second_num.setText(self.runaround_count_text)
|
|||
|
|
|||
|
def set_run_ahead(self, run_ahead):
|
|||
|
self.run_ahead_text = run_ahead
|
|||
|
self.run_ahead_num.setText(self.run_ahead_text)
|
|||
|
|
|||
|
def get_runaround_count(self):
|
|||
|
return self.runaround_count_text
|
|||
|
|
|||
|
def get_run_ahead(self):
|
|||
|
return self.run_ahead_text
|
|||
|
|
|||
|
def get_num_label(self):
|
|||
|
return self.pole_num
|
|||
|
|
|||
|
def show(self):
|
|||
|
self.overlay.show()
|
|||
|
self.dialog.show()
|
|||
|
|
|||
|
# 取消按钮响应事件
|
|||
|
def cancel_button_action(self):
|
|||
|
self.dialog.hide()
|
|||
|
self.overlay.hide()
|
|||
|
if self.cancel_action:
|
|||
|
self.cancel_action()
|
|||
|
|
|||
|
# 确认按钮响应事件
|
|||
|
def commit_button_action(self):
|
|||
|
self.dialog.hide()
|
|||
|
self.overlay.hide()
|
|||
|
# 调用链接函数
|
|||
|
if self.commit_action:
|
|||
|
self.commit_action()
|
|||
|
|
|||
|
def connect(self, func):
|
|||
|
self.commit_action = func
|
|||
|
|
|||
|
def cancel_connect(self, func):
|
|||
|
self.cancel_action = func
|
|||
|
|
|||
|
def down_button_action(self):
|
|||
|
self.pole_num = int(self.num_label.text()) - 1
|
|||
|
if self.pole_num >= 0:
|
|||
|
self.num_label.setText(f"{self.pole_num}")
|
|||
|
|
|||
|
def add_button_action(self):
|
|||
|
self.pole_num = int(self.num_label.text()) + 1
|
|||
|
self.num_label.setText(f"{self.pole_num}")
|
|||
|
|
|||
|
# 初始化取消按钮
|
|||
|
@staticmethod
|
|||
|
def _init_cancel_button():
|
|||
|
cancel_btn = QPushButton("取消")
|
|||
|
cancel_btn.setStyleSheet(
|
|||
|
"border: 1px solid #222222;"
|
|||
|
"color: #222222;"
|
|||
|
"padding-top: 30px;"
|
|||
|
"padding-bottom: 30px;"
|
|||
|
"margin: 50px 20px 20px 20px;"
|
|||
|
"border-radius: 4px;"
|
|||
|
"font: 24px \"Microsoft YaHei UI\";"
|
|||
|
)
|
|||
|
return cancel_btn
|
|||
|
|
|||
|
# 初始化确认按钮
|
|||
|
@staticmethod
|
|||
|
def _init_commit_button():
|
|||
|
commit_btn = QPushButton("确定")
|
|||
|
commit_btn.setStyleSheet(
|
|||
|
"border: 1px solid #409eff;"
|
|||
|
"color: #ffffff;"
|
|||
|
"padding-top: 30px;"
|
|||
|
"padding-bottom: 30px;"
|
|||
|
"margin: 50px 20px 20px 20px;"
|
|||
|
"border-radius: 4px;"
|
|||
|
"font: 24px \"Microsoft YaHei UI\";"
|
|||
|
"background-color: #409eff;"
|
|||
|
)
|
|||
|
return commit_btn
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def _init_title_label():
|
|||
|
title_label = QLabel("请确认人员测试是否有扣分项")
|
|||
|
title_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
|||
|
title_label.setWordWrap(True)
|
|||
|
title_label.setStyleSheet(
|
|||
|
"font: 600 30px \"Microsoft YaHei UI\";"
|
|||
|
"letter-spacing: 4px;"
|
|||
|
"margin-left: 6px;"
|
|||
|
"margin-right: 6px;"
|
|||
|
)
|
|||
|
return title_label
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def _init_pole_title():
|
|||
|
pole_title = QLabel("撞杆")
|
|||
|
pole_title.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
|||
|
pole_title.setStyleSheet(
|
|||
|
"font: 30px \"Microsoft YaHei UI\";"
|
|||
|
"letter-spacing: 4px;"
|
|||
|
"margin-left: 6px;"
|
|||
|
"margin-right: 6px;"
|
|||
|
)
|
|||
|
return pole_title
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def _init_down_button_widget():
|
|||
|
down_button = QPushButton("-")
|
|||
|
down_button.setStyleSheet(
|
|||
|
"font: 100px \"Microsoft YaHei UI\";"
|
|||
|
"color: #ffffff;"
|
|||
|
"background-color: #409eff;"
|
|||
|
"height: 100%;"
|
|||
|
"margin-top: -9px;"
|
|||
|
"border: none;"
|
|||
|
)
|
|||
|
return down_button
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def _init_num_label_widget():
|
|||
|
num_label = QLabel("0")
|
|||
|
num_label.setAlignment(Qt.AlignCenter)
|
|||
|
num_label.setStyleSheet(
|
|||
|
"font: 600 35px \"Microsoft YaHei UI\";"
|
|||
|
"letter-spacing: 4px;"
|
|||
|
"border-top: 2px solid #e7e7e7;"
|
|||
|
"border-bottom: 2px solid #e7e7e7;"
|
|||
|
"border-left: none;"
|
|||
|
"border-right: none;"
|
|||
|
)
|
|||
|
return num_label
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def _init_add_button_widget():
|
|||
|
add_button = QPushButton("+")
|
|||
|
add_button.setStyleSheet(
|
|||
|
"font: 75px \"Microsoft YaHei UI\";"
|
|||
|
"color: #ffffff;"
|
|||
|
"background-color: #409eff;"
|
|||
|
"height: 100%;"
|
|||
|
"margin-top: -9px;"
|
|||
|
"border: none;"
|
|||
|
)
|
|||
|
return add_button
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def _init_button_label_widget():
|
|||
|
button_label_widget = QWidget()
|
|||
|
button_label_widget.setStyleSheet(
|
|||
|
"border: 2px solid #e7e7e7;"
|
|||
|
)
|
|||
|
return button_label_widget
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def _init_run_second_title():
|
|||
|
run_second_title = QLabel("总用时")
|
|||
|
run_second_title.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
|||
|
run_second_title.setStyleSheet(
|
|||
|
"font: 30px \"Microsoft YaHei UI\";"
|
|||
|
"letter-spacing: 4px;"
|
|||
|
"margin-left: 6px;"
|
|||
|
"margin-right: 6px;"
|
|||
|
)
|
|||
|
return run_second_title
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def _init_run_second_num():
|
|||
|
run_second_num = QLabel("0秒")
|
|||
|
run_second_num.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
|||
|
run_second_num.setStyleSheet(
|
|||
|
"font: 30px \"Microsoft YaHei UI\";"
|
|||
|
"letter-spacing: 4px;"
|
|||
|
"margin-left: 6px;"
|
|||
|
"margin-right: 6px;"
|
|||
|
)
|
|||
|
return run_second_num
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def _init_run_ahead_title():
|
|||
|
run_ahead_title = QLabel("抢跑")
|
|||
|
run_ahead_title.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
|||
|
run_ahead_title.setStyleSheet(
|
|||
|
"font: 30px \"Microsoft YaHei UI\";"
|
|||
|
"letter-spacing: 4px;"
|
|||
|
"margin-left: 6px;"
|
|||
|
"margin-right: 6px;"
|
|||
|
)
|
|||
|
return run_ahead_title
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def _init_run_ahead_num():
|
|||
|
run_ahead_num = QLabel("0秒")
|
|||
|
run_ahead_num.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
|||
|
run_ahead_num.setStyleSheet(
|
|||
|
"font: 30px \"Microsoft YaHei UI\";"
|
|||
|
"letter-spacing: 4px;"
|
|||
|
"margin-left: 6px;"
|
|||
|
"margin-right: 6px;"
|
|||
|
)
|
|||
|
return run_ahead_num
|