feat:修复不同输入框获取值方式不一致问题
This commit is contained in:
parent
8b8df295f1
commit
744bc4eb2f
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -2,7 +2,7 @@ from pymodbus.client import ModbusTcpClient
|
|||||||
import time
|
import time
|
||||||
client = ModbusTcpClient('localhost', port=5020)
|
client = ModbusTcpClient('localhost', port=5020)
|
||||||
client.connect()
|
client.connect()
|
||||||
client.write_registers(address=11, values=[2122])
|
client.write_registers(address=11, values=[2222])
|
||||||
# client.write_registers(address=3, values=[0])
|
# client.write_registers(address=3, values=[0])
|
||||||
# time.sleep(2)
|
# time.sleep(2)
|
||||||
# client.write_registers(address=0, values=[0])
|
# client.write_registers(address=0, values=[0])
|
||||||
|
|||||||
@ -27,7 +27,7 @@ from utils.electricity_monitor import ElectricityHandler
|
|||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QWidget, QMessageBox, QTableWidgetItem, QStackedWidget, QLabel,
|
QWidget, QMessageBox, QTableWidgetItem, QStackedWidget, QLabel,
|
||||||
QTableWidget, QMenu, QComboBox, QFormLayout, QDialog, QVBoxLayout,
|
QTableWidget, QMenu, QComboBox, QFormLayout, QDialog, QVBoxLayout,
|
||||||
QFrame, QHBoxLayout, QSplitter, QPushButton
|
QFrame, QHBoxLayout, QSplitter, QPushButton, QTextEdit
|
||||||
)
|
)
|
||||||
from PySide6.QtCore import Qt, QTimer, Slot, Signal
|
from PySide6.QtCore import Qt, QTimer, Slot, Signal
|
||||||
from PySide6.QtGui import QBrush, QColor
|
from PySide6.QtGui import QBrush, QColor
|
||||||
@ -739,7 +739,11 @@ class MainWindow(MainWindowUI):
|
|||||||
for field_name, label in self.info_values.items():
|
for field_name, label in self.info_values.items():
|
||||||
order_info_key = self.FIELD_MAPPING.get(field_name)
|
order_info_key = self.FIELD_MAPPING.get(field_name)
|
||||||
if order_info_key:
|
if order_info_key:
|
||||||
order_info[order_info_key] = label.text()
|
# 根据控件类型选择合适的方法获取文本
|
||||||
|
if isinstance(label, QTextEdit):
|
||||||
|
order_info[order_info_key] = label.toPlainText()
|
||||||
|
else:
|
||||||
|
order_info[order_info_key] = label.text()
|
||||||
# 更新/补充 qd 字段
|
# 更新/补充 qd 字段
|
||||||
order_info["qd"] = self._current_gc_qd
|
order_info["qd"] = self._current_gc_qd
|
||||||
# 再调用 update_info_table
|
# 再调用 update_info_table
|
||||||
@ -3588,7 +3592,11 @@ class MainWindow(MainWindowUI):
|
|||||||
tqd = order_info.get("tqd")
|
tqd = order_info.get("tqd")
|
||||||
if bqd is not None and tqd is not None:
|
if bqd is not None and tqd is not None:
|
||||||
value = f"{bqd} - {tqd}"
|
value = f"{bqd} - {tqd}"
|
||||||
self.info_values[field_name].setText(value)
|
# 根据控件类型选择合适的方法设置文本
|
||||||
|
if isinstance(self.info_values[field_name], QTextEdit):
|
||||||
|
self.info_values[field_name].setPlainText(value)
|
||||||
|
else:
|
||||||
|
self.info_values[field_name].setText(value)
|
||||||
else:
|
else:
|
||||||
logging.warning(f"字段名 '{field_name}' 在info_values中不存在")
|
logging.warning(f"字段名 '{field_name}' 在info_values中不存在")
|
||||||
|
|
||||||
@ -3603,16 +3611,6 @@ class MainWindow(MainWindowUI):
|
|||||||
def handle_print_row(self):
|
def handle_print_row(self):
|
||||||
"""处理打印按钮点击事件,打印选中的微丝产线表格行"""
|
"""处理打印按钮点击事件,打印选中的微丝产线表格行"""
|
||||||
try:
|
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(
|
reply = QMessageBox.question(
|
||||||
@ -3626,21 +3624,6 @@ class MainWindow(MainWindowUI):
|
|||||||
if reply != QMessageBox.Yes:
|
if reply != QMessageBox.Yes:
|
||||||
return
|
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,触发打印
|
# 向D12寄存器写入1,触发打印
|
||||||
from utils.modbus_utils import ModbusUtils
|
from utils.modbus_utils import ModbusUtils
|
||||||
@ -3655,7 +3638,7 @@ class MainWindow(MainWindowUI):
|
|||||||
# 向D12寄存器写入1,表示打印请求
|
# 向D12寄存器写入1,表示打印请求
|
||||||
success = modbus.write_register(client, 12, 1)
|
success = modbus.write_register(client, 12, 1)
|
||||||
if success:
|
if success:
|
||||||
logging.info(f"已向D12寄存器写入1,触发打印工程号 {gc_note} 的数据")
|
logging.info(f"已向D12寄存器写入1")
|
||||||
else:
|
else:
|
||||||
QMessageBox.warning(self, "警告", "发送打印请求失败,请检查PLC连接")
|
QMessageBox.warning(self, "警告", "发送打印请求失败,请检查PLC连接")
|
||||||
finally:
|
finally:
|
||||||
@ -3727,12 +3710,14 @@ class MainWindow(MainWindowUI):
|
|||||||
def _log_focus_widget_info(self, widget):
|
def _log_focus_widget_info(self, widget):
|
||||||
"""记录当前焦点控件的信息,用于调试"""
|
"""记录当前焦点控件的信息,用于调试"""
|
||||||
try:
|
try:
|
||||||
from PySide6.QtWidgets import QLineEdit, QComboBox
|
from PySide6.QtWidgets import QLineEdit, QComboBox, QTextEdit
|
||||||
widget_type = "未知"
|
widget_type = "未知"
|
||||||
if isinstance(widget, QLineEdit):
|
if isinstance(widget, QLineEdit):
|
||||||
widget_type = "输入框"
|
widget_type = "输入框"
|
||||||
elif isinstance(widget, QComboBox):
|
elif isinstance(widget, QComboBox):
|
||||||
widget_type = "下拉框"
|
widget_type = "下拉框"
|
||||||
|
elif isinstance(widget, QTextEdit):
|
||||||
|
widget_type = "文本编辑框"
|
||||||
|
|
||||||
widget_name = widget.objectName() if widget else "无"
|
widget_name = widget.objectName() if widget else "无"
|
||||||
widget_text = ""
|
widget_text = ""
|
||||||
@ -3741,6 +3726,8 @@ class MainWindow(MainWindowUI):
|
|||||||
widget_text = widget.text()
|
widget_text = widget.text()
|
||||||
elif isinstance(widget, QComboBox):
|
elif isinstance(widget, QComboBox):
|
||||||
widget_text = widget.currentText()
|
widget_text = widget.currentText()
|
||||||
|
elif isinstance(widget, QTextEdit):
|
||||||
|
widget_text = widget.toPlainText()
|
||||||
|
|
||||||
logging.info(f"当前焦点控件: 类型={widget_type}, 名称={widget_name}, 文本={widget_text}")
|
logging.info(f"当前焦点控件: 类型={widget_type}, 名称={widget_name}, 文本={widget_text}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user