2025-06-12 17:29:35 +08:00
|
|
|
|
from PySide6.QtWidgets import (
|
|
|
|
|
|
QWidget, QLabel, QLineEdit, QComboBox, QCheckBox,
|
|
|
|
|
|
QGridLayout, QGroupBox, QPushButton, QHBoxLayout,
|
|
|
|
|
|
QVBoxLayout, QFormLayout, QSpinBox
|
|
|
|
|
|
)
|
|
|
|
|
|
from PySide6.QtCore import Qt, Signal
|
|
|
|
|
|
|
|
|
|
|
|
class SerialSettingsUI(QWidget):
|
|
|
|
|
|
"""串口设置UI组件"""
|
|
|
|
|
|
|
|
|
|
|
|
# 定义信号
|
|
|
|
|
|
settings_changed = Signal()
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
|
|
super().__init__(parent)
|
|
|
|
|
|
self.init_ui()
|
|
|
|
|
|
|
|
|
|
|
|
def init_ui(self):
|
|
|
|
|
|
"""初始化UI"""
|
|
|
|
|
|
main_layout = QVBoxLayout(self)
|
|
|
|
|
|
|
|
|
|
|
|
# 创建全局启用选项
|
2025-07-07 15:33:56 +08:00
|
|
|
|
enable_layout = QVBoxLayout()
|
|
|
|
|
|
|
|
|
|
|
|
# 第一行:串口功能和键盘监听
|
|
|
|
|
|
enable_row1 = QHBoxLayout()
|
2025-06-12 17:29:35 +08:00
|
|
|
|
self.enable_serial_checkbox = QCheckBox("启用串口功能")
|
2025-07-07 15:33:56 +08:00
|
|
|
|
self.enable_keyboard_checkbox = QCheckBox("启用键盘监听")
|
|
|
|
|
|
enable_row1.addWidget(self.enable_serial_checkbox)
|
|
|
|
|
|
enable_row1.addWidget(self.enable_keyboard_checkbox)
|
|
|
|
|
|
enable_row1.addStretch()
|
|
|
|
|
|
|
|
|
|
|
|
# 第二行:键盘快捷键说明
|
|
|
|
|
|
enable_row2 = QHBoxLayout()
|
|
|
|
|
|
key_info_label = QLabel("键盘快捷键: PageUp 触发米电阻查询")
|
|
|
|
|
|
key_info_label.setStyleSheet("color: #666; font-style: italic;")
|
|
|
|
|
|
enable_row2.addWidget(key_info_label)
|
|
|
|
|
|
enable_row2.addStretch()
|
|
|
|
|
|
|
|
|
|
|
|
# 添加到垂直布局
|
|
|
|
|
|
enable_layout.addLayout(enable_row1)
|
|
|
|
|
|
enable_layout.addLayout(enable_row2)
|
|
|
|
|
|
|
2025-06-12 17:29:35 +08:00
|
|
|
|
main_layout.addLayout(enable_layout)
|
|
|
|
|
|
|
2025-06-30 09:58:16 +08:00
|
|
|
|
# # 创建串口设置组
|
2025-06-12 17:29:35 +08:00
|
|
|
|
serial_group = QGroupBox("串口设置")
|
|
|
|
|
|
serial_layout = QGridLayout(serial_group)
|
|
|
|
|
|
|
|
|
|
|
|
# 米电阻串口设置
|
|
|
|
|
|
mdz_group = QGroupBox("米电阻串口")
|
|
|
|
|
|
mdz_layout = QFormLayout(mdz_group)
|
|
|
|
|
|
|
|
|
|
|
|
# 串口选择
|
|
|
|
|
|
mdz_port_layout = QHBoxLayout()
|
|
|
|
|
|
self.mdz_port_combo = QComboBox()
|
2025-06-30 09:58:16 +08:00
|
|
|
|
self.mdz_port_combo.addItem("不使用", "") # 添加空选项
|
2025-06-12 17:29:35 +08:00
|
|
|
|
self.mdz_refresh_btn = QPushButton("刷新")
|
|
|
|
|
|
mdz_port_layout.addWidget(self.mdz_port_combo)
|
|
|
|
|
|
mdz_port_layout.addWidget(self.mdz_refresh_btn)
|
|
|
|
|
|
mdz_layout.addRow("串口:", mdz_port_layout)
|
|
|
|
|
|
|
|
|
|
|
|
# 波特率
|
|
|
|
|
|
self.mdz_baud_combo = QComboBox()
|
|
|
|
|
|
for baud in ["1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200"]:
|
|
|
|
|
|
self.mdz_baud_combo.addItem(baud)
|
|
|
|
|
|
mdz_layout.addRow("波特率:", self.mdz_baud_combo)
|
|
|
|
|
|
|
|
|
|
|
|
# 数据位
|
|
|
|
|
|
self.mdz_data_bits_combo = QComboBox()
|
|
|
|
|
|
for bits in ["5", "6", "7", "8"]:
|
|
|
|
|
|
self.mdz_data_bits_combo.addItem(bits)
|
|
|
|
|
|
mdz_layout.addRow("数据位:", self.mdz_data_bits_combo)
|
|
|
|
|
|
|
|
|
|
|
|
# 停止位
|
|
|
|
|
|
self.mdz_stop_bits_combo = QComboBox()
|
|
|
|
|
|
for bits in ["1", "1.5", "2"]:
|
|
|
|
|
|
self.mdz_stop_bits_combo.addItem(bits)
|
|
|
|
|
|
mdz_layout.addRow("停止位:", self.mdz_stop_bits_combo)
|
|
|
|
|
|
|
|
|
|
|
|
# 校验位
|
|
|
|
|
|
self.mdz_parity_combo = QComboBox()
|
|
|
|
|
|
for parity in [("无校验", "N"), ("奇校验", "O"), ("偶校验", "E")]:
|
|
|
|
|
|
self.mdz_parity_combo.addItem(parity[0], parity[1])
|
|
|
|
|
|
mdz_layout.addRow("校验位:", self.mdz_parity_combo)
|
|
|
|
|
|
|
|
|
|
|
|
# 查询指令
|
|
|
|
|
|
self.mdz_query_cmd = QLineEdit()
|
|
|
|
|
|
mdz_layout.addRow("查询指令:", self.mdz_query_cmd)
|
|
|
|
|
|
|
|
|
|
|
|
# 查询间隔
|
|
|
|
|
|
self.mdz_query_interval = QSpinBox()
|
|
|
|
|
|
self.mdz_query_interval.setRange(1, 60)
|
|
|
|
|
|
self.mdz_query_interval.setSuffix(" 秒")
|
|
|
|
|
|
mdz_layout.addRow("查询间隔:", self.mdz_query_interval)
|
|
|
|
|
|
|
|
|
|
|
|
# 线径串口设置
|
2025-06-13 09:01:41 +08:00
|
|
|
|
xj_group = QGroupBox("线径串口")
|
|
|
|
|
|
xj_layout = QFormLayout(xj_group)
|
2025-06-12 17:29:35 +08:00
|
|
|
|
|
|
|
|
|
|
# 串口选择
|
2025-06-13 09:01:41 +08:00
|
|
|
|
xj_port_layout = QHBoxLayout()
|
|
|
|
|
|
self.xj_port_combo = QComboBox()
|
2025-06-30 09:58:16 +08:00
|
|
|
|
self.xj_port_combo.addItem("不使用", "") # 添加空选项
|
2025-06-13 09:01:41 +08:00
|
|
|
|
self.xj_refresh_btn = QPushButton("刷新")
|
|
|
|
|
|
xj_port_layout.addWidget(self.xj_port_combo)
|
|
|
|
|
|
xj_port_layout.addWidget(self.xj_refresh_btn)
|
|
|
|
|
|
xj_layout.addRow("串口:", xj_port_layout)
|
2025-06-12 17:29:35 +08:00
|
|
|
|
|
|
|
|
|
|
# 波特率
|
2025-06-13 09:01:41 +08:00
|
|
|
|
self.xj_baud_combo = QComboBox()
|
2025-06-12 17:29:35 +08:00
|
|
|
|
for baud in ["1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200"]:
|
2025-06-13 09:01:41 +08:00
|
|
|
|
self.xj_baud_combo.addItem(baud)
|
|
|
|
|
|
xj_layout.addRow("波特率:", self.xj_baud_combo)
|
2025-06-12 17:29:35 +08:00
|
|
|
|
|
|
|
|
|
|
# 数据位
|
2025-06-13 09:01:41 +08:00
|
|
|
|
self.xj_data_bits_combo = QComboBox()
|
2025-06-12 17:29:35 +08:00
|
|
|
|
for bits in ["5", "6", "7", "8"]:
|
2025-06-13 09:01:41 +08:00
|
|
|
|
self.xj_data_bits_combo.addItem(bits)
|
|
|
|
|
|
xj_layout.addRow("数据位:", self.xj_data_bits_combo)
|
2025-06-12 17:29:35 +08:00
|
|
|
|
|
|
|
|
|
|
# 停止位
|
2025-06-13 09:01:41 +08:00
|
|
|
|
self.xj_stop_bits_combo = QComboBox()
|
2025-06-12 17:29:35 +08:00
|
|
|
|
for bits in ["1", "1.5", "2"]:
|
2025-06-13 09:01:41 +08:00
|
|
|
|
self.xj_stop_bits_combo.addItem(bits)
|
|
|
|
|
|
xj_layout.addRow("停止位:", self.xj_stop_bits_combo)
|
2025-06-12 17:29:35 +08:00
|
|
|
|
|
|
|
|
|
|
# 校验位
|
2025-06-13 09:01:41 +08:00
|
|
|
|
self.xj_parity_combo = QComboBox()
|
2025-06-12 17:29:35 +08:00
|
|
|
|
for parity in [("无校验", "N"), ("奇校验", "O"), ("偶校验", "E")]:
|
2025-06-13 09:01:41 +08:00
|
|
|
|
self.xj_parity_combo.addItem(parity[0], parity[1])
|
|
|
|
|
|
xj_layout.addRow("校验位:", self.xj_parity_combo)
|
2025-06-12 17:29:35 +08:00
|
|
|
|
|
2025-07-07 15:33:56 +08:00
|
|
|
|
# 查询指令
|
|
|
|
|
|
self.xj_query_cmd = QLineEdit()
|
|
|
|
|
|
xj_layout.addRow("查询指令:", self.xj_query_cmd)
|
|
|
|
|
|
|
|
|
|
|
|
# 查询间隔
|
|
|
|
|
|
self.xj_query_interval = QSpinBox()
|
|
|
|
|
|
self.xj_query_interval.setRange(1, 60)
|
|
|
|
|
|
self.xj_query_interval.setSuffix(" 秒")
|
|
|
|
|
|
xj_layout.addRow("查询间隔:", self.xj_query_interval)
|
|
|
|
|
|
|
|
|
|
|
|
# 自动查询
|
|
|
|
|
|
self.xj_auto_query = QCheckBox("启用自动查询")
|
|
|
|
|
|
xj_layout.addRow("", self.xj_auto_query)
|
|
|
|
|
|
|
2025-06-30 09:58:16 +08:00
|
|
|
|
# 扫码器串口设置
|
|
|
|
|
|
scanner_group = QGroupBox("扫码器串口")
|
|
|
|
|
|
scanner_layout = QFormLayout(scanner_group)
|
|
|
|
|
|
|
|
|
|
|
|
# 串口选择
|
|
|
|
|
|
scanner_port_layout = QHBoxLayout()
|
|
|
|
|
|
self.scanner_port_combo = QComboBox()
|
|
|
|
|
|
self.scanner_port_combo.addItem("不使用", "") # 添加空选项
|
|
|
|
|
|
self.scanner_refresh_btn = QPushButton("刷新")
|
|
|
|
|
|
scanner_port_layout.addWidget(self.scanner_port_combo)
|
|
|
|
|
|
scanner_port_layout.addWidget(self.scanner_refresh_btn)
|
|
|
|
|
|
scanner_layout.addRow("串口:", scanner_port_layout)
|
|
|
|
|
|
|
|
|
|
|
|
# 波特率
|
|
|
|
|
|
self.scanner_baud_combo = QComboBox()
|
|
|
|
|
|
for baud in ["1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200"]:
|
|
|
|
|
|
self.scanner_baud_combo.addItem(baud)
|
|
|
|
|
|
scanner_layout.addRow("波特率:", self.scanner_baud_combo)
|
|
|
|
|
|
|
|
|
|
|
|
# 数据位
|
|
|
|
|
|
self.scanner_data_bits_combo = QComboBox()
|
|
|
|
|
|
for bits in ["5", "6", "7", "8"]:
|
|
|
|
|
|
self.scanner_data_bits_combo.addItem(bits)
|
|
|
|
|
|
scanner_layout.addRow("数据位:", self.scanner_data_bits_combo)
|
|
|
|
|
|
|
|
|
|
|
|
# 停止位
|
|
|
|
|
|
self.scanner_stop_bits_combo = QComboBox()
|
|
|
|
|
|
for bits in ["1", "1.5", "2"]:
|
|
|
|
|
|
self.scanner_stop_bits_combo.addItem(bits)
|
|
|
|
|
|
scanner_layout.addRow("停止位:", self.scanner_stop_bits_combo)
|
|
|
|
|
|
|
|
|
|
|
|
# 校验位
|
|
|
|
|
|
self.scanner_parity_combo = QComboBox()
|
|
|
|
|
|
for parity in [("无校验", "N"), ("奇校验", "O"), ("偶校验", "E")]:
|
|
|
|
|
|
self.scanner_parity_combo.addItem(parity[0], parity[1])
|
|
|
|
|
|
scanner_layout.addRow("校验位:", self.scanner_parity_combo)
|
2025-06-12 17:29:35 +08:00
|
|
|
|
|
2025-06-13 09:01:41 +08:00
|
|
|
|
# 将三个组添加到布局
|
2025-06-12 17:29:35 +08:00
|
|
|
|
serial_layout.addWidget(mdz_group, 0, 0)
|
2025-06-13 09:01:41 +08:00
|
|
|
|
serial_layout.addWidget(xj_group, 0, 1)
|
2025-06-30 09:58:16 +08:00
|
|
|
|
serial_layout.addWidget(scanner_group, 1, 0) # 添加扫码器串口设置,放在第二行第一列
|
2025-06-12 17:29:35 +08:00
|
|
|
|
|
|
|
|
|
|
# 设置列伸缩因子,使两列等宽(比例1:1)
|
|
|
|
|
|
serial_layout.setColumnStretch(0, 1)
|
|
|
|
|
|
serial_layout.setColumnStretch(1, 1)
|
|
|
|
|
|
|
|
|
|
|
|
main_layout.addWidget(serial_group)
|
|
|
|
|
|
|
|
|
|
|
|
# 测试按钮
|
|
|
|
|
|
test_layout = QHBoxLayout()
|
|
|
|
|
|
self.test_mdz_btn = QPushButton("测试米电阻串口")
|
2025-06-13 09:01:41 +08:00
|
|
|
|
self.test_xj_btn = QPushButton("测试线径串口")
|
2025-06-30 09:58:16 +08:00
|
|
|
|
self.test_scanner_btn = QPushButton("测试扫码器串口") # 添加测试扫码器串口按钮
|
2025-06-12 17:29:35 +08:00
|
|
|
|
test_layout.addWidget(self.test_mdz_btn)
|
2025-06-13 09:01:41 +08:00
|
|
|
|
test_layout.addWidget(self.test_xj_btn)
|
2025-06-30 09:58:16 +08:00
|
|
|
|
test_layout.addWidget(self.test_scanner_btn) # 添加到布局
|
2025-06-12 17:29:35 +08:00
|
|
|
|
test_layout.addStretch()
|
|
|
|
|
|
main_layout.addLayout(test_layout)
|
|
|
|
|
|
|
|
|
|
|
|
# 保存按钮
|
|
|
|
|
|
button_layout = QHBoxLayout()
|
|
|
|
|
|
self.save_btn = QPushButton("保存设置")
|
|
|
|
|
|
self.save_btn.setStyleSheet("background-color: #e3f2fd; border: 1px solid #2196f3; padding: 8px 16px; font-weight: bold; border-radius: 4px;")
|
|
|
|
|
|
button_layout.addStretch()
|
|
|
|
|
|
button_layout.addWidget(self.save_btn)
|
|
|
|
|
|
main_layout.addLayout(button_layout)
|
|
|
|
|
|
|
|
|
|
|
|
main_layout.addStretch()
|