feat: 更新托盘信息获取逻辑,修改托盘料字段名称,优化加载对话框和主窗口托盘号处理,添加了 API 和本地数据源的支持
This commit is contained in:
parent
507a345d43
commit
c091a55cb0
@ -60,7 +60,7 @@ class TaryApi:
|
||||
"tp_note": tray_info.get("tp_note", ""), # 托盘号
|
||||
"product_name": tray_info.get("zx_name", ""), # 产品名称
|
||||
"axis_type": tray_info.get("zx", ""), # 轴型
|
||||
"material": str(tray_info.get("cs", "")), # 托盘料
|
||||
"tier": str(tray_info.get("cs", "")), # 托盘料
|
||||
"weight": str(tray_info.get("zl", "")), # 重量
|
||||
"quantity": "" # 数量先空下
|
||||
}
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
"enable_keyboard_listener": false,
|
||||
"enable_camera": false
|
||||
},
|
||||
"base_url":"http://192.168.0.133:8080"
|
||||
"base_url": "http://localhost:8084",
|
||||
"mode": "standalone"
|
||||
},
|
||||
"apis": {
|
||||
"get_tray_info": "/apjt/xcsc/tpda/getByTp_note/"
|
||||
@ -47,10 +48,11 @@
|
||||
"host": "localhost",
|
||||
"port": "5020"
|
||||
},
|
||||
"serial":{
|
||||
"keyboard":{
|
||||
"trigger_key":"Key.page_up"
|
||||
},"mdz":{
|
||||
"serial": {
|
||||
"keyboard": {
|
||||
"trigger_key": "Key.page_up"
|
||||
},
|
||||
"mdz": {
|
||||
"bit": 10,
|
||||
"code": "mdz",
|
||||
"data_bits": 8,
|
||||
@ -61,7 +63,8 @@
|
||||
"ser": "COM5",
|
||||
"stop_bits": 1,
|
||||
"timeout": 1
|
||||
},"cz":{
|
||||
},
|
||||
"cz": {
|
||||
"bit": 10,
|
||||
"code": "cz",
|
||||
"data_bits": 8,
|
||||
|
||||
@ -14,53 +14,20 @@ class PalletTypeDAO:
|
||||
if hasattr(self, 'db'):
|
||||
self.db.close()
|
||||
|
||||
def get_all_pallet_types(self, include_disabled=False):
|
||||
"""获取所有托盘类型
|
||||
|
||||
Args:
|
||||
include_disabled: 是否包含禁用的类型
|
||||
|
||||
Returns:
|
||||
list: 托盘类型列表
|
||||
"""
|
||||
def get_pallet_code(self):
|
||||
"""获取托盘号"""
|
||||
try:
|
||||
if include_disabled:
|
||||
sql = """
|
||||
SELECT id, type_name, operation_type, description, enabled, sort_order
|
||||
FROM wsbz_pallet_types
|
||||
sql = """
|
||||
SELECT DISTINCT pallet_code
|
||||
FROM wsbz_pallet_archives
|
||||
WHERE is_deleted = FALSE
|
||||
ORDER BY sort_order
|
||||
"""
|
||||
params = ()
|
||||
else:
|
||||
sql = """
|
||||
SELECT id, type_name, operation_type, description, enabled, sort_order
|
||||
FROM wsbz_pallet_types
|
||||
WHERE is_deleted = FALSE AND enabled = TRUE
|
||||
ORDER BY sort_order
|
||||
"""
|
||||
params = ()
|
||||
|
||||
self.db.cursor.execute(sql, params)
|
||||
"""
|
||||
self.db.cursor.execute(sql)
|
||||
results = self.db.cursor.fetchall()
|
||||
|
||||
pallet_types = []
|
||||
for row in results:
|
||||
pallet_type = {
|
||||
'id': row[0],
|
||||
'type_name': row[1],
|
||||
'operation_type': row[2],
|
||||
'description': row[3],
|
||||
'enabled': bool(row[4]),
|
||||
'sort_order': row[5]
|
||||
}
|
||||
pallet_types.append(pallet_type)
|
||||
|
||||
return pallet_types
|
||||
return [row[0] for row in results]
|
||||
except Exception as e:
|
||||
logging.error(f"获取托盘类型失败: {str(e)}")
|
||||
logging.error(f"获取托盘号失败: {str(e)}")
|
||||
return []
|
||||
|
||||
def get_pallet_type_by_pallet_id(self, pallet_code):
|
||||
"""根据托盘号获取托盘类型
|
||||
|
||||
@ -84,7 +51,37 @@ class PalletTypeDAO:
|
||||
except Exception as e:
|
||||
logging.error(f"获取托盘类型失败: {str(e)}")
|
||||
return None
|
||||
def get_pallet_info_by_pallet_id(self, pallet_code):
|
||||
"""根据托盘号获取托盘信息
|
||||
|
||||
Args:
|
||||
pallet_code: 托盘号
|
||||
|
||||
Returns:
|
||||
dict: 托盘信息,未找到则返回None
|
||||
"""
|
||||
try:
|
||||
sql = """
|
||||
SELECT pallet_code,
|
||||
pallet_name,
|
||||
description,
|
||||
axios_name,
|
||||
axios_type,
|
||||
tier,
|
||||
size,
|
||||
amount,
|
||||
weight
|
||||
FROM wsbz_pallet_archives t1
|
||||
WHERE pallet_code = ? AND t1.is_deleted = FALSE
|
||||
"""
|
||||
params = (pallet_code,)
|
||||
self.db.cursor.execute(sql, params)
|
||||
row = self.db.cursor.fetchone()
|
||||
if row:
|
||||
return row
|
||||
except Exception as e:
|
||||
logging.error(f"获取托盘类型失败: {str(e)}")
|
||||
return None
|
||||
def get_pallet_types_by_operation(self, operation_type, include_disabled=False):
|
||||
"""根据操作类型获取托盘类型
|
||||
|
||||
|
||||
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -9,7 +9,7 @@ class LoadingDialogUI(QDialog):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("上料操作")
|
||||
self.setFixedSize(600, 300)
|
||||
self.setFixedSize(600, 250)
|
||||
|
||||
# 设置字体
|
||||
self.normal_font = QFont("微软雅黑", 12)
|
||||
@ -87,43 +87,6 @@ class LoadingDialogUI(QDialog):
|
||||
row1 = QHBoxLayout()
|
||||
row1.setSpacing(0)
|
||||
|
||||
order_layout = QHBoxLayout()
|
||||
order_layout.setSpacing(0)
|
||||
self.order_label = QLabel("订单号")
|
||||
self.order_label.setFont(self.normal_font)
|
||||
self.order_label.setStyleSheet(label_style)
|
||||
self.order_label.setFixedWidth(100)
|
||||
self.order_label.setFixedHeight(45)
|
||||
|
||||
self.order_input = QLineEdit()
|
||||
self.order_input.setFont(self.normal_font)
|
||||
self.order_input.setPlaceholderText("请扫描订单号")
|
||||
self.order_input.setStyleSheet(input_style)
|
||||
self.order_input.setFixedHeight(45)
|
||||
|
||||
order_layout.addWidget(self.order_label)
|
||||
order_layout.addWidget(self.order_input, 1)
|
||||
|
||||
product_layout = QHBoxLayout()
|
||||
product_layout.setSpacing(0)
|
||||
self.product_label = QLabel("产品")
|
||||
self.product_label.setFont(self.normal_font)
|
||||
self.product_label.setStyleSheet(label_style)
|
||||
self.product_label.setFixedWidth(100)
|
||||
self.product_label.setFixedHeight(45)
|
||||
|
||||
self.product_value = QLabel("")
|
||||
self.product_value.setFont(self.normal_font)
|
||||
self.product_value.setStyleSheet(value_style)
|
||||
self.product_value.setFixedHeight(45)
|
||||
|
||||
product_layout.addWidget(self.product_label)
|
||||
product_layout.addWidget(self.product_value, 1)
|
||||
|
||||
row1.addLayout(order_layout, 1)
|
||||
row1.addLayout(product_layout, 1)
|
||||
container_layout.addLayout(row1)
|
||||
|
||||
# 第二行:托盘号
|
||||
row2 = QHBoxLayout()
|
||||
row2.setSpacing(0)
|
||||
@ -164,24 +127,24 @@ class LoadingDialogUI(QDialog):
|
||||
axis_layout.addWidget(self.axis_label)
|
||||
axis_layout.addWidget(self.axis_value, 1)
|
||||
|
||||
material_layout = QHBoxLayout()
|
||||
material_layout.setSpacing(0)
|
||||
self.pallet_material_label = QLabel("托盘料")
|
||||
self.pallet_material_label.setFont(self.normal_font)
|
||||
self.pallet_material_label.setStyleSheet(label_style)
|
||||
self.pallet_material_label.setFixedWidth(100)
|
||||
self.pallet_material_label.setFixedHeight(40)
|
||||
tier_layout = QHBoxLayout()
|
||||
tier_layout.setSpacing(0)
|
||||
self.pallet_tier_label = QLabel("托盘料")
|
||||
self.pallet_tier_label.setFont(self.normal_font)
|
||||
self.pallet_tier_label.setStyleSheet(label_style)
|
||||
self.pallet_tier_label.setFixedWidth(100)
|
||||
self.pallet_tier_label.setFixedHeight(40)
|
||||
|
||||
self.pallet_material_value = QLabel("--")
|
||||
self.pallet_material_value.setFont(self.normal_font)
|
||||
self.pallet_material_value.setStyleSheet(value_style)
|
||||
self.pallet_material_value.setFixedHeight(40)
|
||||
self.pallet_tier_value = QLabel("--")
|
||||
self.pallet_tier_value.setFont(self.normal_font)
|
||||
self.pallet_tier_value.setStyleSheet(value_style)
|
||||
self.pallet_tier_value.setFixedHeight(40)
|
||||
|
||||
material_layout.addWidget(self.pallet_material_label)
|
||||
material_layout.addWidget(self.pallet_material_value, 1)
|
||||
tier_layout.addWidget(self.pallet_tier_label)
|
||||
tier_layout.addWidget(self.pallet_tier_value, 1)
|
||||
|
||||
row3.addLayout(axis_layout, 1)
|
||||
row3.addLayout(material_layout, 1)
|
||||
row3.addLayout(tier_layout, 1)
|
||||
container_layout.addLayout(row3)
|
||||
|
||||
# 第四行:数量和重量
|
||||
|
||||
@ -223,12 +223,9 @@ class MainWindowUI(QMainWindow):
|
||||
self.tray_edit.setMaxVisibleItems(10) # 设置下拉框最多显示10个项目
|
||||
self.tray_edit.completer().setCaseSensitivity(Qt.CaseInsensitive) # 设置补全不区分大小写
|
||||
self.tray_edit.completer().setFilterMode(Qt.MatchContains) # 设置模糊匹配模式
|
||||
self.tray_edit.addItem("托盘1")
|
||||
self.tray_edit.addItem("托盘2")
|
||||
self.tray_edit.addItem("托盘3")
|
||||
self.tray_edit.addItem("托盘4")
|
||||
self.tray_edit.addItem("托盘5")
|
||||
self.tray_edit.addItem("托盘6")
|
||||
# 允许清空选择
|
||||
self.tray_edit.setCurrentText("")
|
||||
|
||||
self.tray_layout.addWidget(self.tray_edit)
|
||||
|
||||
self.left_layout.addWidget(self.tray_frame)
|
||||
|
||||
@ -123,24 +123,24 @@ class UnloadingDialogUI(QDialog):
|
||||
axis_layout.addWidget(self.axis_label)
|
||||
axis_layout.addWidget(self.axis_value, 1)
|
||||
|
||||
material_layout = QHBoxLayout()
|
||||
material_layout.setSpacing(0)
|
||||
self.pallet_material_label = QLabel("托盘料")
|
||||
self.pallet_material_label.setFont(self.normal_font)
|
||||
self.pallet_material_label.setStyleSheet(label_style)
|
||||
self.pallet_material_label.setFixedWidth(100)
|
||||
self.pallet_material_label.setFixedHeight(40)
|
||||
tier_layout = QHBoxLayout()
|
||||
tier_layout.setSpacing(0)
|
||||
self.pallet_tier_label = QLabel("托盘料")
|
||||
self.pallet_tier_label.setFont(self.normal_font)
|
||||
self.pallet_tier_label.setStyleSheet(label_style)
|
||||
self.pallet_tier_label.setFixedWidth(100)
|
||||
self.pallet_tier_label.setFixedHeight(40)
|
||||
|
||||
self.pallet_material_value = QLabel("--")
|
||||
self.pallet_material_value.setFont(self.normal_font)
|
||||
self.pallet_material_value.setStyleSheet(value_style)
|
||||
self.pallet_material_value.setFixedHeight(40)
|
||||
self.pallet_tier_value = QLabel("--")
|
||||
self.pallet_tier_value.setFont(self.normal_font)
|
||||
self.pallet_tier_value.setStyleSheet(value_style)
|
||||
self.pallet_tier_value.setFixedHeight(40)
|
||||
|
||||
material_layout.addWidget(self.pallet_material_label)
|
||||
material_layout.addWidget(self.pallet_material_value, 1)
|
||||
tier_layout.addWidget(self.pallet_tier_label)
|
||||
tier_layout.addWidget(self.pallet_tier_value, 1)
|
||||
|
||||
row2.addLayout(axis_layout, 1)
|
||||
row2.addLayout(material_layout, 1)
|
||||
row2.addLayout(tier_layout, 1)
|
||||
container_layout.addLayout(row2)
|
||||
|
||||
# 第三行:数量和重量
|
||||
|
||||
@ -17,31 +17,8 @@ class PalletTypeManager:
|
||||
"""初始化托盘类型管理器"""
|
||||
self.dao = PalletTypeDAO()
|
||||
self.pallet_types = []
|
||||
self.reload_pallet_types()
|
||||
|
||||
def reload_pallet_types(self):
|
||||
"""重新加载托盘类型"""
|
||||
try:
|
||||
self.pallet_types = self.dao.get_all_pallet_types(include_disabled=True)
|
||||
logging.info(f"已加载{len(self.pallet_types)}个托盘类型")
|
||||
return True
|
||||
except Exception as e:
|
||||
logging.error(f"加载托盘类型失败: {str(e)}")
|
||||
return False
|
||||
|
||||
def get_all_pallet_types(self, include_disabled=False):
|
||||
"""获取所有托盘类型
|
||||
|
||||
Args:
|
||||
include_disabled: 是否包含禁用的类型
|
||||
|
||||
Returns:
|
||||
list: 托盘类型列表
|
||||
"""
|
||||
if include_disabled:
|
||||
return self.pallet_types
|
||||
else:
|
||||
return [pallet_type for pallet_type in self.pallet_types if pallet_type['enabled']]
|
||||
|
||||
def get_pallet_types_by_operation(self, operation_type, include_disabled=False):
|
||||
"""根据操作类型获取托盘类型
|
||||
@ -210,3 +187,22 @@ class PalletTypeManager:
|
||||
return result
|
||||
else:
|
||||
return None
|
||||
# 获取托盘号
|
||||
def get_pallet_code(self):
|
||||
"""获取托盘号"""
|
||||
result = self.dao.get_pallet_code()
|
||||
if result:
|
||||
return result
|
||||
else:
|
||||
return None
|
||||
def get_pallet_info_by_pallet_id(self, pallet_code):
|
||||
"""根据托盘号获取托盘信息
|
||||
|
||||
Args:
|
||||
pallet_code: 托盘号
|
||||
"""
|
||||
result = self.dao.get_pallet_info_by_pallet_id(pallet_code)
|
||||
if result:
|
||||
return result
|
||||
else:
|
||||
return None
|
||||
@ -3,7 +3,8 @@ from apis.tary_api import TaryApi
|
||||
from PySide6.QtCore import Qt, Signal
|
||||
from PySide6.QtWidgets import QMessageBox, QDialog
|
||||
import logging
|
||||
|
||||
from utils.app_mode import AppMode
|
||||
from utils.pallet_type_manager import PalletTypeManager
|
||||
class LoadingDialog(LoadingDialogUI):
|
||||
# 定义一个信号,用于向主窗口传递托盘号
|
||||
tray_code_signal = Signal(str, str, str, str)
|
||||
@ -13,9 +14,6 @@ class LoadingDialog(LoadingDialogUI):
|
||||
super().__init__()
|
||||
self.parent = parent
|
||||
|
||||
# 初始化API
|
||||
self.tary_api = TaryApi()
|
||||
|
||||
# 彻底禁用对话框的回车键关闭功能
|
||||
self.setModal(True)
|
||||
# 禁用所有按钮的默认行为
|
||||
@ -34,7 +32,8 @@ class LoadingDialog(LoadingDialogUI):
|
||||
"""设置事件连接"""
|
||||
# 托盘号输入框回车事件触发查询
|
||||
self.tray_input.returnPressed.connect(self.handle_tray_return_pressed)
|
||||
self.tray_input.editingFinished.connect(self.on_tray_query)
|
||||
# 移除editingFinished事件,避免重复触发查询
|
||||
# self.tray_input.editingFinished.connect(self.on_tray_query)
|
||||
|
||||
# 确认按钮点击事件
|
||||
self.confirm_button.clicked.connect(self.accept)
|
||||
@ -59,9 +58,36 @@ class LoadingDialog(LoadingDialogUI):
|
||||
return
|
||||
|
||||
logging.info(f"查询托盘号: {tray_code}")
|
||||
if AppMode.is_api():
|
||||
self.tary_api = TaryApi()
|
||||
# 调用API获取托盘信息
|
||||
response = self.tary_api.get_tary_info(tray_code)
|
||||
else:
|
||||
pallet_type_manager = PalletTypeManager.get_instance()
|
||||
pallet_info = pallet_type_manager.get_pallet_info_by_pallet_id(tray_code)
|
||||
|
||||
# 检查返回的数据类型并进行适当处理
|
||||
if pallet_info is None:
|
||||
response = {
|
||||
"success": False,
|
||||
"message": "未找到托盘信息"
|
||||
}
|
||||
else:
|
||||
# 如果返回的是元组(数据库查询结果),将其转换为字典
|
||||
# 根据dao/pallet_type_dao.py中get_pallet_info_by_pallet_id方法的SQL查询
|
||||
# 返回的字段顺序为:pallet_code, pallet_name, description, axios_name, axios_type, tier, size, amount, weight
|
||||
response = {
|
||||
"success": True,
|
||||
"data": {
|
||||
"tp_note": pallet_info[0] if len(pallet_info) > 0 else "",
|
||||
"product_name": pallet_info[1] if len(pallet_info) > 1 else "",
|
||||
"axis_type": pallet_info[4] if len(pallet_info) > 4 else "",
|
||||
"tier": str(pallet_info[5]) if len(pallet_info) > 5 else "",
|
||||
"weight": str(pallet_info[8]) if len(pallet_info) > 8 else "",
|
||||
"quantity": ""
|
||||
}
|
||||
}
|
||||
|
||||
# 调用API获取托盘信息
|
||||
response = self.tary_api.get_tary_info(tray_code)
|
||||
|
||||
logging.info(f"托盘信息响应: {response}")
|
||||
logging.info(f"response.success={response.get('success')}, response.data存在={response.get('data') is not None}")
|
||||
@ -72,20 +98,17 @@ class LoadingDialog(LoadingDialogUI):
|
||||
|
||||
# 显示托盘相关信息 - 只更新轴型、托盘料和重量,不更新订单号和产品
|
||||
axis_type = str(tray_data.get("axis_type", "--"))
|
||||
material = str(tray_data.get("material", "--"))
|
||||
tier = str(tray_data.get("tier", "--"))
|
||||
weight = str(tray_data.get("weight", "--"))
|
||||
|
||||
logging.info(f"显示托盘信息: 轴型={axis_type}, 托盘料={material}, 重量={weight}")
|
||||
logging.info(f"显示托盘信息: 轴型={axis_type}, 托盘料={tier}, 重量={weight}")
|
||||
|
||||
# 只设置轴型、托盘料和重量字段,不设置产品名称
|
||||
self.axis_value.setText(axis_type)
|
||||
self.pallet_material_value.setText(material)
|
||||
self.pallet_tier_value.setText(tier)
|
||||
self.quantity_value.setText("") # 数量为空
|
||||
self.weight_value.setText(f"{weight} kg")
|
||||
|
||||
# 不再根据托盘号设置订单号
|
||||
# self.order_input.setText(tray_code)
|
||||
|
||||
# 发送托盘号到主窗口
|
||||
from widgets.main_window import MainWindow
|
||||
main_window = self.parent
|
||||
@ -106,8 +129,6 @@ class LoadingDialog(LoadingDialogUI):
|
||||
main_window.tray_edit.setCurrentText(tray_code)
|
||||
logging.info(f"设置主窗口当前托盘号: {tray_code}")
|
||||
|
||||
# 成功获取信息后,将焦点设置到订单号输入框上
|
||||
self.order_input.setFocus()
|
||||
else:
|
||||
# 获取托盘信息失败
|
||||
error_msg = response.get("message", "获取托盘信息失败")
|
||||
@ -124,8 +145,9 @@ class LoadingDialog(LoadingDialogUI):
|
||||
logging.info(f"捕获到回车键事件,当前焦点部件: {self.focusWidget()}")
|
||||
|
||||
# 如果焦点在托盘输入框上,触发查询
|
||||
# 注释掉此处的on_tray_query调用,因为已经通过returnPressed信号处理了
|
||||
if self.focusWidget() == self.tray_input:
|
||||
self.on_tray_query()
|
||||
# self.on_tray_query() - 通过returnPressed信号已经处理,这里不需要再调用
|
||||
event.accept() # 消费掉这个事件
|
||||
return
|
||||
|
||||
|
||||
@ -124,8 +124,8 @@ class MainWindow(MainWindowUI):
|
||||
# 设置中央部件为堆叠部件
|
||||
self.setCentralWidget(self.stacked_widget)
|
||||
|
||||
# 添加托盘类型选择下拉框
|
||||
self.add_pallet_type_selectors()
|
||||
# # 添加托盘类型选择下拉框
|
||||
# self.add_pallet_type_selectors()
|
||||
|
||||
# 连接信号和槽
|
||||
self.connect_signals()
|
||||
@ -170,49 +170,52 @@ class MainWindow(MainWindowUI):
|
||||
# 注册串口数据回调函数
|
||||
self.register_serial_callbacks()
|
||||
|
||||
def add_pallet_type_selectors(self):
|
||||
"""添加托盘类型选择下拉框"""
|
||||
# 创建上料托盘类型选择下拉框
|
||||
self.input_pallet_type_label = QLabel("上料托盘类型:")
|
||||
self.input_pallet_type_label.setFont(self.normal_font)
|
||||
self.input_pallet_type_label.setVisible(False)
|
||||
self.material_form_layout.addRow(self.input_pallet_type_label)
|
||||
# 加载托盘号列表
|
||||
self.load_pallet_codes()
|
||||
|
||||
self.input_pallet_type_combo = QComboBox()
|
||||
self.input_pallet_type_combo.setFont(self.normal_font)
|
||||
self.input_pallet_type_combo.setVisible(False)
|
||||
self.material_form_layout.addRow("", self.input_pallet_type_combo)
|
||||
# def add_pallet_type_selectors(self):
|
||||
# """添加托盘类型选择下拉框"""
|
||||
# # 创建上料托盘类型选择下拉框
|
||||
# self.input_pallet_type_label = QLabel("上料托盘类型:")
|
||||
# self.input_pallet_type_label.setFont(self.normal_font)
|
||||
# self.input_pallet_type_label.setVisible(False)
|
||||
# self.material_form_layout.addRow(self.input_pallet_type_label)
|
||||
|
||||
# 创建下料托盘类型选择下拉框
|
||||
self.output_pallet_type_label = QLabel("下料托盘类型:")
|
||||
self.output_pallet_type_label.setFont(self.normal_font)
|
||||
self.output_pallet_type_label.setVisible(False)
|
||||
self.output_form_layout.addRow(self.output_pallet_type_label)
|
||||
# self.input_pallet_type_combo = QComboBox()
|
||||
# self.input_pallet_type_combo.setFont(self.normal_font)
|
||||
# self.input_pallet_type_combo.setVisible(False)
|
||||
# self.material_form_layout.addRow("", self.input_pallet_type_combo)
|
||||
|
||||
self.output_pallet_type_combo = QComboBox()
|
||||
self.output_pallet_type_combo.setFont(self.normal_font)
|
||||
self.output_pallet_type_combo.setVisible(False)
|
||||
self.output_form_layout.addRow("", self.output_pallet_type_combo)
|
||||
# # 创建下料托盘类型选择下拉框
|
||||
# self.output_pallet_type_label = QLabel("下料托盘类型:")
|
||||
# self.output_pallet_type_label.setFont(self.normal_font)
|
||||
# self.output_pallet_type_label.setVisible(False)
|
||||
# self.output_form_layout.addRow(self.output_pallet_type_label)
|
||||
|
||||
# 加载托盘类型数据
|
||||
self.update_pallet_types()
|
||||
# self.output_pallet_type_combo = QComboBox()
|
||||
# self.output_pallet_type_combo.setFont(self.normal_font)
|
||||
# self.output_pallet_type_combo.setVisible(False)
|
||||
# self.output_form_layout.addRow("", self.output_pallet_type_combo)
|
||||
|
||||
def update_pallet_types(self):
|
||||
"""更新托盘类型下拉框"""
|
||||
# 重新加载托盘类型数据
|
||||
self.pallet_type_manager.reload_pallet_types()
|
||||
# # 加载托盘类型数据
|
||||
# self.update_pallet_types()
|
||||
|
||||
# 更新上料托盘类型
|
||||
input_types = self.pallet_type_manager.get_pallet_types_by_operation("input")
|
||||
self.input_pallet_type_combo.clear()
|
||||
for pallet_type in input_types:
|
||||
self.input_pallet_type_combo.addItem(pallet_type['type_name'], pallet_type['id'])
|
||||
# def update_pallet_types(self):
|
||||
# """更新托盘类型下拉框"""
|
||||
# # 重新加载托盘类型数据
|
||||
# self.pallet_type_manager.reload_pallet_types()
|
||||
|
||||
# 更新下料托盘类型
|
||||
output_types = self.pallet_type_manager.get_pallet_types_by_operation("output")
|
||||
self.output_pallet_type_combo.clear()
|
||||
for pallet_type in output_types:
|
||||
self.output_pallet_type_combo.addItem(pallet_type['type_name'], pallet_type['id'])
|
||||
# # 更新上料托盘类型
|
||||
# input_types = self.pallet_type_manager.get_pallet_types_by_operation("input")
|
||||
# self.input_pallet_type_combo.clear()
|
||||
# for pallet_type in input_types:
|
||||
# self.input_pallet_type_combo.addItem(pallet_type['type_name'], pallet_type['id'])
|
||||
|
||||
# # 更新下料托盘类型
|
||||
# output_types = self.pallet_type_manager.get_pallet_types_by_operation("output")
|
||||
# self.output_pallet_type_combo.clear()
|
||||
# for pallet_type in output_types:
|
||||
# self.output_pallet_type_combo.addItem(pallet_type['type_name'], pallet_type['id'])
|
||||
|
||||
def load_config(self):
|
||||
"""加载配置文件"""
|
||||
@ -299,8 +302,54 @@ class MainWindow(MainWindowUI):
|
||||
if not self.camera_display.camera_manager.isGrabbing:
|
||||
self.camera_display.start_display()
|
||||
|
||||
# 加载托盘号列表
|
||||
self.load_pallet_codes()
|
||||
|
||||
logging.info("显示主页面")
|
||||
|
||||
def load_pallet_codes(self):
|
||||
"""从托盘类型管理器加载托盘号并更新到tray_edit"""
|
||||
try:
|
||||
# 获取当前文本,以便保留用户选择
|
||||
current_text = self.tray_edit.currentText()
|
||||
|
||||
# 清空当前项目
|
||||
self.tray_edit.clear()
|
||||
|
||||
# 获取托盘号
|
||||
pallet_codes = self.pallet_type_manager.get_pallet_code()
|
||||
|
||||
if pallet_codes and len(pallet_codes) > 0:
|
||||
# 添加托盘号到下拉框
|
||||
for code in pallet_codes:
|
||||
self.tray_edit.addItem(code)
|
||||
|
||||
# 如果有之前的选择,尝试恢复它
|
||||
if current_text:
|
||||
index = self.tray_edit.findText(current_text)
|
||||
if index >= 0:
|
||||
self.tray_edit.setCurrentIndex(index)
|
||||
logging.info(f"已加载托盘号,共 {len(pallet_codes)} 个")
|
||||
else:
|
||||
# 如果没有托盘号,添加默认项
|
||||
default_codes = ["托盘1", "托盘2", "托盘3", "托盘4", "托盘5", "托盘6"]
|
||||
for code in default_codes:
|
||||
self.tray_edit.addItem(code)
|
||||
logging.warning("未找到托盘号,使用默认值")
|
||||
|
||||
# 尝试恢复之前的选择
|
||||
if current_text:
|
||||
index = self.tray_edit.findText(current_text)
|
||||
if index >= 0:
|
||||
self.tray_edit.setCurrentIndex(index)
|
||||
except Exception as e:
|
||||
logging.error(f"加载托盘号失败: {str(e)}")
|
||||
# 如果加载失败,添加默认项
|
||||
self.tray_edit.clear()
|
||||
default_codes = ["托盘1", "托盘2", "托盘3", "托盘4", "托盘5", "托盘6"]
|
||||
for code in default_codes:
|
||||
self.tray_edit.addItem(code)
|
||||
|
||||
def show_settings_page(self):
|
||||
"""显示设置页面"""
|
||||
# 创建设置窗口
|
||||
@ -325,15 +374,15 @@ class MainWindow(MainWindowUI):
|
||||
# 更新串口管理器配置
|
||||
self.serial_manager.reload_config()
|
||||
|
||||
# 重新加载托盘号
|
||||
self.load_pallet_codes()
|
||||
|
||||
logging.info("设置已更新,重新加载配置")
|
||||
|
||||
def handle_input(self):
|
||||
"""处理上料按钮点击事件"""
|
||||
# 获取托盘号
|
||||
tray_id = self.tray_edit.currentText()
|
||||
if not tray_id:
|
||||
QMessageBox.warning(self, "提示", "请先选择或输入托盘号")
|
||||
return
|
||||
|
||||
# 启动监听(不论后续是否确认上料)
|
||||
# 启动Modbus监控
|
||||
@ -358,7 +407,7 @@ class MainWindow(MainWindowUI):
|
||||
# 如果用户确认,则执行上料操作
|
||||
if result == QDialog.Accepted:
|
||||
# 获取托盘料值作为拆垛层数
|
||||
stow_num = dialog.pallet_material_value.text()
|
||||
stow_num = dialog.pallet_tier_value.text()
|
||||
if stow_num == "--" or not stow_num:
|
||||
QMessageBox.warning(self, "错误", "未获取到托盘料信息,请重试")
|
||||
return
|
||||
@ -370,7 +419,7 @@ class MainWindow(MainWindowUI):
|
||||
self.init_seq[tray_id] = 1
|
||||
|
||||
if not pallet_type:
|
||||
QMessageBox.warning(self, "错误", "未查到对应下料托盘类型")
|
||||
QMessageBox.warning(self, "错误", "未查到对应托盘类型")
|
||||
return
|
||||
|
||||
# 执行Modbus操作
|
||||
@ -398,9 +447,6 @@ class MainWindow(MainWindowUI):
|
||||
"""处理下料按钮点击事件"""
|
||||
# 获取托盘号
|
||||
tray_id = self.tray_edit.currentText()
|
||||
if not tray_id:
|
||||
QMessageBox.warning(self, "提示", "请先选择或输入托盘号")
|
||||
return
|
||||
|
||||
# 启动监听(不论后续是否确认下料)
|
||||
# 启动Modbus监控
|
||||
@ -425,7 +471,7 @@ class MainWindow(MainWindowUI):
|
||||
# 如果用户确认,则执行下料操作
|
||||
if result == QDialog.Accepted:
|
||||
# 获取托盘料值作为下料层数
|
||||
stow_num = dialog.pallet_material_value.text()
|
||||
stow_num = dialog.pallet_tier_value.text()
|
||||
if stow_num == "--" or not stow_num:
|
||||
QMessageBox.warning(self, "错误", "未获取到托盘料信息,请重试")
|
||||
return
|
||||
|
||||
@ -3,6 +3,8 @@ from apis.tary_api import TaryApi
|
||||
from PySide6.QtCore import Qt, Signal
|
||||
from PySide6.QtWidgets import QMessageBox, QDialog
|
||||
import logging
|
||||
from utils.app_mode import AppMode
|
||||
from utils.pallet_type_manager import PalletTypeManager
|
||||
|
||||
class UnloadingDialog(UnloadingDialogUI):
|
||||
# 定义一个信号,用于向主窗口传递托盘号
|
||||
@ -34,7 +36,8 @@ class UnloadingDialog(UnloadingDialogUI):
|
||||
"""设置事件连接"""
|
||||
# 托盘号输入框回车事件触发查询
|
||||
self.tray_input.returnPressed.connect(self.handle_tray_return_pressed)
|
||||
self.tray_input.editingFinished.connect(self.on_tray_query)
|
||||
# 移除editingFinished事件,避免重复触发查询
|
||||
# self.tray_input.editingFinished.connect(self.on_tray_query)
|
||||
|
||||
# 确认按钮点击事件
|
||||
self.confirm_button.clicked.connect(self.accept)
|
||||
@ -60,8 +63,36 @@ class UnloadingDialog(UnloadingDialogUI):
|
||||
|
||||
logging.info(f"查询托盘号: {tray_code}")
|
||||
|
||||
# 调用API获取托盘信息
|
||||
response = self.tary_api.get_tary_info(tray_code)
|
||||
if AppMode.is_api():
|
||||
self.tary_api = TaryApi()
|
||||
# 调用API获取托盘信息
|
||||
response = self.tary_api.get_tary_info(tray_code)
|
||||
else:
|
||||
pallet_type_manager = PalletTypeManager.get_instance()
|
||||
pallet_info = pallet_type_manager.get_pallet_info_by_pallet_id(tray_code)
|
||||
|
||||
# 检查返回的数据类型并进行适当处理
|
||||
if pallet_info is None:
|
||||
response = {
|
||||
"success": False,
|
||||
"message": "未找到托盘信息"
|
||||
}
|
||||
else:
|
||||
# 如果返回的是元组(数据库查询结果),将其转换为字典
|
||||
# 根据dao/pallet_type_dao.py中get_pallet_info_by_pallet_id方法的SQL查询
|
||||
# 返回的字段顺序为:pallet_code, pallet_name, description, axios_name, axios_type, tier, size, amount, weight
|
||||
response = {
|
||||
"success": True,
|
||||
"data": {
|
||||
"tp_note": pallet_info[0] if len(pallet_info) > 0 else "",
|
||||
"product_name": pallet_info[1] if len(pallet_info) > 1 else "",
|
||||
"axis_type": pallet_info[4] if len(pallet_info) > 4 else "",
|
||||
"tier": str(pallet_info[5]) if len(pallet_info) > 5 else "",
|
||||
"weight": str(pallet_info[8]) if len(pallet_info) > 8 else "",
|
||||
"quantity": ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
logging.info(f"托盘信息响应: {response}")
|
||||
logging.info(f"response.success={response.get('success')}, response.data存在={response.get('data') is not None}")
|
||||
@ -72,14 +103,14 @@ class UnloadingDialog(UnloadingDialogUI):
|
||||
|
||||
# 显示托盘相关信息
|
||||
axis_type = str(tray_data.get("axis_type", "--"))
|
||||
material = str(tray_data.get("material", "--"))
|
||||
tier = str(tray_data.get("tier", "--"))
|
||||
weight = str(tray_data.get("weight", "--"))
|
||||
|
||||
logging.info(f"显示托盘信息: 轴型={axis_type}, 托盘料={material}, 重量={weight}")
|
||||
logging.info(f"显示托盘信息: 轴型={axis_type}, 托盘料={tier}, 重量={weight}")
|
||||
|
||||
# 设置显示值
|
||||
self.axis_value.setText(axis_type)
|
||||
self.pallet_material_value.setText(material)
|
||||
self.pallet_tier_value.setText(tier)
|
||||
self.quantity_value.setText("") # 数量为空
|
||||
self.weight_value.setText(f"{weight} kg")
|
||||
|
||||
@ -110,3 +141,26 @@ class UnloadingDialog(UnloadingDialogUI):
|
||||
except Exception as e:
|
||||
logging.error(f"查询托盘信息异常: {str(e)}")
|
||||
QMessageBox.critical(self, "查询异常", f"查询托盘信息时发生异常: {str(e)}")
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
"""重写键盘事件处理,防止回车关闭对话框"""
|
||||
# 如果按下回车键
|
||||
if event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter:
|
||||
logging.info(f"捕获到回车键事件,当前焦点部件: {self.focusWidget()}")
|
||||
|
||||
# 如果焦点在托盘输入框上,触发查询
|
||||
if self.focusWidget() == self.tray_input:
|
||||
# 不需要重复调用on_tray_query,因为returnPressed信号已经处理了
|
||||
event.accept() # 消费掉这个事件
|
||||
return
|
||||
|
||||
# 如果焦点在确认按钮上,则允许默认行为(确认)
|
||||
if self.focusWidget() == self.confirm_button:
|
||||
return super().keyPressEvent(event)
|
||||
|
||||
# 其他情况下,阻止回车事件传播
|
||||
event.accept() # 消费掉这个事件
|
||||
return
|
||||
|
||||
# 其他键位事件交给父类处理
|
||||
super().keyPressEvent(event)
|
||||
Loading…
Reference in New Issue
Block a user