diff --git a/src/gui/panels/step2_panel.py b/src/gui/panels/step2_panel.py index 4f271c3..ffd5741 100644 --- a/src/gui/panels/step2_panel.py +++ b/src/gui/panels/step2_panel.py @@ -179,6 +179,9 @@ class Step2Panel(QWidget): # 填充获取到的路径 if mask_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(mask_path): + mask_path = os.path.join(self.work_dir or '', mask_path).replace('\\', '/') self.water_mask_file.set_path(mask_path) # 3. 自动填充输出路径(基于工作目录) diff --git a/src/gui/panels/step3_panel.py b/src/gui/panels/step3_panel.py index e782018..77fcc03 100644 --- a/src/gui/panels/step3_panel.py +++ b/src/gui/panels/step3_panel.py @@ -294,6 +294,9 @@ class Step3Panel(QWidget): mask_path = main_window.step1_panel.mask_file.get_path() if mask_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(mask_path): + mask_path = os.path.join(self.work_dir or '', mask_path).replace('\\', '/') self.water_mask_file.set_path(mask_path) # 自动填充输出路径(基于工作目录) diff --git a/src/gui/panels/step5_5_panel.py b/src/gui/panels/step5_5_panel.py index 770f52a..21fd07e 100644 --- a/src/gui/panels/step5_5_panel.py +++ b/src/gui/panels/step5_5_panel.py @@ -308,11 +308,17 @@ class Step5_5Panel(QWidget): # 优先直接从 Step5 的输出 widget 读取(已运行的最新输出) step5_output = main_window.step5_panel.output_file.get_path() if step5_output: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step5_output): + step5_output = os.path.join(self.work_dir or '', step5_output).replace('\\', '/') self.training_data_widget.set_path(step5_output) else: # 退而求其次,使用 Step5 的输入 CSV step5_csv = main_window.step5_panel.csv_file.get_path() if step5_csv: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step5_csv): + step5_csv = os.path.join(self.work_dir or '', step5_csv).replace('\\', '/') self.training_data_widget.set_path(step5_csv) # 如果上述都没找到,尝试从 pipeline.step_outputs 回退 diff --git a/src/gui/panels/step5_panel.py b/src/gui/panels/step5_panel.py index 274ebe0..5193471 100644 --- a/src/gui/panels/step5_panel.py +++ b/src/gui/panels/step5_panel.py @@ -170,9 +170,15 @@ class Step5Panel(QWidget): mask_path = main_window.step1_panel.output_file.get_path() else: mask_path = main_window.step1_panel.mask_file.get_path() + # 若为相对路径,使用 work_dir 合成为绝对路径 + if mask_path and not os.path.isabs(mask_path): + mask_path = os.path.join(self.work_dir or '', mask_path).replace('\\', '/') # 填充水体掩膜路径 if mask_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(mask_path): + mask_path = os.path.join(self.work_dir or '', mask_path).replace('\\', '/') self.water_mask_file.set_path(mask_path) # 3. 尝试从 Step2 界面读取耀斑掩膜路径 @@ -180,6 +186,9 @@ class Step5Panel(QWidget): if hasattr(main_window, 'step2_panel'): glint_path = main_window.step2_panel.output_file.get_path() if glint_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(glint_path): + glint_path = os.path.join(self.work_dir or '', glint_path).replace('\\', '/') self.glint_mask_file.set_path(glint_path) # 4. 自动填充输出路径(基于工作目录) @@ -196,6 +205,9 @@ class Step5Panel(QWidget): if main_window and hasattr(main_window, 'step4_panel'): step4_output_path = main_window.step4_panel.output_file.get_path() if step4_output_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step4_output_path): + step4_output_path = os.path.join(self.work_dir or '', step4_output_path).replace('\\', '/') existing_csv = self.csv_file.get_path() if not existing_csv or not existing_csv.strip(): self.csv_file.set_path(step4_output_path) diff --git a/src/gui/panels/step6_5_panel.py b/src/gui/panels/step6_5_panel.py index a1f4653..4ea1b6d 100644 --- a/src/gui/panels/step6_5_panel.py +++ b/src/gui/panels/step6_5_panel.py @@ -230,6 +230,9 @@ class Step6_5Panel(QWidget): if main_window and hasattr(main_window, 'step5_panel'): step5_output_path = main_window.step5_panel.output_file.get_path() if step5_output_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step5_output_path): + step5_output_path = os.path.join(self.work_dir or '', step5_output_path).replace('\\', '/') existing = self.training_csv_file.get_path() if not existing or not existing.strip(): self.training_csv_file.set_path(step5_output_path) diff --git a/src/gui/panels/step6_75_panel.py b/src/gui/panels/step6_75_panel.py index 611c3c8..aaf8504 100644 --- a/src/gui/panels/step6_75_panel.py +++ b/src/gui/panels/step6_75_panel.py @@ -148,7 +148,7 @@ class Step6_75Panel(QWidget): output_layout = QFormLayout() self.output_dir = QLineEdit() - self.output_dir.setText("9_Custom_Regression_Modeling") + self.output_dir.setText("") # 路径由 update_from_config 根据 work_dir 自动填充 output_layout.addRow("输出目录名:", self.output_dir) output_group.setLayout(output_layout) @@ -299,6 +299,9 @@ class Step6_75Panel(QWidget): if main_window and hasattr(main_window, 'step5_panel'): step5_output_path = main_window.step5_panel.output_file.get_path() if step5_output_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step5_output_path): + step5_output_path = os.path.join(self.work_dir or '', step5_output_path).replace('\\', '/') existing = self.csv_file.get_path() if not existing or not existing.strip(): self.csv_file.set_path(step5_output_path) diff --git a/src/gui/panels/step6_panel.py b/src/gui/panels/step6_panel.py index 066f691..81e1e6b 100644 --- a/src/gui/panels/step6_panel.py +++ b/src/gui/panels/step6_panel.py @@ -298,12 +298,15 @@ class Step6Panel(QWidget): else: self.work_dir = None - # 1. 尝试从 Step5 界面读取训练数据路径 + # 1. 尝试从 Step5 界面读取训练数据路径,并确保为绝对路径 main_window = self.window() if hasattr(main_window, 'step5_panel'): # 优先直接从 Step5 的输出 widget 读取 step5_output = main_window.step5_panel.output_file.get_path() if step5_output: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step5_output): + step5_output = os.path.join(self.work_dir or '', step5_output).replace('\\', '/') self.training_csv_file.set_path(step5_output) elif hasattr(main_window, 'step5_panel') and hasattr(main_window.step5_panel, 'get_config'): # 回退:从 Step5 的 config 字典中查找可能的键名 @@ -315,6 +318,9 @@ class Step6Panel(QWidget): or step5_cfg.get('output_csv') ) if step5_csv: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step5_csv): + step5_csv = os.path.join(self.work_dir or '', step5_csv).replace('\\', '/') self.training_csv_file.set_path(step5_csv) # 2. 自动填充输出文件路径(基于工作目录和输入文件名) diff --git a/src/gui/panels/step7_panel.py b/src/gui/panels/step7_panel.py index 87ec1bc..c8b13c9 100644 --- a/src/gui/panels/step7_panel.py +++ b/src/gui/panels/step7_panel.py @@ -145,6 +145,9 @@ class Step7Panel(QWidget): deglint_path = main_window.step3_panel.output_file.get_path() if deglint_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(deglint_path): + deglint_path = os.path.join(self.work_dir or '', deglint_path).replace('\\', '/') self.deglint_img_file.set_path(deglint_path) # 2. 填充水域掩膜路径(优先从 pipeline.step_outputs 获取绝对路径) @@ -161,6 +164,9 @@ class Step7Panel(QWidget): water_mask_path = main_window.step1_panel.output_file.get_path() if water_mask_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(water_mask_path): + water_mask_path = os.path.join(self.work_dir or '', water_mask_path).replace('\\', '/') self.water_mask_file.set_path(water_mask_path) # 3. 自动填充输出路径(绝对路径) diff --git a/src/gui/panels/step8_5_panel.py b/src/gui/panels/step8_5_panel.py index e694a47..82914db 100644 --- a/src/gui/panels/step8_5_panel.py +++ b/src/gui/panels/step8_5_panel.py @@ -102,6 +102,9 @@ class Step8_5Panel(QWidget): if main_window and hasattr(main_window, 'step7_panel'): step7_output_path = main_window.step7_panel.output_file.get_path() if step7_output_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step7_output_path): + step7_output_path = os.path.join(self.work_dir or '', step7_output_path).replace('\\', '/') existing = self.sampling_csv_file.get_path() if not existing or not existing.strip(): self.sampling_csv_file.set_path(step7_output_path) @@ -110,6 +113,9 @@ class Step8_5Panel(QWidget): if main_window and hasattr(main_window, 'step6_5_panel'): step6_5_models_dir = main_window.step6_5_panel.output_dir.get_path() if step6_5_models_dir: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step6_5_models_dir): + step6_5_models_dir = os.path.join(self.work_dir or '', step6_5_models_dir).replace('\\', '/') existing_models = self.models_dir_file.get_path() if not existing_models or not existing_models.strip(): self.models_dir_file.set_path(step6_5_models_dir) diff --git a/src/gui/panels/step8_75_panel.py b/src/gui/panels/step8_75_panel.py index 1733790..809ce6b 100644 --- a/src/gui/panels/step8_75_panel.py +++ b/src/gui/panels/step8_75_panel.py @@ -39,7 +39,7 @@ class Step8_75Panel(QWidget): self.regression_models_dir.label.setText("回归模型目录:") self.regression_models_dir.browse_btn.clicked.disconnect() self.regression_models_dir.browse_btn.clicked.connect(self.browse_regression_models_dir) - self.regression_models_dir.set_path("9_Custom_Regression_Modeling") + self.regression_models_dir.set_path("") # 路径由 update_from_config 根据 work_dir 自动填充 layout.addWidget(self.regression_models_dir) # 公式CSV文件选择(用于查找index_formula) @@ -95,6 +95,9 @@ class Step8_75Panel(QWidget): if main_window and hasattr(main_window, 'step7_panel'): step7_output_path = main_window.step7_panel.output_file.get_path() if step7_output_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step7_output_path): + step7_output_path = os.path.join(self.work_dir or '', step7_output_path).replace('\\', '/') existing = self.sampling_csv_file.get_path() if not existing or not existing.strip(): self.sampling_csv_file.set_path(step7_output_path) @@ -103,11 +106,21 @@ class Step8_75Panel(QWidget): if main_window and hasattr(main_window, 'step6_75_panel'): step6_75_models_dir = main_window.step6_75_panel.output_dir.text().strip() if step6_75_models_dir: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step6_75_models_dir): + step6_75_models_dir = os.path.join(self.work_dir or '', step6_75_models_dir).replace('\\', '/') existing_models = self.regression_models_dir.get_path() if not existing_models or not existing_models.strip(): self.regression_models_dir.set_path(step6_75_models_dir) - # 3. 自动填充输出目录(自定义回归预测目录) + # 3. 自动填充回归模型目录(如果 step6_75 未提供) + if self.work_dir: + models_dir = self.regression_models_dir.get_path().strip() + if not models_dir: + default_models_dir = os.path.join(self.work_dir, "9_Custom_Regression_Modeling").replace('\\', '/') + self.regression_models_dir.set_path(default_models_dir) + + # 4. 自动填充输出目录(自定义回归预测目录) if self.work_dir: output_dir = os.path.join(self.work_dir, "11_12_13_predictions/Custom_Regression_Prediction") os.makedirs(output_dir, exist_ok=True) diff --git a/src/gui/panels/step8_panel.py b/src/gui/panels/step8_panel.py index 2440c66..d1ae65a 100644 --- a/src/gui/panels/step8_panel.py +++ b/src/gui/panels/step8_panel.py @@ -99,6 +99,9 @@ class Step8Panel(QWidget): if main_window and hasattr(main_window, 'step7_panel'): step7_output_path = main_window.step7_panel.output_file.get_path() if step7_output_path: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step7_output_path): + step7_output_path = os.path.join(self.work_dir or '', step7_output_path).replace('\\', '/') existing = self.sampling_csv_file.get_path() if not existing or not existing.strip(): self.sampling_csv_file.set_path(step7_output_path) @@ -107,6 +110,9 @@ class Step8Panel(QWidget): if main_window and hasattr(main_window, 'step6_panel'): step6_models_dir = main_window.step6_panel.output_dir.get_path() if step6_models_dir: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step6_models_dir): + step6_models_dir = os.path.join(self.work_dir or '', step6_models_dir).replace('\\', '/') existing_models = self.models_dir_file.get_path() if not existing_models or not existing_models.strip(): self.models_dir_file.set_path(step6_models_dir) diff --git a/src/gui/panels/step9_panel.py b/src/gui/panels/step9_panel.py index 35b6ea5..74c8531 100644 --- a/src/gui/panels/step9_panel.py +++ b/src/gui/panels/step9_panel.py @@ -324,12 +324,18 @@ class Step9Panel(QWidget): if hasattr(main_window, 'step8_panel'): step8_output = main_window.step8_panel.output_file.get_path() if step8_output: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step8_output): + step8_output = os.path.join(self.work_dir or '', step8_output).replace('\\', '/') pred_dir = str(Path(step8_output).parent) # 2. 备选:从 Step8.5 界面读取非经验预测输出目录 if not pred_dir and hasattr(main_window, 'step8_5_panel'): step8_5_output = main_window.step8_5_panel.output_file.get_path() if step8_5_output: + # 若为相对路径,使用 work_dir 合成为绝对路径 + if not os.path.isabs(step8_5_output): + step8_5_output = os.path.join(self.work_dir or '', step8_5_output).replace('\\', '/') pred_dir = str(Path(step8_5_output).parent) # 3. 备选:从 Step8.75 界面读取自定义回归预测输出目录