feat: 在主窗口中新增打印托盘号功能,并优化托盘完成处理逻辑
This commit is contained in:
parent
1af12e3cf2
commit
470c58ace0
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -2,11 +2,11 @@ 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=[212])
|
client.write_registers(address=11, values=[2122])
|
||||||
# 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])
|
||||||
client.write_registers(address=4, values=[0])
|
# client.write_registers(address=4, values=[0])
|
||||||
|
|
||||||
# client.write_registers(address=30, values=[25])
|
# client.write_registers(address=30, values=[25])
|
||||||
# client.write_registers(address=5, values=[16])
|
# client.write_registers(address=5, values=[16])
|
||||||
@ -15,6 +15,6 @@ client.write_registers(address=4, values=[0])
|
|||||||
client.write_registers(address=13, values=[1])
|
client.write_registers(address=13, values=[1])
|
||||||
|
|
||||||
|
|
||||||
result = client.read_holding_registers(address=0, count=1)
|
result = client.read_holding_registers(address=11, count=1)
|
||||||
print(result.registers[0],"123===")
|
print(result.registers[0],"123===")
|
||||||
client.close()
|
client.close()
|
||||||
@ -3354,19 +3354,32 @@ class MainWindow(MainWindowUI):
|
|||||||
""")
|
""")
|
||||||
self.delete_row_button.clicked.connect(self.handle_delete_row)
|
self.delete_row_button.clicked.connect(self.handle_delete_row)
|
||||||
|
|
||||||
# 创建打印按钮
|
# 打印托盘号按钮
|
||||||
|
self.print_tray_button = QPushButton("打印托盘号")
|
||||||
|
self.print_tray_button.setFont(self.normal_font)
|
||||||
|
self.print_tray_button.setStyleSheet("""
|
||||||
|
QPushButton {
|
||||||
|
padding: 5px 8px;
|
||||||
|
background-color: #e3f2fd;
|
||||||
|
border: 1px solid #2196f3;
|
||||||
|
}
|
||||||
|
QPushButton:hover {
|
||||||
|
background-color: #c8e6c9;
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
self.print_tray_button.clicked.connect(lambda: self.handle_tray_complete(ismt=False))
|
||||||
|
|
||||||
|
# 打印选中行按钮
|
||||||
self.print_row_button = QPushButton("打印选中行")
|
self.print_row_button = QPushButton("打印选中行")
|
||||||
self.print_row_button.setFont(self.normal_font)
|
self.print_row_button.setFont(self.normal_font)
|
||||||
self.print_row_button.setStyleSheet("""
|
self.print_row_button.setStyleSheet("""
|
||||||
QPushButton {
|
QPushButton {
|
||||||
padding: 5px 10px;
|
padding: 5px 8px;
|
||||||
background-color: #e3f2fd;
|
background-color: #e0e0e0;
|
||||||
border: 1px solid #2196f3;
|
border: 1px solid #cccccc;
|
||||||
border-radius: 4px;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
}
|
||||||
QPushButton:hover {
|
QPushButton:hover {
|
||||||
background-color: #bbdefb;
|
background-color: #f5f5f5;
|
||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
self.print_row_button.clicked.connect(self.handle_print_row)
|
self.print_row_button.clicked.connect(self.handle_print_row)
|
||||||
@ -3376,6 +3389,7 @@ class MainWindow(MainWindowUI):
|
|||||||
title_layout.addStretch()
|
title_layout.addStretch()
|
||||||
title_layout.addWidget(self.print_row_button)
|
title_layout.addWidget(self.print_row_button)
|
||||||
title_layout.addWidget(self.delete_row_button)
|
title_layout.addWidget(self.delete_row_button)
|
||||||
|
title_layout.addWidget(self.print_tray_button)
|
||||||
|
|
||||||
# 设置容器样式
|
# 设置容器样式
|
||||||
title_container.setFixedHeight(40)
|
title_container.setFixedHeight(40)
|
||||||
@ -3453,26 +3467,29 @@ class MainWindow(MainWindowUI):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def handle_tray_complete(self):
|
def handle_tray_complete(self, ismt=True):
|
||||||
"""处理托盘完成按钮点击事件"""
|
"""托盘完成或打印托盘号事件
|
||||||
|
Args:
|
||||||
|
ismt: 是否满托,True为满托,False为未满托
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
# 获取托盘号
|
# 获取托盘号
|
||||||
tray_id = self.tray_edit.currentText()
|
tray_id = self.tray_edit.currentText()
|
||||||
if not tray_id:
|
if not tray_id:
|
||||||
QMessageBox.warning(self, "提示", "请先选择托盘号")
|
QMessageBox.warning(self, "提示", "请先选择托盘号")
|
||||||
return
|
return
|
||||||
|
if ismt:
|
||||||
# 确认对话框
|
# 确认对话框
|
||||||
reply = QMessageBox.question(
|
reply = QMessageBox.question(
|
||||||
self,
|
self,
|
||||||
"确认完成",
|
"确认完成",
|
||||||
f"确认将托盘 {tray_id} 标记为已满托?",
|
f"确认将托盘 {tray_id} 标记为已满托?",
|
||||||
QMessageBox.Yes | QMessageBox.No,
|
QMessageBox.Yes | QMessageBox.No,
|
||||||
QMessageBox.No
|
QMessageBox.No
|
||||||
)
|
)
|
||||||
|
|
||||||
if reply != QMessageBox.Yes:
|
if reply != QMessageBox.Yes:
|
||||||
return
|
return
|
||||||
|
|
||||||
# 调用接口
|
# 调用接口
|
||||||
from apis.gc_api import GcApi
|
from apis.gc_api import GcApi
|
||||||
@ -3480,7 +3497,7 @@ class MainWindow(MainWindowUI):
|
|||||||
|
|
||||||
# 准备参数
|
# 准备参数
|
||||||
params = {
|
params = {
|
||||||
'ismt': True,
|
'ismt': ismt,
|
||||||
'corp_id': self.corp_id,
|
'corp_id': self.corp_id,
|
||||||
'tray_id': tray_id,
|
'tray_id': tray_id,
|
||||||
'ip': '192.168.1.246'
|
'ip': '192.168.1.246'
|
||||||
@ -3491,8 +3508,12 @@ class MainWindow(MainWindowUI):
|
|||||||
|
|
||||||
# 处理响应
|
# 处理响应
|
||||||
if response.get('status', False):
|
if response.get('status', False):
|
||||||
QMessageBox.information(self, "成功", "托盘已标记为完成")
|
if ismt:
|
||||||
logging.info(f"托盘 {tray_id} 已标记为完成")
|
QMessageBox.information(self, "成功", "托盘已标记为完成")
|
||||||
|
logging.info(f"托盘 {tray_id} 已标记为完成")
|
||||||
|
else:
|
||||||
|
QMessageBox.information(self, "成功", "托盘号已打印")
|
||||||
|
logging.info(f"托盘号 {tray_id} 已打印")
|
||||||
else:
|
else:
|
||||||
error_msg = response.get('message', '未知错误')
|
error_msg = response.get('message', '未知错误')
|
||||||
QMessageBox.warning(self, "失败", f"标记托盘完成失败: {error_msg}")
|
QMessageBox.warning(self, "失败", f"标记托盘完成失败: {error_msg}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user