from PySide6.QtWidgets import ( QWidget, QLabel, QLineEdit, QPushButton, QComboBox, QGridLayout, QHBoxLayout, QVBoxLayout, QTabWidget, QFrame, QFormLayout, QGroupBox, QRadioButton, QSpacerItem, QSizePolicy, QTableWidget, QTableWidgetItem, QHeaderView, QSlider, QCheckBox ) from PySide6.QtGui import QFont, QBrush, QColor from PySide6.QtCore import Qt, Signal, QSize class SettingsUI(QWidget): def __init__(self, parent=None): super().__init__(parent) self.parent = parent self.init_ui() def init_ui(self): # 设置字体 self.title_font = QFont("微软雅黑", 14, QFont.Bold) self.normal_font = QFont("微软雅黑", 10) self.small_font = QFont("微软雅黑", 9) # 创建主布局 self.main_layout = QVBoxLayout(self) self.main_layout.setContentsMargins(10, 10, 10, 10) # 创建标题 self.title_label = QLabel("系统设置") self.title_label.setFont(self.title_font) self.title_label.setAlignment(Qt.AlignCenter) self.title_label.setStyleSheet("color: #1a237e; margin-bottom: 10px;") self.main_layout.addWidget(self.title_label) # 创建选项卡部件 self.tab_widget = QTabWidget() self.tab_widget.setFont(self.normal_font) self.main_layout.addWidget(self.tab_widget) # 创建各个选项卡 self.create_camera_tab() self.create_database_tab() self.create_inspection_tab() self.create_plc_tab() self.create_push_tab() self.create_auth_tab() self.create_user_tab() self.create_param_tab() self.create_pallet_type_tab() def create_camera_tab(self): # 相机设置选项卡 self.camera_tab = QWidget() self.camera_layout = QVBoxLayout(self.camera_tab) self.camera_layout.setContentsMargins(20, 20, 20, 20) # 相机选择区域 self.camera_select_group = QGroupBox("相机选择") self.camera_select_group.setFont(self.normal_font) self.camera_select_layout = QHBoxLayout() self.camera_label = QLabel("相机设备:") self.camera_label.setFont(self.normal_font) self.camera_combo = QComboBox() self.camera_combo.setFont(self.normal_font) self.camera_combo.setMinimumWidth(300) self.refresh_button = QPushButton("刷新设备") self.refresh_button.setFont(self.normal_font) self.camera_select_layout.addWidget(self.camera_label) self.camera_select_layout.addWidget(self.camera_combo) self.camera_select_layout.addWidget(self.refresh_button) self.camera_select_layout.addStretch(1) self.camera_select_group.setLayout(self.camera_select_layout) self.camera_layout.addWidget(self.camera_select_group) # 相机控制区域 self.camera_control_group = QGroupBox("相机控制") self.camera_control_group.setFont(self.normal_font) self.camera_control_layout = QHBoxLayout() self.open_button = QPushButton("打开相机") self.open_button.setFont(self.normal_font) self.open_button.setFixedWidth(120) self.close_button = QPushButton("关闭相机") self.close_button.setFont(self.normal_font) self.close_button.setFixedWidth(120) self.test_button = QPushButton("测试预览") self.test_button.setFont(self.normal_font) self.test_button.setFixedWidth(120) self.camera_control_layout.addWidget(self.open_button) self.camera_control_layout.addWidget(self.close_button) self.camera_control_layout.addWidget(self.test_button) self.camera_control_layout.addStretch(1) self.camera_control_group.setLayout(self.camera_control_layout) self.camera_layout.addWidget(self.camera_control_group) # 相机参数设置区域 self.camera_params_group = QGroupBox("相机参数") self.camera_params_group.setFont(self.normal_font) self.camera_params_layout = QGridLayout() self.camera_params_layout.setColumnStretch(1, 1) # 让滑块列占据更多空间 # 曝光时间 self.exposure_label = QLabel("曝光时间:") self.exposure_label.setFont(self.normal_font) self.exposure_slider = QSlider(Qt.Horizontal) self.exposure_slider.setMinimum(1000) self.exposure_slider.setMaximum(50000) self.exposure_slider.setValue(20000) self.exposure_slider.setTickPosition(QSlider.TicksBelow) self.exposure_slider.setTickInterval(5000) self.exposure_value = QLabel("20000 μs") self.exposure_value.setFont(self.normal_font) self.exposure_value.setMinimumWidth(80) # 增益 self.gain_label = QLabel("增益:") self.gain_label.setFont(self.normal_font) self.gain_slider = QSlider(Qt.Horizontal) self.gain_slider.setMinimum(0) self.gain_slider.setMaximum(100) self.gain_slider.setValue(10) self.gain_slider.setTickPosition(QSlider.TicksBelow) self.gain_slider.setTickInterval(10) self.gain_value = QLabel("10") self.gain_value.setFont(self.normal_font) self.gain_value.setMinimumWidth(80) # 帧率 self.framerate_label = QLabel("帧率:") self.framerate_label.setFont(self.normal_font) self.framerate_slider = QSlider(Qt.Horizontal) self.framerate_slider.setMinimum(1) self.framerate_slider.setMaximum(30) self.framerate_slider.setValue(15) self.framerate_slider.setTickPosition(QSlider.TicksBelow) self.framerate_slider.setTickInterval(5) self.framerate_value = QLabel("15 fps") self.framerate_value.setFont(self.normal_font) self.framerate_value.setMinimumWidth(80) # 添加到布局 self.camera_params_layout.addWidget(self.exposure_label, 0, 0) self.camera_params_layout.addWidget(self.exposure_slider, 0, 1) self.camera_params_layout.addWidget(self.exposure_value, 0, 2) self.camera_params_layout.addWidget(self.gain_label, 1, 0) self.camera_params_layout.addWidget(self.gain_slider, 1, 1) self.camera_params_layout.addWidget(self.gain_value, 1, 2) self.camera_params_layout.addWidget(self.framerate_label, 2, 0) self.camera_params_layout.addWidget(self.framerate_slider, 2, 1) self.camera_params_layout.addWidget(self.framerate_value, 2, 2) self.camera_params_group.setLayout(self.camera_params_layout) self.camera_layout.addWidget(self.camera_params_group) # 相机设置按钮 self.camera_buttons_layout = QHBoxLayout() self.get_params_button = QPushButton("获取参数") self.get_params_button.setFont(self.normal_font) self.get_params_button.setFixedWidth(120) self.set_params_button = QPushButton("设置参数") self.set_params_button.setFont(self.normal_font) self.set_params_button.setFixedWidth(120) self.save_camera_button = QPushButton("保存设置") self.save_camera_button.setFont(self.normal_font) self.save_camera_button.setFixedWidth(120) self.camera_buttons_layout.addStretch(1) self.camera_buttons_layout.addWidget(self.get_params_button) self.camera_buttons_layout.addWidget(self.set_params_button) self.camera_buttons_layout.addWidget(self.save_camera_button) self.camera_layout.addLayout(self.camera_buttons_layout) # 预览区域 self.preview_group = QGroupBox("相机预览") self.preview_group.setFont(self.normal_font) self.preview_layout = QVBoxLayout() self.preview_frame = QFrame() self.preview_frame.setFrameShape(QFrame.Box) self.preview_frame.setLineWidth(1) self.preview_frame.setMinimumHeight(200) self.preview_frame.setStyleSheet("background-color: black;") self.preview_layout.addWidget(self.preview_frame) self.preview_group.setLayout(self.preview_layout) self.camera_layout.addWidget(self.preview_group) # 添加弹性空间 self.camera_layout.addStretch(1) self.tab_widget.addTab(self.camera_tab, "相机设置") def create_database_tab(self): # 数据源设置选项卡 self.database_tab = QWidget() self.database_layout = QVBoxLayout(self.database_tab) self.database_layout.setContentsMargins(20, 20, 20, 20) # 数据库类型选择 self.db_type_group = QGroupBox("数据库类型") self.db_type_group.setFont(self.normal_font) self.db_type_layout = QHBoxLayout() self.sqlite_radio = QCheckBox("SQLite") self.sqlite_radio.setFont(self.normal_font) self.sqlite_radio.setChecked(True) self.pgsql_radio = QCheckBox("PostgreSQL") self.pgsql_radio.setFont(self.normal_font) self.mysql_radio = QCheckBox("MySQL") self.mysql_radio.setFont(self.normal_font) self.db_type_layout.addWidget(self.sqlite_radio) self.db_type_layout.addWidget(self.pgsql_radio) self.db_type_layout.addWidget(self.mysql_radio) self.db_type_layout.addStretch(1) self.db_type_group.setLayout(self.db_type_layout) self.database_layout.addWidget(self.db_type_group) # 数据库连接设置 self.db_conn_group = QGroupBox("连接设置") self.db_conn_group.setFont(self.normal_font) self.db_conn_layout = QFormLayout() self.host_label = QLabel("主机:") self.host_label.setFont(self.normal_font) self.host_input = QLineEdit() self.host_input.setFont(self.normal_font) self.host_input.setPlaceholderText("localhost") self.user_label = QLabel("用户:") self.user_label.setFont(self.normal_font) self.user_input = QLineEdit() self.user_input.setFont(self.normal_font) self.password_label = QLabel("密码:") self.password_label.setFont(self.normal_font) self.password_input = QLineEdit() self.password_input.setFont(self.normal_font) self.password_input.setEchoMode(QLineEdit.Password) self.database_label = QLabel("数据库:") self.database_label.setFont(self.normal_font) self.database_input = QLineEdit() self.database_input.setFont(self.normal_font) self.database_input.setPlaceholderText("db/jtDB.db") self.port_label = QLabel("端口:") self.port_label.setFont(self.normal_font) self.port_input = QLineEdit() self.port_input.setFont(self.normal_font) self.desc_label = QLabel("说明:") self.desc_label.setFont(self.normal_font) self.desc_input = QLineEdit() self.desc_input.setFont(self.normal_font) self.db_conn_layout.addRow(self.host_label, self.host_input) self.db_conn_layout.addRow(self.user_label, self.user_input) self.db_conn_layout.addRow(self.password_label, self.password_input) self.db_conn_layout.addRow(self.database_label, self.database_input) self.db_conn_layout.addRow(self.port_label, self.port_input) self.db_conn_layout.addRow(self.desc_label, self.desc_input) self.db_conn_group.setLayout(self.db_conn_layout) self.database_layout.addWidget(self.db_conn_group) # 按钮区域 self.db_buttons_layout = QHBoxLayout() self.test_conn_button = QPushButton("测试连接") self.test_conn_button.setFont(self.normal_font) self.test_conn_button.setFixedWidth(120) self.save_db_button = QPushButton("保存设置") self.save_db_button.setFont(self.normal_font) self.save_db_button.setFixedWidth(120) self.db_buttons_layout.addStretch(1) self.db_buttons_layout.addWidget(self.test_conn_button) self.db_buttons_layout.addSpacing(20) self.db_buttons_layout.addWidget(self.save_db_button) self.database_layout.addLayout(self.db_buttons_layout) self.database_layout.addStretch(1) self.tab_widget.addTab(self.database_tab, "数据源设置") def create_inspection_tab(self): """创建检验配置选项卡""" # 检验配置选项卡 self.inspection_tab = QWidget() self.inspection_layout = QVBoxLayout(self.inspection_tab) self.inspection_layout.setContentsMargins(0, 0, 0, 0) self.inspection_layout.setSpacing(0) # 添加一个临时提示标签,表示此处将由InspectionSettingsWidget替换 self.inspection_placeholder = QLabel("正在加载检验配置...") self.inspection_placeholder.setFont(self.normal_font) self.inspection_placeholder.setAlignment(Qt.AlignCenter) self.inspection_placeholder.setStyleSheet("color: #888888; padding: 20px;") self.inspection_layout.addWidget(self.inspection_placeholder) # 添加到选项卡 self.tab_widget.addTab(self.inspection_tab, "检验配置") def create_plc_tab(self): # PLC设置选项卡 self.plc_tab = QWidget() self.plc_layout = QVBoxLayout(self.plc_tab) self.plc_layout.setContentsMargins(20, 20, 20, 20) # 占位标签 self.plc_placeholder = QLabel("PLC设置(待实现)") self.plc_placeholder.setFont(self.normal_font) self.plc_placeholder.setAlignment(Qt.AlignCenter) self.plc_layout.addWidget(self.plc_placeholder) self.plc_layout.addStretch(1) self.tab_widget.addTab(self.plc_tab, "PLC设置") def create_push_tab(self): # 推送设置选项卡 self.push_tab = QWidget() self.push_layout = QVBoxLayout(self.push_tab) self.push_layout.setContentsMargins(20, 20, 20, 20) # 占位标签 self.push_placeholder = QLabel("推送设置(待实现)") self.push_placeholder.setFont(self.normal_font) self.push_placeholder.setAlignment(Qt.AlignCenter) self.push_layout.addWidget(self.push_placeholder) self.push_layout.addStretch(1) self.tab_widget.addTab(self.push_tab, "推送设置") def create_auth_tab(self): # 授权设置选项卡 self.auth_tab = QWidget() self.auth_layout = QVBoxLayout(self.auth_tab) self.auth_layout.setContentsMargins(20, 20, 20, 20) # 占位标签 self.auth_placeholder = QLabel("授权设置(待实现)") self.auth_placeholder.setFont(self.normal_font) self.auth_placeholder.setAlignment(Qt.AlignCenter) self.auth_layout.addWidget(self.auth_placeholder) self.auth_layout.addStretch(1) self.tab_widget.addTab(self.auth_tab, "授权设置") def create_user_tab(self): # 用户设置选项卡 self.user_tab = QWidget() self.user_layout = QVBoxLayout(self.user_tab) self.user_layout.setContentsMargins(20, 20, 20, 20) # 占位标签 self.user_placeholder = QLabel("用户设置(待实现)") self.user_placeholder.setFont(self.normal_font) self.user_placeholder.setAlignment(Qt.AlignCenter) self.user_layout.addWidget(self.user_placeholder) self.user_layout.addStretch(1) self.tab_widget.addTab(self.user_tab, "用户设置") def create_param_tab(self): # 参数配置选项卡 self.param_tab = QWidget() self.param_layout = QVBoxLayout(self.param_tab) self.param_layout.setContentsMargins(20, 20, 20, 20) # 占位标签 self.param_placeholder = QLabel("参数配置(待实现)") self.param_placeholder.setFont(self.normal_font) self.param_placeholder.setAlignment(Qt.AlignCenter) self.param_layout.addWidget(self.param_placeholder) self.param_layout.addStretch(1) self.tab_widget.addTab(self.param_tab, "参数配置") def create_pallet_type_tab(self): # 托盘类型设置选项卡 self.pallet_type_tab = QWidget() self.pallet_type_layout = QVBoxLayout(self.pallet_type_tab) self.pallet_type_layout.setContentsMargins(20, 20, 20, 20) # 占位标签 self.pallet_type_placeholder = QLabel("正在加载托盘类型设置...") self.pallet_type_placeholder.setFont(self.normal_font) self.pallet_type_placeholder.setAlignment(Qt.AlignCenter) self.pallet_type_placeholder.setStyleSheet("color: #888888; padding: 20px;") self.pallet_type_layout.addWidget(self.pallet_type_placeholder) self.tab_widget.addTab(self.pallet_type_tab, "托盘类型") def back_to_main(self): """返回主页""" if self.parent and hasattr(self.parent, 'show_main_page'): self.parent.show_main_page()