界面优化
This commit is contained in:
@ -1125,6 +1125,19 @@ class VisualizationPanel(QWidget):
|
|||||||
dir_group.setLayout(dir_layout)
|
dir_group.setLayout(dir_layout)
|
||||||
left_layout.addWidget(dir_group)
|
left_layout.addWidget(dir_group)
|
||||||
|
|
||||||
|
# 图像目录选择(优先指向预测结果目录)
|
||||||
|
img_dir_group = QGroupBox("图像目录")
|
||||||
|
img_dir_layout = QHBoxLayout()
|
||||||
|
self.img_dir_edit = QLineEdit()
|
||||||
|
self.img_dir_edit.setPlaceholderText("预测结果目录(自动填充)…")
|
||||||
|
self.img_dir_edit.setReadOnly(True)
|
||||||
|
img_dir_browse_btn = QPushButton("浏览")
|
||||||
|
img_dir_browse_btn.clicked.connect(self.browse_img_dir)
|
||||||
|
img_dir_layout.addWidget(self.img_dir_edit, 1)
|
||||||
|
img_dir_layout.addWidget(img_dir_browse_btn)
|
||||||
|
img_dir_group.setLayout(img_dir_layout)
|
||||||
|
left_layout.addWidget(img_dir_group)
|
||||||
|
|
||||||
# 图像目录树
|
# 图像目录树
|
||||||
tree_group = QGroupBox("图像目录")
|
tree_group = QGroupBox("图像目录")
|
||||||
tree_layout = QVBoxLayout()
|
tree_layout = QVBoxLayout()
|
||||||
@ -1210,6 +1223,73 @@ class VisualizationPanel(QWidget):
|
|||||||
self.work_dir_edit.setText(dir_path)
|
self.work_dir_edit.setText(dir_path)
|
||||||
self.scan_work_directory()
|
self.scan_work_directory()
|
||||||
|
|
||||||
|
def browse_img_dir(self):
|
||||||
|
"""手动浏览图像目录"""
|
||||||
|
dir_path = QFileDialog.getExistingDirectory(self, "选择图像目录")
|
||||||
|
if dir_path:
|
||||||
|
self.img_dir_edit.setText(dir_path)
|
||||||
|
self.image_tree.scan_directory(dir_path)
|
||||||
|
self._load_first_image_from_tree()
|
||||||
|
|
||||||
|
def update_from_config(self, work_dir=None, pipeline=None):
|
||||||
|
"""从全局配置自动推断并填入图像目录,然后自动加载目录内容。
|
||||||
|
|
||||||
|
推断优先级:
|
||||||
|
1. {work_dir}/11_12_13_predictions/Machine_Learning_Prediction(机器学习预测)
|
||||||
|
2. {work_dir}/11_12_13_predictions/Non_Empirical_Prediction(普通回归预测)
|
||||||
|
3. {work_dir}/11_12_13_predictions/Custom_Regression_Prediction(自定义回归预测)
|
||||||
|
4. {work_dir}/14_visualization(可视化目录)
|
||||||
|
5. {work_dir}(工作目录根)
|
||||||
|
"""
|
||||||
|
if work_dir:
|
||||||
|
self.work_dir = work_dir
|
||||||
|
self.work_dir_edit.setText(str(work_dir))
|
||||||
|
elif not self.work_dir:
|
||||||
|
return
|
||||||
|
|
||||||
|
work_path = Path(self.work_dir)
|
||||||
|
pred_dir = work_path / "11_12_13_predictions"
|
||||||
|
|
||||||
|
# 按优先级寻找存在的目录
|
||||||
|
candidates = [
|
||||||
|
pred_dir / "Machine_Learning_Prediction",
|
||||||
|
pred_dir / "Non_Empirical_Prediction",
|
||||||
|
pred_dir / "Custom_Regression_Prediction",
|
||||||
|
work_path / "14_visualization",
|
||||||
|
work_path,
|
||||||
|
]
|
||||||
|
detected_dir = None
|
||||||
|
for candidate in candidates:
|
||||||
|
if candidate.exists() and candidate.is_dir():
|
||||||
|
detected_dir = candidate
|
||||||
|
break
|
||||||
|
|
||||||
|
if detected_dir:
|
||||||
|
detected_str = str(detected_dir)
|
||||||
|
self.img_dir_edit.setText(detected_str)
|
||||||
|
self.image_tree.scan_directory(detected_str)
|
||||||
|
else:
|
||||||
|
# 无预测目录时扫描整个工作目录
|
||||||
|
self.image_tree.scan_directory(self.work_dir)
|
||||||
|
|
||||||
|
# 自动触发加载第一张图像
|
||||||
|
self._load_first_image_from_tree()
|
||||||
|
|
||||||
|
def _load_first_image_from_tree(self):
|
||||||
|
"""从目录树中加载第一张图像到右侧查看器"""
|
||||||
|
tree = self.image_tree
|
||||||
|
if tree is None:
|
||||||
|
return
|
||||||
|
for category_item in tree.category_items.values():
|
||||||
|
for i in range(category_item.childCount()):
|
||||||
|
child = category_item.child(i)
|
||||||
|
data = child.data(0, Qt.UserRole)
|
||||||
|
if data and data.get("type") == "image":
|
||||||
|
img_path = data.get("path")
|
||||||
|
if img_path and Path(img_path).exists():
|
||||||
|
self.image_viewer.load_image(img_path)
|
||||||
|
return
|
||||||
|
|
||||||
def scan_work_directory(self):
|
def scan_work_directory(self):
|
||||||
"""扫描工作目录中的图像文件"""
|
"""扫描工作目录中的图像文件"""
|
||||||
if not self.work_dir:
|
if not self.work_dir:
|
||||||
|
|||||||
@ -2126,6 +2126,10 @@ class WaterQualityGUI(QMainWindow):
|
|||||||
elif index == 9:
|
elif index == 9:
|
||||||
self.step7_panel.update_from_config(work_dir=self.work_dir, pipeline=self.pipeline)
|
self.step7_panel.update_from_config(work_dir=self.work_dir, pipeline=self.pipeline)
|
||||||
|
|
||||||
|
# 可视化分析面板切换时自动推断图像目录并加载目录树
|
||||||
|
elif index == 14:
|
||||||
|
self.viz_panel.update_from_config(work_dir=self.work_dir, pipeline=self.pipeline)
|
||||||
|
|
||||||
def apply_stylesheet(self):
|
def apply_stylesheet(self):
|
||||||
"""应用样式表 - 应用现代化设计风格"""
|
"""应用样式表 - 应用现代化设计风格"""
|
||||||
# 应用主样式表
|
# 应用主样式表
|
||||||
|
|||||||
Reference in New Issue
Block a user