216 lines
8.2 KiB
Python
216 lines
8.2 KiB
Python
from PySide6.QtWidgets import (
|
||
QWidget, QVBoxLayout, QHBoxLayout, QFormLayout, QLabel,
|
||
QLineEdit, QCheckBox, QComboBox, QPushButton, QGroupBox,
|
||
QTableWidget, QTableWidgetItem, QHeaderView, QAbstractItemView,
|
||
QSpinBox, QDoubleSpinBox, QFrame, QScrollArea
|
||
)
|
||
from PySide6.QtGui import QFont, QBrush, QColor
|
||
from PySide6.QtCore import Qt, Signal
|
||
|
||
class InspectionSettingsUI(QWidget):
|
||
"""检验设置UI"""
|
||
|
||
def __init__(self, parent=None):
|
||
super().__init__(parent)
|
||
self.parent = parent
|
||
self.init_ui()
|
||
|
||
def init_ui(self):
|
||
"""初始化UI"""
|
||
# 设置字体
|
||
self.title_font = QFont("微软雅黑", 14, QFont.Bold)
|
||
self.normal_font = QFont("微软雅黑", 11)
|
||
self.small_font = QFont("微软雅黑", 9)
|
||
|
||
# 设置背景颜色,便于识别
|
||
self.setStyleSheet("background-color: #f5f5f5;")
|
||
|
||
# 创建主布局
|
||
self.main_layout = QVBoxLayout(self)
|
||
self.main_layout.setContentsMargins(20, 20, 20, 20)
|
||
self.main_layout.setSpacing(15)
|
||
|
||
# 标题
|
||
self.title_label = QLabel("检验项目配置")
|
||
self.title_label.setFont(self.title_font)
|
||
self.title_label.setAlignment(Qt.AlignCenter)
|
||
self.title_label.setStyleSheet("color: #1a237e; padding: 10px;")
|
||
self.main_layout.addWidget(self.title_label)
|
||
|
||
# 说明文本
|
||
self.desc_label = QLabel("配置检验二级菜单项目,至少1项,最多6项。启用的项目将显示在微丝产线表格的检验区域。")
|
||
self.desc_label.setWordWrap(True)
|
||
self.desc_label.setStyleSheet("color: #666666; padding: 0px 10px 10px 10px;")
|
||
self.main_layout.addWidget(self.desc_label)
|
||
|
||
# 创建滚动区域
|
||
self.scroll_area = QScrollArea()
|
||
self.scroll_area.setWidgetResizable(True)
|
||
self.scroll_area.setFrameShape(QFrame.NoFrame)
|
||
|
||
# 创建滚动区域的内容部件
|
||
self.scroll_widget = QWidget()
|
||
self.scroll_layout = QVBoxLayout(self.scroll_widget)
|
||
self.scroll_layout.setContentsMargins(0, 0, 0, 0)
|
||
self.scroll_layout.setSpacing(15)
|
||
|
||
# 创建6个检验项目配置组
|
||
self.config_groups = []
|
||
for i in range(6):
|
||
group = self.create_config_group(i + 1)
|
||
self.scroll_layout.addWidget(group)
|
||
self.config_groups.append(group)
|
||
|
||
# 设置滚动区域的部件
|
||
self.scroll_area.setWidget(self.scroll_widget)
|
||
self.main_layout.addWidget(self.scroll_area, 1)
|
||
|
||
# 底部按钮区域
|
||
self.button_layout = QHBoxLayout()
|
||
self.button_layout.setContentsMargins(0, 10, 0, 0)
|
||
|
||
self.save_button = QPushButton("保存配置")
|
||
self.save_button.setFont(self.normal_font)
|
||
self.save_button.setFixedSize(120, 40)
|
||
self.save_button.setStyleSheet("""
|
||
QPushButton {
|
||
background-color: #4caf50;
|
||
color: white;
|
||
border: none;
|
||
border-radius: 5px;
|
||
}
|
||
QPushButton:hover {
|
||
background-color: #45a049;
|
||
}
|
||
QPushButton:pressed {
|
||
background-color: #3d8b40;
|
||
}
|
||
""")
|
||
|
||
self.reset_button = QPushButton("重置")
|
||
self.reset_button.setFont(self.normal_font)
|
||
self.reset_button.setFixedSize(120, 40)
|
||
self.reset_button.setStyleSheet("""
|
||
QPushButton {
|
||
background-color: #f44336;
|
||
color: white;
|
||
border: none;
|
||
border-radius: 5px;
|
||
}
|
||
QPushButton:hover {
|
||
background-color: #e53935;
|
||
}
|
||
QPushButton:pressed {
|
||
background-color: #d32f2f;
|
||
}
|
||
""")
|
||
|
||
self.button_layout.addStretch()
|
||
self.button_layout.addWidget(self.reset_button)
|
||
self.button_layout.addSpacing(20)
|
||
self.button_layout.addWidget(self.save_button)
|
||
|
||
self.main_layout.addLayout(self.button_layout)
|
||
|
||
def create_config_group(self, position):
|
||
"""创建检验项目配置组
|
||
|
||
Args:
|
||
position: 位置序号 (1-6)
|
||
|
||
Returns:
|
||
QGroupBox: 配置组
|
||
"""
|
||
group = QGroupBox(f"检验项目 {position}")
|
||
group.setFont(self.normal_font)
|
||
group.setCheckable(True)
|
||
group.setChecked(position <= 3) # 默认前3个启用
|
||
|
||
group_layout = QFormLayout(group)
|
||
group_layout.setContentsMargins(15, 25, 15, 15)
|
||
group_layout.setSpacing(10)
|
||
|
||
# 名称
|
||
name_label = QLabel("项目名称:")
|
||
name_label.setFont(self.normal_font)
|
||
name_input = QLineEdit()
|
||
name_input.setFont(self.normal_font)
|
||
name_input.setObjectName(f"name_input_{position}")
|
||
group_layout.addRow(name_label, name_input)
|
||
|
||
# 显示名称
|
||
display_name_label = QLabel("显示名称:")
|
||
display_name_label.setFont(self.normal_font)
|
||
display_name_input = QLineEdit()
|
||
display_name_input.setFont(self.normal_font)
|
||
display_name_input.setObjectName(f"display_name_input_{position}")
|
||
group_layout.addRow(display_name_label, display_name_input)
|
||
|
||
# 数据类型
|
||
data_type_label = QLabel("数据类型:")
|
||
data_type_label.setFont(self.normal_font)
|
||
data_type_combo = QComboBox()
|
||
data_type_combo.setFont(self.normal_font)
|
||
data_type_combo.setObjectName(f"data_type_combo_{position}")
|
||
data_type_combo.addItem("文本", "text")
|
||
data_type_combo.addItem("数值", "number")
|
||
data_type_combo.addItem("枚举", "enum")
|
||
group_layout.addRow(data_type_label, data_type_combo)
|
||
|
||
# 单位 (用于数值类型)
|
||
unit_label = QLabel("单位:")
|
||
unit_label.setFont(self.normal_font)
|
||
unit_input = QLineEdit()
|
||
unit_input.setFont(self.normal_font)
|
||
unit_input.setObjectName(f"unit_input_{position}")
|
||
group_layout.addRow(unit_label, unit_input)
|
||
|
||
# 最小值 (用于数值类型)
|
||
min_value_label = QLabel("最小值:")
|
||
min_value_label.setFont(self.normal_font)
|
||
min_value_spin = QDoubleSpinBox()
|
||
min_value_spin.setFont(self.normal_font)
|
||
min_value_spin.setObjectName(f"min_value_spin_{position}")
|
||
min_value_spin.setRange(-999999, 999999)
|
||
min_value_spin.setDecimals(2)
|
||
min_value_spin.setSingleStep(0.1)
|
||
group_layout.addRow(min_value_label, min_value_spin)
|
||
|
||
# 最大值 (用于数值类型)
|
||
max_value_label = QLabel("最大值:")
|
||
max_value_label.setFont(self.normal_font)
|
||
max_value_spin = QDoubleSpinBox()
|
||
max_value_spin.setFont(self.normal_font)
|
||
max_value_spin.setObjectName(f"max_value_spin_{position}")
|
||
max_value_spin.setRange(-999999, 999999)
|
||
max_value_spin.setDecimals(2)
|
||
max_value_spin.setSingleStep(0.1)
|
||
max_value_spin.setValue(100)
|
||
group_layout.addRow(max_value_label, max_value_spin)
|
||
|
||
# 枚举值 (用于枚举类型)
|
||
enum_values_label = QLabel("枚举值:")
|
||
enum_values_label.setFont(self.normal_font)
|
||
enum_values_input = QLineEdit()
|
||
enum_values_input.setFont(self.normal_font)
|
||
enum_values_input.setObjectName(f"enum_values_input_{position}")
|
||
enum_values_input.setPlaceholderText("用逗号分隔,如: 合格,不合格,需重检")
|
||
group_layout.addRow(enum_values_label, enum_values_input)
|
||
|
||
# 是否必填
|
||
required_check = QCheckBox("必填项")
|
||
required_check.setFont(self.normal_font)
|
||
required_check.setObjectName(f"required_check_{position}")
|
||
group_layout.addRow("", required_check)
|
||
|
||
# 保存位置信息
|
||
group.setProperty("position", position)
|
||
|
||
return group
|
||
|
||
def set_form_enabled(self, enabled):
|
||
"""设置表单是否可编辑"""
|
||
for group in self.config_groups:
|
||
group.setEnabled(enabled)
|
||
self.save_button.setEnabled(enabled)
|
||
self.reset_button.setEnabled(enabled) |