feat: 新增按钮贴标功能

This commit is contained in:
zhu-mengmeng 2025-07-17 09:34:33 +08:00
parent 397c7398c8
commit 38f0062308
3 changed files with 94 additions and 4 deletions

View File

@ -116,7 +116,7 @@
}
},
"electricity": {
"auto_start": false,
"auto_start": true,
"interval_minutes": 30
}
}

Binary file not shown.

View File

@ -2090,6 +2090,12 @@ class MainWindow(MainWindowUI):
self.process_table.removeRow(data_row)
logging.info(f"已删除处理完成的行 {data_row}")
# 复原寄存器 12 为 0
modbus = ModbusUtils()
client = modbus.get_client()
modbus.write_register_until_success(client, 12, 0)
modbus.close_client(client)
# 重新连接单元格变更信号
self.process_table.cellChanged.connect(self.handle_inspection_cell_changed)
@ -3221,9 +3227,27 @@ class MainWindow(MainWindowUI):
""")
self.delete_row_button.clicked.connect(self.handle_delete_row)
# 创建打印按钮
self.print_row_button = QPushButton("打印选中行")
self.print_row_button.setFont(self.normal_font)
self.print_row_button.setStyleSheet("""
QPushButton {
padding: 5px 10px;
background-color: #e3f2fd;
border: 1px solid #2196f3;
border-radius: 4px;
font-weight: bold;
}
QPushButton:hover {
background-color: #bbdefb;
}
""")
self.print_row_button.clicked.connect(self.handle_print_row)
# 将标题和按钮添加到布局中
title_layout.addWidget(self.process_title)
title_layout.addStretch()
title_layout.addWidget(self.print_row_button)
title_layout.addWidget(self.delete_row_button)
# 设置容器样式
@ -3399,3 +3423,69 @@ class MainWindow(MainWindowUI):
# 记录异常堆栈,便于调试
import traceback
logging.error(traceback.format_exc())
def handle_print_row(self):
"""处理打印按钮点击事件,打印选中的微丝产线表格行"""
try:
# 获取当前选中的行
selected_rows = self.process_table.selectionModel().selectedRows()
if not selected_rows:
# 如果没有选中整行,则获取当前选中的单元格所在行
current_row = self.process_table.currentRow()
if current_row >= 2: # 确保不是表头行
selected_rows = [self.process_table.model().index(current_row, 0)]
else:
QMessageBox.warning(self, "提示", "请先选择要打印的数据行")
return
# 确认打印
reply = QMessageBox.question(
self,
"确认打印",
"确定要打印选中的数据吗?",
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No
)
if reply != QMessageBox.Yes:
return
# 获取选中的行索引(只处理第一个选中的行)
row = selected_rows[0].row()
if row < 2: # 跳过表头行
return
# 获取工程号(用于日志记录)
gc_note_item = self.process_table.item(row, 1)
if not gc_note_item:
QMessageBox.warning(self, "提示", "无法获取工程号信息")
return
gc_note = gc_note_item.text().strip()
if not gc_note:
QMessageBox.warning(self, "提示", "工程号不能为空")
return
# 向D12寄存器写入1触发打印
from utils.modbus_utils import ModbusUtils
modbus = ModbusUtils()
client = modbus.get_client()
if not client:
QMessageBox.critical(self, "错误", "无法连接到Modbus服务器")
return
try:
# 向D12寄存器写入1表示打印请求
success = modbus.write_register(client, 12, 1)
if success:
logging.info(f"已向D12寄存器写入1触发打印工程号 {gc_note} 的数据")
else:
QMessageBox.warning(self, "警告", "发送打印请求失败请检查PLC连接")
finally:
# 释放客户端连接
modbus.close_client(client)
except Exception as e:
logging.error(f"打印数据失败: {str(e)}")
QMessageBox.critical(self, "错误", f"打印数据失败: {str(e)}")