541 lines
18 KiB
Python
541 lines
18 KiB
Python
from PyQt5.QtWidgets import *
|
||
from PyQt5.QtCore import Qt
|
||
|
||
|
||
class PopAddPersonDialog:
|
||
|
||
def __init__(self, parent):
|
||
super().__init__()
|
||
self.cancel_action = None
|
||
self.commit_action = None
|
||
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.65),
|
||
int(self.screenRect.height() * 0.65)) # 设置对话框的宽度为屏幕的35%,高度为屏幕的70%
|
||
# 必填项提示图标
|
||
self.required_label = self.init_required_label()
|
||
# 姓名标题提示
|
||
self.name_title_label = self._init_name_title_label()
|
||
# 姓名输入框
|
||
self.name_label = self._init_name_label()
|
||
# 编号ID标题提示
|
||
self.id_title_label = self._init_id_title_label()
|
||
# 编号ID输入框
|
||
self.id_label = self._init_id_label()
|
||
# 班级标题提示
|
||
self.class_title_label = self._init_class_title_label()
|
||
# 班级输入框
|
||
self.class_label = self._init_class_label()
|
||
# 性别标题提示
|
||
self.gender_title_label = self._init_gender_title_label()
|
||
# 性别下拉选择框
|
||
self.gender_combobox = self._init_gender_combobox()
|
||
# 年龄标题提示
|
||
self.age_title_label = self._init_age_title_label()
|
||
# 年龄输入框
|
||
self.age_label = self._init_age_label()
|
||
# 身高标题提示
|
||
self.height_title_label = self._init_height_title_label()
|
||
# 身高输入框
|
||
self.height_label = self._init_height_label()
|
||
# 体重标题提示
|
||
self.weight_title_label = self._init_weight_title_label()
|
||
# 体重输入框
|
||
self.weight_label = self._init_weight_label()
|
||
# bmi标题提示
|
||
self.bmi_title_label = self._init_bmi_title_label()
|
||
# bmi输入框
|
||
self.bmi_label = self._init_bmi_label()
|
||
# pbf标题提示
|
||
self.pbf_title_label = self._init_pbf_title_label()
|
||
# pbf输入框
|
||
self.pbf_label = self._init_pbf_label()
|
||
# 分配手环标题提示
|
||
self.band_title_label = self._init_band_title_label()
|
||
# 分配手环按钮
|
||
self.band_btn = self._init_band_button()
|
||
# 取消按钮
|
||
self.cancel_btn = self._init_cancel_button()
|
||
# 确认按钮
|
||
self.commit_btn = self._init_commit_button()
|
||
# 姓名布局
|
||
self.name_layout = QHBoxLayout()
|
||
self.name_layout.setContentsMargins(20, 0, 20, 0)
|
||
self.name_layout.addWidget(self.init_required_label(), 5)
|
||
self.name_layout.addWidget(self.name_title_label, 15)
|
||
self.name_layout.addWidget(self.name_label, 80)
|
||
# 编号布局
|
||
self.id_layout = QHBoxLayout()
|
||
self.id_layout.setContentsMargins(20, 0, 20, 0)
|
||
self.id_layout.addWidget(self.init_required_label(), 5)
|
||
self.id_layout.addWidget(self.id_title_label, 15)
|
||
self.id_layout.addWidget(self.id_label, 80)
|
||
# 班级布局
|
||
self.class_layout = QHBoxLayout()
|
||
self.class_layout.setContentsMargins(20, 0, 20, 0)
|
||
self.class_layout.addWidget(self.init_required_label(), 5)
|
||
self.class_layout.addWidget(self.class_title_label, 15)
|
||
self.class_layout.addWidget(self.class_label, 80)
|
||
# 性别布局
|
||
self.gender_layout = QHBoxLayout()
|
||
self.gender_layout.setContentsMargins(20, 0, 20, 0)
|
||
self.gender_layout.addWidget(self.init_required_label(), 5)
|
||
self.gender_layout.addWidget(self.gender_title_label, 15)
|
||
self.gender_layout.addWidget(self.gender_combobox, 80)
|
||
# 年龄布局
|
||
self.age_layout = QHBoxLayout()
|
||
self.age_layout.setContentsMargins(20, 0, 20, 0)
|
||
self.age_layout.addWidget(self.init_required_label(), 5)
|
||
self.age_layout.addWidget(self.age_title_label, 15)
|
||
self.age_layout.addWidget(self.age_label, 80)
|
||
# 身高布局
|
||
self.height_layout = QHBoxLayout()
|
||
self.height_layout.setContentsMargins(20, 0, 20, 0)
|
||
self.height_layout.addWidget(self.init_required_label(), 5)
|
||
self.height_layout.addWidget(self.height_title_label, 15)
|
||
self.height_layout.addWidget(self.height_label, 80)
|
||
# 体重布局
|
||
self.weight_layout = QHBoxLayout()
|
||
self.weight_layout.setContentsMargins(20, 0, 20, 0)
|
||
self.weight_layout.addWidget(self.init_required_label(), 5)
|
||
self.weight_layout.addWidget(self.weight_title_label, 15)
|
||
self.weight_layout.addWidget(self.weight_label, 80)
|
||
# bmi布局
|
||
self.bmi_layout = QHBoxLayout()
|
||
self.bmi_layout.setContentsMargins(20, 0, 20, 0)
|
||
self.bmi_layout.addWidget(self.init_empty_widget(), 5)
|
||
self.bmi_layout.addWidget(self.bmi_title_label, 15)
|
||
self.bmi_layout.addWidget(self.bmi_label, 80)
|
||
# pbf布局
|
||
self.pbf_layout = QHBoxLayout()
|
||
self.pbf_layout.setContentsMargins(20, 0, 20, 0)
|
||
self.pbf_layout.addWidget(self.init_empty_widget(), 5)
|
||
self.pbf_layout.addWidget(self.pbf_title_label, 15)
|
||
self.pbf_layout.addWidget(self.pbf_label, 80)
|
||
# 手环布局
|
||
self.band_layout = QHBoxLayout()
|
||
self.band_layout.setContentsMargins(20, 0, 20, 0)
|
||
self.band_layout.addWidget(self.init_required_label(), 5)
|
||
self.band_layout.addWidget(self.band_title_label, 15)
|
||
self.band_layout.addWidget(self.band_btn, 80)
|
||
|
||
self.row1_layout = QHBoxLayout()
|
||
self.row1_layout.setContentsMargins(50, 0, 50, 20)
|
||
self.row1_layout.addLayout(self.name_layout, 50)
|
||
self.row1_layout.addLayout(self.id_layout, 50)
|
||
|
||
self.row2_layout = QHBoxLayout()
|
||
self.row2_layout.setContentsMargins(50, 0, 50, 20)
|
||
self.row2_layout.addLayout(self.class_layout, 50)
|
||
self.row2_layout.addLayout(self.gender_layout, 50)
|
||
|
||
self.row3_layout = QHBoxLayout()
|
||
self.row3_layout.setContentsMargins(50, 0, 50, 20)
|
||
self.row3_layout.addLayout(self.age_layout, 50)
|
||
self.row3_layout.addLayout(self.height_layout, 50)
|
||
|
||
self.row4_layout = QHBoxLayout()
|
||
self.row4_layout.setContentsMargins(50, 0, 50, 20)
|
||
self.row4_layout.addLayout(self.weight_layout, 50)
|
||
self.row4_layout.addLayout(self.band_layout, 50)
|
||
|
||
self.row5_layout = QHBoxLayout()
|
||
self.row5_layout.setContentsMargins(50, 0, 50, 20)
|
||
self.row5_layout.addLayout(self.bmi_layout, 50)
|
||
self.row5_layout.addLayout(self.pbf_layout, 50)
|
||
|
||
self.config_layout = QVBoxLayout()
|
||
self.config_layout.addLayout(self.row1_layout, 20)
|
||
self.config_layout.addLayout(self.row2_layout, 20)
|
||
self.config_layout.addLayout(self.row3_layout, 20)
|
||
self.config_layout.addLayout(self.row4_layout, 20)
|
||
self.config_layout.addLayout(self.row5_layout, 20)
|
||
|
||
# 底部确定取消按钮布局
|
||
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.addLayout(self.config_layout, 90)
|
||
self.main_layout.addLayout(self.btn_layout, 10)
|
||
|
||
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()
|
||
|
||
self.cancel_btn.clicked.connect(self.cancel_button_action)
|
||
self.commit_btn.clicked.connect(self.commit_button_action)
|
||
self.band_btn.clicked.connect(self.band_btn_action)
|
||
|
||
self.gender_list = ['男', '女']
|
||
for item in self.gender_list:
|
||
self.gender_combobox.addItem(item)
|
||
|
||
def get_data_value(self):
|
||
data = {
|
||
'name': self.name_label.text(),
|
||
'id': self.id_label.text(),
|
||
'class': self.class_label.text(),
|
||
'gender': self.gender_combobox.currentText(),
|
||
'age': self.age_label.text(),
|
||
'height': self.height_label.text(),
|
||
'weight': self.weight_label.text(),
|
||
'bmi': self.bmi_label.text(),
|
||
'pbf': self.pbf_label.text(),
|
||
'band_id': None,
|
||
'person_type': None
|
||
}
|
||
return data
|
||
|
||
# 清空输入框
|
||
def clear_fields(self):
|
||
# 清除所有输入字段的文本
|
||
self.name_label.clear()
|
||
self.id_label.clear()
|
||
self.class_label.clear()
|
||
self.gender_combobox.setCurrentIndex(0)
|
||
self.age_label.clear()
|
||
self.height_label.clear()
|
||
self.weight_label.clear()
|
||
self.bmi_label.clear()
|
||
self.pbf_label.clear()
|
||
|
||
def show(self):
|
||
self.overlay.show()
|
||
self.dialog.show()
|
||
|
||
def hide(self):
|
||
self.dialog.hide()
|
||
self.overlay.hide()
|
||
|
||
def band_btn_action(self):
|
||
print('分配手环事件')
|
||
|
||
# 取消按钮响应事件
|
||
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
|
||
|
||
@staticmethod
|
||
def init_empty_widget():
|
||
empty_widget = QFrame()
|
||
return empty_widget
|
||
|
||
@staticmethod
|
||
def init_required_label():
|
||
required_label = QLabel("*")
|
||
required_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
||
required_label.setStyleSheet(
|
||
"color: #ff0000;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
)
|
||
return required_label
|
||
|
||
@staticmethod
|
||
def _init_name_title_label():
|
||
name_title_label = QLabel("姓名:")
|
||
name_title_label.setStyleSheet(
|
||
"color: #222222;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
)
|
||
return name_title_label
|
||
|
||
@staticmethod
|
||
def _init_name_label():
|
||
name_label = QLineEdit()
|
||
name_label.setPlaceholderText("请输入姓名")
|
||
name_label.setStyleSheet(
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"color: #222222;"
|
||
"letter-spacing: 4px;"
|
||
"border: 1px solid #222222;"
|
||
"border-radius: 4px;"
|
||
"padding-top: 15px;"
|
||
"padding-bottom: 15px;"
|
||
"padding-left: 15px;"
|
||
)
|
||
return name_label
|
||
|
||
@staticmethod
|
||
def _init_id_title_label():
|
||
id_title_label = QLabel("编号:")
|
||
id_title_label.setStyleSheet(
|
||
"color: #222222;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
)
|
||
return id_title_label
|
||
|
||
@staticmethod
|
||
def _init_id_label():
|
||
id_label = QLineEdit()
|
||
id_label.setPlaceholderText("请输入编号")
|
||
id_label.setStyleSheet(
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"color: #222222;"
|
||
"letter-spacing: 4px;"
|
||
"border: 1px solid #222222;"
|
||
"border-radius: 4px;"
|
||
"padding-top: 15px;"
|
||
"padding-bottom: 15px;"
|
||
"padding-left: 15px;"
|
||
)
|
||
return id_label
|
||
|
||
@staticmethod
|
||
def _init_class_title_label():
|
||
class_title_label = QLabel("班级:")
|
||
class_title_label.setStyleSheet(
|
||
"color: #222222;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
)
|
||
return class_title_label
|
||
|
||
@staticmethod
|
||
def _init_class_label():
|
||
class_label = QLineEdit()
|
||
class_label.setPlaceholderText("请输入班级")
|
||
class_label.setStyleSheet(
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"color: #222222;"
|
||
"letter-spacing: 4px;"
|
||
"border: 1px solid #222222;"
|
||
"border-radius: 4px;"
|
||
"padding-top: 15px;"
|
||
"padding-bottom: 15px;"
|
||
"padding-left: 15px;"
|
||
)
|
||
return class_label
|
||
|
||
@staticmethod
|
||
def _init_gender_title_label():
|
||
gender_title_label = QLabel("性别:")
|
||
gender_title_label.setStyleSheet(
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"color: #222222;"
|
||
"letter-spacing: 4px;"
|
||
)
|
||
return gender_title_label
|
||
|
||
@staticmethod
|
||
def _init_gender_combobox():
|
||
gender_combobox = QComboBox()
|
||
gender_combobox.setStyleSheet(
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"color: #222222;"
|
||
"letter-spacing: 4px;"
|
||
"border: 1px solid #222222;"
|
||
"border-radius: 4px;"
|
||
"padding-top: 15px;"
|
||
"padding-bottom: 15px;"
|
||
"padding-left: 15px;"
|
||
)
|
||
return gender_combobox
|
||
|
||
@staticmethod
|
||
def _init_age_title_label():
|
||
age_title_label = QLabel("年龄:")
|
||
age_title_label.setStyleSheet(
|
||
"color: #222222;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
)
|
||
return age_title_label
|
||
|
||
@staticmethod
|
||
def _init_age_label():
|
||
age_label = QLineEdit()
|
||
age_label.setPlaceholderText("请输入年龄")
|
||
age_label.setStyleSheet(
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"color: #222222;"
|
||
"letter-spacing: 4px;"
|
||
"border: 1px solid #222222;"
|
||
"border-radius: 4px;"
|
||
"padding-top: 15px;"
|
||
"padding-bottom: 15px;"
|
||
"padding-left: 15px;"
|
||
)
|
||
return age_label
|
||
|
||
@staticmethod
|
||
def _init_height_title_label():
|
||
height_title_label = QLabel("身高:")
|
||
height_title_label.setStyleSheet(
|
||
"color: #222222;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
)
|
||
return height_title_label
|
||
|
||
@staticmethod
|
||
def _init_height_label():
|
||
height_label = QLineEdit()
|
||
height_label.setPlaceholderText("请输入身高(cm)")
|
||
height_label.setStyleSheet(
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"color: #222222;"
|
||
"letter-spacing: 4px;"
|
||
"border: 1px solid #222222;"
|
||
"border-radius: 4px;"
|
||
"padding-top: 15px;"
|
||
"padding-bottom: 15px;"
|
||
"padding-left: 15px;"
|
||
)
|
||
return height_label
|
||
|
||
@staticmethod
|
||
def _init_weight_title_label():
|
||
weight_title_label = QLabel("体重:")
|
||
weight_title_label.setStyleSheet(
|
||
"color: #222222;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
)
|
||
return weight_title_label
|
||
|
||
@staticmethod
|
||
def _init_weight_label():
|
||
weight_label = QLineEdit()
|
||
weight_label.setPlaceholderText("请输入体重(kg)")
|
||
weight_label.setStyleSheet(
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"color: #222222;"
|
||
"letter-spacing: 4px;"
|
||
"border: 1px solid #222222;"
|
||
"border-radius: 4px;"
|
||
"padding-top: 15px;"
|
||
"padding-bottom: 15px;"
|
||
"padding-left: 15px;"
|
||
)
|
||
return weight_label
|
||
|
||
@staticmethod
|
||
def _init_bmi_title_label():
|
||
bmi_title_label = QLabel("BMI:")
|
||
bmi_title_label.setStyleSheet(
|
||
"color: #222222;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
)
|
||
return bmi_title_label
|
||
|
||
@staticmethod
|
||
def _init_bmi_label():
|
||
bmi_label = QLineEdit()
|
||
bmi_label.setPlaceholderText("请输入BMI")
|
||
bmi_label.setStyleSheet(
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"color: #222222;"
|
||
"letter-spacing: 4px;"
|
||
"border: 1px solid #222222;"
|
||
"border-radius: 4px;"
|
||
"padding-top: 15px;"
|
||
"padding-bottom: 15px;"
|
||
"padding-left: 15px;"
|
||
)
|
||
return bmi_label
|
||
|
||
@staticmethod
|
||
def _init_pbf_title_label():
|
||
pbf_title_label = QLabel("PBF:")
|
||
pbf_title_label.setStyleSheet(
|
||
"color: #222222;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
)
|
||
return pbf_title_label
|
||
|
||
@staticmethod
|
||
def _init_pbf_label():
|
||
pbf_label = QLineEdit()
|
||
pbf_label.setPlaceholderText("请输入PBF")
|
||
pbf_label.setStyleSheet(
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"color: #222222;"
|
||
"letter-spacing: 4px;"
|
||
"border: 1px solid #222222;"
|
||
"border-radius: 4px;"
|
||
"padding-top: 15px;"
|
||
"padding-bottom: 15px;"
|
||
"padding-left: 15px;"
|
||
)
|
||
return pbf_label
|
||
|
||
@staticmethod
|
||
def _init_band_title_label():
|
||
band_title_label = QLabel("手环:")
|
||
band_title_label.setStyleSheet(
|
||
"color: #222222;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
)
|
||
return band_title_label
|
||
|
||
@staticmethod
|
||
def _init_band_button():
|
||
band_btn = QPushButton("分配手环")
|
||
band_btn.setStyleSheet(
|
||
"border: 1px solid #222222;"
|
||
"color: #222222;"
|
||
"border-radius: 4px;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"padding-top: 15px;"
|
||
"padding-bottom: 15px;"
|
||
)
|
||
return band_btn
|
||
|
||
# 初始化取消按钮
|
||
@staticmethod
|
||
def _init_cancel_button():
|
||
cancel_btn = QPushButton("取消")
|
||
cancel_btn.setStyleSheet(
|
||
"border: 1px solid #222222;"
|
||
"color: #222222;"
|
||
"padding-top: 30px;"
|
||
"padding-bottom: 30px;"
|
||
"margin-left: 20px;"
|
||
"margin-right: 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-left: 20px;"
|
||
"margin-right: 20px;"
|
||
"border-radius: 4px;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"background-color: #409eff;"
|
||
)
|
||
return commit_btn
|