LISHUZUOXUN_yangjiang/LSZXPagesManagerLibrary/pop_band_alarm_dialog.py

240 lines
7.9 KiB
Python
Raw Normal View History

2024-09-23 14:54:15 +08:00
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
class PopBandAlarmDialog:
def __init__(self, parent):
self.cancel_action = None
self.commit_action = None
self.labels = []
self.person_list = []
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)
self.dialog.setFixedSize(int(self.screenRect.width() * 0.7), int(self.screenRect.height() * 0.8))
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.scroll_area = QScrollArea()
self.scroll_area.setWidgetResizable(True)
self.scroll_area.setStyleSheet("border: 1px solid #bbbbbb;")
self.scroll_area_layout = QVBoxLayout()
self.scroll_area_layout.addWidget(self.scroll_area)
self.main_layout = QVBoxLayout()
self.main_layout.addLayout(self.scroll_area_layout, 80)
self.main_layout.addLayout(self.btn_layout, 20)
self.dialog.setLayout(self.main_layout)
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 redraw_person_list(self, person_list):
column_num = 7
row_num = 6
self.labels.clear()
self.person_list = person_list
scroll_widget = QWidget()
scroll_layout = QVBoxLayout(scroll_widget)
row_layout = QHBoxLayout()
for index, item in enumerate(self.person_list):
card_widget = self.create_person_card(item)
card_widget.mousePressEvent = lambda event, lbl=card_widget: self.item_clicked(event, lbl)
row_layout.addWidget(card_widget)
self.labels.append(card_widget)
if (index + 1) % 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.setStyleSheet("border:none")
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.setStyleSheet("border:none")
row_layout = QHBoxLayout()
row_layout.addWidget(empty_box)
scroll_layout.addLayout(row_layout)
self.scroll_area.setWidget(scroll_widget)
# 确认人员相关信息卡片
def create_person_card(self, item):
card_widget = QWidget()
card_widget.item = item
card_widget.name_label = self.init_name_label_widget(item["name"])
card_widget.id_label = self.init_id_label_widget(str(item["id"]))
person_card_layout = QVBoxLayout(card_widget)
person_card_layout.addWidget(card_widget.name_label, 50)
person_card_layout.addWidget(card_widget.id_label, 50)
card_widget.setStyleSheet(
"border-radius: 4px;"
"border: 1px solid #bbbbbb;"
"margin: 4px;"
)
return card_widget
def show(self, person_list):
self.redraw_person_list(person_list)
self.overlay.show()
self.dialog.show()
def hide(self):
self.dialog.hide()
self.overlay.hide()
# 取消按钮响应事件
def cancel_button_action(self):
self.labels = []
self.dialog.hide()
self.overlay.hide()
if self.cancel_action:
self.cancel_action()
# 确认按钮响应事件
def commit_button_action(self):
self.dialog.hide()
self.overlay.hide()
self.labels = []
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 item_clicked(self, event, lbl):
for l in self.labels:
if l == lbl:
l.setStyleSheet(
"border-radius: 4px;"
"border: none;"
"margin: 4px;"
"background-color: #409eff;"
)
l.name_label.setStyleSheet(
"color: #ffffff;"
"font: 24px \"Microsoft YaHei UI\";"
)
l.id_label.setStyleSheet(
"border: 1px solid white;"
"padding: 4px 28px 4px 28px;"
"font: 20px \"Microsoft YaHei UI\";"
"margin: 0px;"
"background-color: #409eff;"
"border-radius: 4px;"
"color: #ffffff;"
)
else:
l.setStyleSheet(
"border-radius: 4px;"
"border: 1px solid #bbbbbb;"
"margin: 4px;"
)
l.name_label.setStyleSheet(
"color: #101010;"
"border: none;"
"font: 24px \"Microsoft YaHei UI\";"
)
l.id_label.setStyleSheet(
"border: 1px solid #e7e7e7;"
"padding: 4px 28px 4px 28px;"
"font: 20px \"Microsoft YaHei UI\";"
"margin: 0px;"
"background-color: #e7e7e7;"
"border-radius: 4px;"
"color: #454545;"
)
def init_name_label_widget(self, name):
name_label = QLabel()
name_label.setAlignment(Qt.AlignCenter)
name_label.setStyleSheet(
"font: 24px \"Microsoft YaHei UI\";"
"color: #101010;"
"padding:0;"
"border: none;"
)
name_label.setText(name)
return name_label
def init_id_label_widget(self, id_str):
id_label = QLabel()
id_label.setAlignment(Qt.AlignCenter)
id_label.setStyleSheet(
"border: 1px solid #e7e7e7;"
"padding: 4px 28px 4px 28px;"
"font: 20px \"Microsoft YaHei UI\";"
"margin: 0px;"
"background-color: #e7e7e7;"
"border-radius: 4px;"
"color: #454545;"
)
id_label.setText('编号:' + id_str)
return id_label
# 初始化取消按钮
@staticmethod
def _init_cancel_button():
cancel_btn = QPushButton("取消")
cancel_btn.setStyleSheet(
"border: 1px solid #222222;"
"color: #222222;"
"padding-top: 30px;"
"padding-bottom: 30px;"
"margin: 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: 20px;"
"border-radius: 4px;"
"font: 24px \"Microsoft YaHei UI\";"
"background-color: #409eff;"
)
return commit_btn