From 53cd8f60b540994ea2bc3ce7e521fbc7a1141735 Mon Sep 17 00:00:00 2001 From: zhu-mengmeng <15588200382@163.com> Date: Fri, 25 Jul 2025 11:49:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B0=86=E6=89=98=E7=9B=98=E5=8F=B7?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A1=86=E4=BB=8EQComboBox=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E4=B8=BAQLineEdit=EF=BC=8C=E4=BC=98=E5=8C=96=E6=89=98=E7=9B=98?= =?UTF-8?q?=E5=8F=B7=E8=AE=BE=E7=BD=AE=E5=92=8C=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/jtDB.db | Bin 278528 -> 282624 bytes fix_status_management.py | 6 +- from pymodbus.py | 7 +- status_management_patch.py | 6 +- ui/main_window_ui.py | 20 ++--- ui/unloading_dialog_ui.py | 6 +- widgets/loading_dialog_widget.py | 19 ++-- widgets/main_window.py | 140 +++++++++++++++++------------ widgets/unloading_dialog_widget.py | 19 ++-- 9 files changed, 115 insertions(+), 108 deletions(-) diff --git a/db/jtDB.db b/db/jtDB.db index 79919406943b257590402cf5d9a1aac964d97a6b..e23af5cc5a82cbc001c5528b6f6ad03fcd8a6540 100644 GIT binary patch delta 3106 zcmai$TWl0n7{_PM^uC>4nsz%Z1zL(gD0DoRIWx1PQm#T83>3Ek0lA156qMEra?{;W zt2AOl>B1x=B(2;j;UehDofs2+@Ij){7ckLSun8*Rp=zqcZ?-h->`q``b~nE{|M`EH z^PQ7OlqI^#wpZnM2!b%HqozUZIJx576!Adk$cAZR;?%N+11&)*bPK33D>M-558XOd zR`YX6ddwdEZvUlJ|0OYac|<@sEe6lZIB-yUucWweZqfGz;rtQeN#S&7S7%RJ<>Zb-dEw+qK_ymRKy^V_aFU47>|`p&&~Lz5_KmeLGNl>O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5#Ze kF+q!vY|+U+e 0: - # 添加托盘号到下拉框 - self.tray_edit.addItems(pallet_codes) - - # 如果有之前的选择,尝试恢复它 - index = self.tray_edit.findText(current_text) - if index != -1: - self.tray_edit.setCurrentIndex(index) + # 由于现在是 QLineEdit,我们不再需要添加多个项目 + # 如果有之前的选择并且它在托盘号列表中,则恢复它 + if current_text in pallet_codes: + self.tray_edit.setText(current_text) else: - self.tray_edit.setCurrentIndex(-1) - self.tray_edit.setCurrentText("") + self.tray_edit.setText("") + + # 这里可以存储托盘号列表,以便在其他地方使用 + self._pallet_codes = pallet_codes logging.info(f"已加载托盘号,共 {len(pallet_codes)} 个") else: - # 如果没有托盘号,则不添加任何项目,保持为空 - logging.warning("未找到托盘号,托盘号列表将为空") - self.tray_edit.setCurrentText("") - + # 如果没有托盘号,则保持为空 + logging.warning("未找到托盘号,托盘号将为空") + self.tray_edit.setText("") + self._pallet_codes = [] except Exception as e: logging.error(f"加载托盘号失败: {str(e)}") - # 如果加载失败,确保下拉框为空 - self.tray_edit.clear() - self.tray_edit.setCurrentText("") + # 如果加载失败,确保文本框为空 + self.tray_edit.setText("") + self._pallet_codes = [] def load_warehouse_data(self): """从API加载库房数据并更新到信息表格的库房组件""" @@ -638,7 +638,7 @@ class MainWindow(MainWindowUI): def handle_input(self): """处理上料按钮点击事件""" # 获取托盘号 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() # 启动监听(不论后续是否确认上料) # 启动Modbus监控 @@ -659,13 +659,13 @@ class MainWindow(MainWindowUI): dialog = self.loading_dialog # 使用类属性引用对话框 # 获取当前主窗口中选择的托盘号,并设置到上料对话框中 - current_tray_id = self.tray_edit.currentText() + current_tray_id = self.tray_edit.text() if current_tray_id: dialog.tray_input.setText(current_tray_id) logging.info(f"将主窗口当前托盘号 {current_tray_id} 设置到上料对话框") # 如果已有上料信息,作为参考显示在对话框中,但允许用户修改 - if self._loading_info and self._current_stow_num > 0: + if self._loading_info and self._current_stow_num >= 0: dialog.order_input.setText(self._loading_info.get('order_code', '')) dialog.tray_input.setText(self._loading_info.get('tray_code', '')) dialog.axis_value.setText(self._loading_info.get('axis_value', '--')) @@ -686,7 +686,7 @@ class MainWindow(MainWindowUI): order_code = dialog.order_input.text().strip() tray_code = dialog.tray_input.text().strip() self._current_order_code = order_code - self.tray_edit.setCurrentText(tray_code) + self.tray_edit.setText(tray_code) # 获取托盘料值作为拆垛层数 stow_num = dialog.pallet_tier_value.text() @@ -738,15 +738,19 @@ class MainWindow(MainWindowUI): dialog = self.unloading_dialog # 使用类属性引用对话框 # 获取当前主窗口中选择的托盘号,并设置到下料对话框中 - current_tray_id = self.tray_edit.currentText() + current_tray_id = self.tray_edit.text() if current_tray_id: dialog.tray_input.setText(current_tray_id) logging.info(f"将主窗口当前托盘号 {current_tray_id} 设置到下料对话框") # 如果有之前的下料信息,作为参考显示在对话框中,但允许用户修改 if self._current_unload_info: + # 确保使用最新的层数值 + if hasattr(self, '_current_unload_num'): + self._current_unload_info['tier'] = str(self._current_unload_num) + dialog.set_unloading_info(self._current_unload_info) - logging.info(f"显示之前的下料信息作为参考") + logging.info(f"显示之前的下料信息作为参考,当前层数:{self._current_unload_info['tier']}") if dialog.exec_() == QDialog.Accepted: # 获取用户最新输入的下料信息 @@ -996,6 +1000,9 @@ class MainWindow(MainWindowUI): # 再调用 update_info_table self.update_info_table(order_info) self.add_new_inspection_row(gc_note, self._current_order_code) + else: + # 弹框提示,获取接口中的 message + QMessageBox.warning(self, "提示", "获取工程号信息失败") else: # 直接添加新行 self.add_new_inspection_row(gc_note, self._current_order_code) @@ -1058,7 +1065,7 @@ class MainWindow(MainWindowUI): self._current_gc_note = gc_note # 记录添加时间,用于确保最新添加的工程号在最后 self._current_gc_note_timestamp = time.time() - logging.info(f"设置最新扫码的工程号: {gc_note}, 时间戳: {self._current_gc_note_timestamp}") + logging.info(f"设置最新扫码的工程号: {gc_note}, 订单号: {order_code}, 时间戳: {self._current_gc_note_timestamp}") try: # 获取启用的检验配置 @@ -1132,7 +1139,7 @@ class MainWindow(MainWindowUI): # 将工程号和托盘号保存到数据库,确保能够正确关联 from dao.inspection_dao import InspectionDAO inspection_dao = InspectionDAO() - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() # 为每个检验位置创建一个空记录,确保工程号在数据库中存在 # 只为没有自动填充值的配置创建空记录 @@ -1221,7 +1228,7 @@ class MainWindow(MainWindowUI): return # 获取托盘号 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() # 获取启用的检验配置 enabled_configs = self.inspection_manager.get_enabled_configs() @@ -1385,7 +1392,7 @@ class MainWindow(MainWindowUI): def _safe_load_data(self): """安全地加载数据,避免循环调用""" # 获取当前托盘号,用于日志记录 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() # 检查是否有加载操作正在进行 if getattr(self, '_loading_data_in_progress', False): @@ -1433,7 +1440,7 @@ class MainWindow(MainWindowUI): def _do_safe_load(self): """实际执行数据加载的方法,由定时器触发""" # 获取当前托盘号,用于日志记录 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() if self._loading_data_in_progress: # 如果已经在加载数据,不要再次触发 @@ -1480,7 +1487,7 @@ class MainWindow(MainWindowUI): try: # 获取托盘号 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() # 防止短时间内重复加载相同数据 current_time = time.time() @@ -1740,7 +1747,7 @@ class MainWindow(MainWindowUI): inspection_dao = InspectionDAO() # 获取托盘号 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() logging.info(f"显示包装记录,当前托盘号: {tray_id}") if not tray_id: @@ -1828,7 +1835,7 @@ class MainWindow(MainWindowUI): # 获取当前的订单号和托盘号 order_id = self._current_order_code if hasattr(self, '_current_order_code') else None - tray_id = self.tray_edit.currentText() if hasattr(self, 'tray_edit') else "" + tray_id = self.tray_edit.text() if hasattr(self, 'tray_edit') else "" # 初始化订单API统计数据 order_api_stats = { @@ -1942,7 +1949,7 @@ class MainWindow(MainWindowUI): return # 获取托盘号 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() # 创建上下文菜单 menu = QMenu(self) @@ -2557,7 +2564,7 @@ class MainWindow(MainWindowUI): self.process_table.setItem(data_row, weight_col, weight_item) # 检查是否已存在相同记录 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() existing_data = inspection_dao.get_inspection_data_by_config(self._current_order_code, gc_note, tray_id, 12, 12) if existing_data and str(existing_data.get('value')) == str(weight_kg): logging.info(f"跳过保存:工程号 {gc_note} 的称重数据 {weight_kg} 已存在") @@ -2659,8 +2666,8 @@ class MainWindow(MainWindowUI): logging.debug(f"字段 '{field_name}' 不在info_values中或为None") # 3. 添加其他必要的信息 - info['xpack'] = self.tray_edit.currentText() - info['spack'] = self.tray_edit.currentText() + info['xpack'] = self.tray_edit.text() + info['spack'] = self.tray_edit.text() info['zh'] = axios_num info['mzl'] = weight_kg info['printsl'] = 1 @@ -2815,7 +2822,7 @@ class MainWindow(MainWindowUI): return # 获取托盘号 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() # 获取启用的检验配置 enabled_configs = self.inspection_manager.get_enabled_configs() @@ -3110,7 +3117,15 @@ class MainWindow(MainWindowUI): # 通过信号触发UI更新 - 显示前一层完成的消息 message = f"第{completed_tier}层下料完成,请启动第{self._current_unload_num}层下料" self.unloading_feedback_signal.emit("output", message) + # 更新下料信息中的层数值,无论对话框是否打开 + if self._current_unload_info: + self._current_unload_info['tier'] = str(self._current_unload_num) + logging.info(f"更新下料信息中的层数为:{self._current_unload_num}") + # 如果下料对话框正在显示,同步更新其中的层数 + if hasattr(self, 'unloading_dialog') and self.unloading_dialog is not None and hasattr(self.unloading_dialog, 'tier_input'): + self.unloading_dialog.tier_input.setText(str(self._current_unload_num)) + logging.info(f"同步更新下料对话框中的层数为:{self._current_unload_num}") # 恢复开始按钮原始样式 self.restore_start_button_style() @@ -3134,10 +3149,9 @@ class MainWindow(MainWindowUI): logging.info("下料任务完成,恢复下料按钮样式") elif "请启动" in desc: QMessageBox.information(self, "下料层完成", desc) - # 如果当前下料信息存在且层数有效,更新UI显示 if self._current_unload_info and self._current_unload_num > 0: - self.show_operation_status("下料层数", "output", f"{self._current_unload_num}/{self._total_unload_num}") + self.show_operation_status("下料层数", "output", f"{self._current_unload_num}") except Exception as e: logging.error(f"处理下料UI更新失败: {str(e)}") @@ -3252,6 +3266,11 @@ class MainWindow(MainWindowUI): # 更新保存的下料信息中的当前层数值 if self._current_unload_info: self._current_unload_info['tier'] = str(level) + + # 如果下料对话框正在显示,同步更新其中的层数 + if hasattr(self, 'unloading_dialog') and self.unloading_dialog is not None and hasattr(self.unloading_dialog, 'tier_input'): + self.unloading_dialog.tier_input.setText(str(level)) + logging.info(f"同步更新下料对话框中的层数为:{level}") # 通过信号在主线程中更新UI self.unloading_level_ui_signal.emit(level) @@ -3320,7 +3339,7 @@ class MainWindow(MainWindowUI): return # 获取托盘号 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() # 获取启用的检验配置 enabled_configs = self.inspection_manager.get_enabled_configs() @@ -3575,7 +3594,7 @@ class MainWindow(MainWindowUI): logging.info(f"记录最近处理线径数据的工程号: {gc_note}") # 获取托盘号 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() # 检查线径公差范围 - 基于前端【线径公差】字段 if "线径公差" in self.info_values and self.info_values["线径公差"] is not None: @@ -3797,7 +3816,7 @@ class MainWindow(MainWindowUI): # 设置当前正在处理的工程号,确保它在重新加载时显示在最后 self._current_gc_note = order_id self._current_gc_note_timestamp = time.time() - logging.info(f"在set_inspection_value中设置最新扫码的工程号: {order_id}, 时间戳: {self._current_gc_note_timestamp}") + logging.info(f"在set_inspection_value中设置最新扫码的工程号: {order_id}, 订单号: {self._current_order_code}, 时间戳: {self._current_gc_note_timestamp}") self.add_new_inspection_row(order_id, self._current_order_code) data_row = 2 # 新添加的行 else: @@ -3905,7 +3924,7 @@ class MainWindow(MainWindowUI): # 保存到数据库,但只在非加载状态下 if not self._loading_data_in_progress: - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() self.save_inspection_data(self._current_order_code, order_id, tray_id, config_position, config_id, formatted_value, status) # 不需要在这里主动触发数据重新加载,因为handle_inspection_cell_changed会处理 @@ -3923,10 +3942,13 @@ class MainWindow(MainWindowUI): # 释放锁 self._set_inspection_value_lock = False - def handle_tray_changed(self): + def handle_tray_changed(self, tray_id=None): """处理托盘号变更事件,启动监听并加载数据""" try: - tray_id = self.tray_edit.currentText() + # 如果没有提供托盘号,则使用当前文本框中的值 + if tray_id is None: + tray_id = self.tray_edit.text() + if tray_id: logging.info(f"托盘号变更为 {tray_id},启动监听") # 初始化托盘号对应的序号(如果不存在) @@ -4294,7 +4316,7 @@ class MainWindow(MainWindowUI): continue # 获取托盘号 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() # 如果开启 api 模式,则调用接口删除远程数据 if AppMode.is_api(): @@ -4391,7 +4413,7 @@ class MainWindow(MainWindowUI): continue # 获取托盘号(从前端组件获取) - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() if not tray_id: logging.warning("托盘号为空,跳过删除") continue @@ -4445,7 +4467,7 @@ class MainWindow(MainWindowUI): """ try: # 获取托盘号 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() if not tray_id: QMessageBox.warning(self, "提示", "请先选择托盘号") return @@ -4822,7 +4844,7 @@ class MainWindow(MainWindowUI): if gc_note_item: row_gc_note = gc_note_item.text().strip() if row_gc_note: # 确保工程号不为空 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() status = inspection_dao.get_product_status(self._current_order_code, row_gc_note, tray_id) if status == target_status: logging.info(f"找到状态为{target_status}的行: {row}, 工程号: {row_gc_note}") @@ -4835,7 +4857,7 @@ class MainWindow(MainWindowUI): if gc_note_item: row_gc_note = gc_note_item.text().strip() if row_gc_note: # 确保工程号不为空 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() status = inspection_dao.get_product_status(self._current_order_code, row_gc_note, tray_id) if status == target_status: logging.info(f"从头开始找到状态为{target_status}的行: {row}, 工程号: {row_gc_note}") @@ -4887,7 +4909,7 @@ class MainWindow(MainWindowUI): return # 获取托盘号 - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() # 获取启用的检验配置 enabled_configs = self.inspection_manager.get_enabled_configs() @@ -4995,7 +5017,7 @@ class MainWindow(MainWindowUI): return False gc_note = gc_note_item.text().strip() - tray_id = self.tray_edit.currentText() + tray_id = self.tray_edit.text() # 获取启用的检验配置 enabled_configs = self.inspection_manager.get_enabled_configs() diff --git a/widgets/unloading_dialog_widget.py b/widgets/unloading_dialog_widget.py index 245f6cc..b4e5564 100644 --- a/widgets/unloading_dialog_widget.py +++ b/widgets/unloading_dialog_widget.py @@ -178,20 +178,13 @@ class UnloadingDialog(UnloadingDialogUI): main_window = self.parent if main_window and isinstance(main_window, MainWindow): # 检查托盘号是否已存在 - existed = False - for i in range(main_window.tray_edit.count()): - if main_window.tray_edit.itemText(i) == tray_code: - existed = True - break - - # 如果不存在,则添加 - if not existed: - logging.info(f"添加托盘号到主窗口: {tray_code}") - main_window.tray_edit.addItem(tray_code) - - # 设置当前选中的托盘号 - main_window.tray_edit.setCurrentText(tray_code) + # 由于 tray_edit 现在是 QLineEdit,不再需要检查是否存在 + # 直接设置文本 logging.info(f"设置主窗口当前托盘号: {tray_code}") + main_window.tray_edit.setText(tray_code) + + # 手动触发托盘号变更事件 + main_window.handle_tray_changed(tray_code) except Exception as e: logging.error(f"查询托盘信息异常: {str(e)}")