体验升级:路径记忆、可视化深度扫描、文件名汉化
This commit is contained in:
@ -85,11 +85,10 @@ class Step5_5Panel(QWidget):
|
||||
output_group = QGroupBox("输出设置")
|
||||
output_layout = QVBoxLayout()
|
||||
|
||||
output_hbox = QHBoxLayout()
|
||||
output_hbox.addWidget(QLabel("输出文件名:"))
|
||||
self.output_filename = QLineEdit("water_quality_indices.csv")
|
||||
output_hbox.addWidget(self.output_filename)
|
||||
output_layout.addLayout(output_hbox)
|
||||
self.output_file_widget = FileSelectWidget(
|
||||
"输出文件:", "CSV Files (*.csv)", mode="save"
|
||||
)
|
||||
output_layout.addWidget(self.output_file_widget)
|
||||
|
||||
output_group.setLayout(output_layout)
|
||||
main_layout.addWidget(output_group)
|
||||
@ -258,11 +257,12 @@ class Step5_5Panel(QWidget):
|
||||
name for name, checkbox in self.index_checkboxes.items()
|
||||
if checkbox.isChecked()
|
||||
]
|
||||
output_path = self.output_file_widget.get_path()
|
||||
return {
|
||||
'training_spectra_path': self.training_data_widget.get_path() or None,
|
||||
'formula_csv_file': self.formula_csv_widget.get_path() or None,
|
||||
'formula_names': selected,
|
||||
'output_filename': self.output_filename.text().strip() or "water_quality_indices.csv",
|
||||
'output_file': output_path or None,
|
||||
'enabled': self.enable_checkbox.isChecked()
|
||||
}
|
||||
|
||||
@ -273,7 +273,6 @@ class Step5_5Panel(QWidget):
|
||||
|
||||
if 'formula_csv_file' in config:
|
||||
self.formula_csv_widget.set_path(config['formula_csv_file'])
|
||||
# 设置CSV路径后自动刷新公式信息
|
||||
self.refresh_formulas()
|
||||
|
||||
if 'formula_names' in config:
|
||||
@ -281,8 +280,10 @@ class Step5_5Panel(QWidget):
|
||||
for name, checkbox in self.index_checkboxes.items():
|
||||
checkbox.setChecked(name in selected_formulas)
|
||||
|
||||
if 'output_filename' in config:
|
||||
self.output_filename.setText(config['output_filename'])
|
||||
if 'output_file' in config and config['output_file']:
|
||||
self.output_file_widget.set_path(config['output_file'])
|
||||
elif 'output_filename' in config and config['output_filename']:
|
||||
self.output_file_widget.set_path(config['output_filename'])
|
||||
|
||||
if 'enabled' in config:
|
||||
self.enable_checkbox.setChecked(config['enabled'])
|
||||
@ -328,9 +329,11 @@ class Step5_5Panel(QWidget):
|
||||
if training_path:
|
||||
self.training_data_widget.set_path(training_path)
|
||||
|
||||
# 2. 自动填充输出文件名(通用逻辑,由 run_step 根据输入文件名动态覆盖)
|
||||
# 核心方法只接受文件名,不接受完整路径。
|
||||
# 保持默认值,run_step 会根据输入自动填入 _indices.csv 后缀
|
||||
# 2. 自动填入输出文件的绝对路径
|
||||
if self.work_dir:
|
||||
output_abs = os.path.join(self.work_dir, "6_water_quality_indices",
|
||||
"training_spectra_indices.csv").replace('\\', '/')
|
||||
self.output_file_widget.set_path(output_abs)
|
||||
|
||||
def is_enabled(self) -> bool:
|
||||
return self.enable_checkbox.isChecked()
|
||||
@ -348,7 +351,7 @@ class Step5_5Panel(QWidget):
|
||||
def run_step(self):
|
||||
"""独立运行步骤5.5:计算水质指数。
|
||||
|
||||
动态根据输入 CSV 文件名生成输出文件名,自动填入 output_filename 文本框。
|
||||
动态根据输入 CSV 文件名生成输出文件名,自动填入 output_file_widget。
|
||||
例如:training_spectra.csv → training_spectra_indices.csv
|
||||
sampling_spectra.csv → sampling_spectra_indices.csv
|
||||
"""
|
||||
@ -369,10 +372,18 @@ class Step5_5Panel(QWidget):
|
||||
QMessageBox.warning(self, "输入验证失败", "公式CSV文件不存在")
|
||||
return
|
||||
|
||||
# 动态生成输出文件名:自动拼接 _indices 后缀
|
||||
# 动态生成输出文件:自动拼接 _indices 后缀
|
||||
input_name = Path(training_csv_path).stem
|
||||
dynamic_output = f"{input_name}_indices.csv"
|
||||
self.output_filename.setText(dynamic_output)
|
||||
|
||||
# 合成完整绝对路径(优先使用 work_dir,其次从 training_csv_path 推导)
|
||||
work_dir = getattr(self, 'work_dir', None)
|
||||
if work_dir:
|
||||
dynamic_output = os.path.join(
|
||||
work_dir, "6_water_quality_indices", dynamic_output
|
||||
).replace('\\', '/')
|
||||
|
||||
self.output_file_widget.set_path(dynamic_output)
|
||||
|
||||
# 获取配置
|
||||
config = self.get_config()
|
||||
|
||||
Reference in New Issue
Block a user