格式统一

This commit is contained in:
duxin
2026-07-01 13:19:46 +08:00
parent 8de73db80e
commit 1611001a72
13 changed files with 348 additions and 116 deletions

View File

@ -26,7 +26,10 @@ PIPELINE_AVAILABLE = True
class Step11MapBatchThread(QThread):
"""专题图:按文件夹内多个预测 CSV 批量生成分布图。"""
"""专题图:按文件夹内多个预测 CSV 批量生成分布图。
2026-07-01 修复:新增 is_running 标志 + stop() 方法,支持外部安全取消。
"""
finished_ok = pyqtSignal(int)
failed = pyqtSignal(str)
@ -39,6 +42,19 @@ class Step11MapBatchThread(QThread):
self.csv_paths = csv_paths
self.step10_kwargs = step10_kwargs
self.output_dir_optional = (output_dir_optional or "").strip() or None
self._cancelled = False
def cancel(self):
"""请求取消(不立即 terminate,让循环自然退出)。"""
self._cancelled = True
def stop(self):
"""安全停止:先请求取消 + 等待 3s,超时后 terminate。"""
self.cancel()
if self.isRunning():
if not self.wait(3000):
self.terminate()
self.wait(2000)
def run(self):
mpl_prev = None
@ -56,6 +72,9 @@ class Step11MapBatchThread(QThread):
from src.core.steps.mapping_step import MappingStep
n = len(self.csv_paths)
for i, csv_p in enumerate(self.csv_paths):
if self._cancelled:
self.log_message.emit("专题图批量任务已被用户取消", "warning")
break
self.progress.emit(i + 1, n)
self.log_message.emit(f"专题图 [{i + 1}/{n}] {csv_p}", "info")
kw = {**self.step10_kwargs, "prediction_csv_path": csv_p}
@ -79,7 +98,10 @@ class Step11MapBatchThread(QThread):
class Step11GeoTIFFBatchThread(QThread):
"""GeoTIFF 批量渲染:遍历文件夹下所有 .tif/.bsq 逐一渲染成分布图 PNG。"""
"""GeoTIFF 批量渲染:遍历文件夹下所有 .tif/.bsq 逐一渲染成分布图 PNG。
2026-07-01 修复:新增 is_running 标志 + stop() 方法,支持外部安全取消。
"""
finished_ok = pyqtSignal(int)
failed = pyqtSignal(str)
@ -100,6 +122,19 @@ class Step11GeoTIFFBatchThread(QThread):
self.boundary_shp_path = boundary_shp_path
self.input_crs = input_crs
self.output_crs = output_crs
self._cancelled = False
def cancel(self):
"""请求取消(不立即 terminate,让循环自然退出)。"""
self._cancelled = True
def stop(self):
"""安全停止:先请求取消 + 等待 3s,超时后 terminate。"""
self.cancel()
if self.isRunning():
if not self.wait(3000):
self.terminate()
self.wait(2000)
def run(self):
mpl_prev = None
@ -118,6 +153,9 @@ class Step11GeoTIFFBatchThread(QThread):
mapper = ContentMapper()
n = len(self.tif_paths)
for i, tif_path in enumerate(self.tif_paths):
if self._cancelled:
self.log_message.emit("GeoTIFF 批量渲染已被用户取消", "warning")
break
self.progress.emit(i + 1, n)
tif_stem = Path(tif_path).stem
chinese_name = mapper._get_chinese_title(tif_stem)
@ -148,11 +186,28 @@ class Step11GeoTIFFBatchThread(QThread):
class Step11MapPanel(QWidget):
"""步骤11:专题图生成"""
"""步骤11:专题图生成。
2026-07-01 修复:订阅 PipelineStopped 事件,支持主窗口停止按钮取消批量任务。
"""
def __init__(self, parent=None):
super().__init__(parent)
self._batch_thread = None
self.init_ui()
# 订阅 PipelineStopped 事件,用户点"强制停止"时自动取消批量线程
from src.gui.core.event_bus import global_event_bus
self._on_stop_sub = lambda data: self._cancel_batch_thread()
global_event_bus.subscribe('PipelineStopped', self._on_stop_sub)
# 面板销毁时清理订阅
self.destroyed.connect(lambda: global_event_bus.unsubscribe('PipelineStopped', self._on_stop_sub))
def _cancel_batch_thread(self):
"""安全取消正在运行的批量线程。"""
if self._batch_thread and self._batch_thread.isRunning():
if hasattr(self._batch_thread, 'stop'):
self._batch_thread.stop()
elif hasattr(self._batch_thread, 'cancel'):
self._batch_thread.cancel()
def init_ui(self):
layout = QVBoxLayout()
@ -410,6 +465,9 @@ class Step11MapPanel(QWidget):
pred_dir = (self.prediction_csv_dir_edit.text() or "").strip()
geotiff_path = (self.geotiff_file.get_path() or "").strip()
config = {
# ★ 2026-07-01 修复:同时提供 batch_mode (bool, Handler 使用) 和
# step10_batch_mode (str, 旧代码兼容)
'batch_mode': folder_mode,
'step10_batch_mode': 'folder' if folder_mode else 'single',
'render_mode': self.render_mode_combo.currentText(),
'prediction_csv_dir': pred_dir if pred_dir else None,

View File

@ -528,11 +528,16 @@ class Step8MlTrainPanel(QWidget):
def get_training_params(self):
"""获取模型训练参数"""
# ★ 2026-07-01 安全保护:float() 前验证 currentText() 是否为有效数值
feature_text = self.feature_start.currentText()
try:
feature_start = float(feature_text)
except (ValueError, TypeError):
feature_start = 374.285004 # 默认光谱起始列
return {
'pipeline_type': 'machine_learning',
# QComboBox 适配:currentText() 取列名;下拉项里就是"374.285004" 等纯数字波段名
# (与原 QLineEdit 中 "374.285004" 字符串保持完全一致,后端 float() 解析不变)
'feature_start': float(self.feature_start.currentText()),
'feature_start': feature_start,
'cv_folds': self.cv_folds.value(),
'preprocess_methods': [method for method, cb in self.preproc_checkboxes.items() if cb.isChecked()],
'model_types': [model for model, cb in self.model_checkboxes.items() if cb.isChecked()],