体验升级:路径记忆、可视化深度扫描、文件名汉化

This commit is contained in:
DXC
2026-05-08 13:33:19 +08:00
parent a4e6747b54
commit 5af466b2d3
4 changed files with 158 additions and 35 deletions

View File

@ -503,6 +503,42 @@ class ImageCategoryTree(QTreeWidget):
("含量分布图", [], "📁"),
]
# 文件名中文翻译映射
NAME_MAPPING = {
"hsi_preview": "高光谱影像预览",
"hsi_original": "原始高光谱影像",
"hsi_deglint": "去耀斑高光谱影像",
"water_mask_overlay": "水域掩膜叠加图",
"water_mask": "水域掩膜图",
"glint_mask": "耀斑掩膜预览",
"glint_overlay": "耀斑叠加对比图",
"deglint_comparison": "去耀斑前后对比",
"training_spectra": "训练光谱特征",
"spectrum_by_param": "参数光谱图",
"model_evaluation": "模型评估散点图",
"model_scatter": "模型散点图",
"regression": "回归分析图",
"validation": "验证结果图",
"spatial_distribution": "参数空间分布图",
"distribution_map": "分布图",
"thematic_map": "水质专题图",
"water_quality_map": "水质分布图",
"prediction_map": "预测结果图",
"inversion_map": "反演结果图",
"correlation_matrix": "特征相关性矩阵",
"feature_correlation": "特征相关性",
"sampling_point_map": "采样点分布图",
"sampling_points": "采样点图",
"point_locations": "采样位置图",
"boxplot": "箱线图",
"histogram": "直方图",
"statistics": "统计图表",
"statistical_chart": "统计图",
"error_analysis": "误差分析图",
"rmse": "RMSE评估图",
"r2_score": "R²得分图",
}
def __init__(self, parent=None):
super().__init__(parent)
self.setHeaderLabel("图像目录")
@ -545,16 +581,18 @@ class ImageCategoryTree(QTreeWidget):
category_item.removeChild(category_item.child(0))
def add_image(self, file_path: Path, display_name: str = None):
"""添加图像到对应的类别"""
"""添加图像到对应的类别(带中文名称翻译)"""
if display_name is None:
display_name = file_path.stem
# 使用翻译映射,查询不到则用原文件名
file_base = file_path.stem
display_name = self.NAME_MAPPING.get(file_base, file_base)
category = self._determine_category(file_path.name)
category_item = self.category_items.get(category, self.category_items["含量分布图"])
image_item = QTreeWidgetItem(category_item)
image_item.setText(0, f" └─ {display_name}")
image_item.setData(0, Qt.UserRole, {"type": "image", "path": str(file_path)})
image_item.setData(0, Qt.UserRole, {"type": "image", "path": str(file_path), "display_name": display_name})
image_item.setToolTip(0, str(file_path))
return image_item
@ -570,7 +608,7 @@ class ImageCategoryTree(QTreeWidget):
return "含量分布图"
def scan_directory(self, work_dir: str):
"""扫描目录中的所有图像文件"""
"""扫描目录中的所有图像文件(深度递归扫描)"""
self.clear_all_images()
work_path = Path(work_dir)
@ -578,13 +616,17 @@ class ImageCategoryTree(QTreeWidget):
return
image_extensions = ['*.png', '*.jpg', '*.jpeg', '*.tif', '*.tiff', '*.bmp']
scan_roots: List[Path] = []
_viz = work_path / "14_visualization"
if _viz.is_dir():
scan_roots.append(_viz)
_wm = work_path / "1_water_mask"
if _wm.is_dir():
scan_roots.append(_wm)
# 扫描根目录列表(按优先级)
scan_roots: List[Path] = [
work_path / "14_visualization",
work_path / "1_water_mask",
work_path / "9_water_quality_prediction",
work_path / "10_feature_construction",
]
# 只保留存在的目录,并补充工作根目录作为兜底
scan_roots = [p for p in scan_roots if p.is_dir()]
if not scan_roots:
scan_roots.append(work_path)
@ -592,7 +634,8 @@ class ImageCategoryTree(QTreeWidget):
image_files: List[Path] = []
for root in scan_roots:
for ext in image_extensions:
for p in root.glob(f"**/{ext}"):
# 使用 rglob 进行深度递归扫描
for p in root.rglob(ext):
key = os.path.normcase(os.path.normpath(str(p.resolve())))
if key in seen_norm:
continue