修复 PyQt 0xC0000409 崩溃:修复 window 属性命名冲突、全局异常钩子、可视化面板健壮重构
This commit is contained in:
@ -102,11 +102,11 @@ class Step6_5Panel(QWidget):
|
||||
self.spectral_start_col.setValue(1)
|
||||
params_layout.addRow("光谱起始列索引:", self.spectral_start_col)
|
||||
|
||||
# 窗口大小
|
||||
self.window = QSpinBox()
|
||||
self.window.setRange(1, 20)
|
||||
self.window.setValue(5)
|
||||
params_layout.addRow("窗口大小:", self.window)
|
||||
# 窗口大小 (变量名已修正,避免覆盖 QWidget.window)
|
||||
self.window_size_spinbox = QSpinBox()
|
||||
self.window_size_spinbox.setRange(1, 20)
|
||||
self.window_size_spinbox.setValue(5)
|
||||
params_layout.addRow("窗口大小:", self.window_size_spinbox)
|
||||
|
||||
params_group.setLayout(params_layout)
|
||||
layout.addWidget(params_group)
|
||||
@ -160,7 +160,7 @@ class Step6_5Panel(QWidget):
|
||||
'algorithms': selected_algorithms,
|
||||
'value_cols': value_cols,
|
||||
'spectral_start_col': self.spectral_start_col.value(),
|
||||
'window': self.window.value(),
|
||||
'window': self.window_size_spinbox.value(),
|
||||
'enabled': self.enable_checkbox.isChecked()
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ class Step6_5Panel(QWidget):
|
||||
self.spectral_start_col.setValue(config['spectral_start_col'])
|
||||
|
||||
if 'window' in config:
|
||||
self.window.setValue(config['window'])
|
||||
self.window_size_spinbox.setValue(config['window'])
|
||||
if 'output_dir' in config:
|
||||
self.output_dir.set_path(config['output_dir'])
|
||||
if 'csv_path' in config:
|
||||
@ -218,38 +218,54 @@ class Step6_5Panel(QWidget):
|
||||
work_dir: 工作目录路径
|
||||
pipeline: Pipeline 实例(未使用,保留接口兼容性)
|
||||
"""
|
||||
if work_dir:
|
||||
self.work_dir = work_dir
|
||||
elif hasattr(self, 'work_dir') and self.work_dir:
|
||||
pass
|
||||
else:
|
||||
self.work_dir = None
|
||||
try:
|
||||
import traceback
|
||||
|
||||
# 1. 尝试从 Step5 界面读取训练光谱 CSV 路径
|
||||
main_window = self.window()
|
||||
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)
|
||||
if work_dir:
|
||||
self.work_dir = work_dir
|
||||
elif hasattr(self, 'work_dir') and self.work_dir:
|
||||
pass
|
||||
else:
|
||||
self.work_dir = None
|
||||
|
||||
# 2. 自动填充输出目录(8_Regression_Modeling)
|
||||
if self.work_dir:
|
||||
output_dir = os.path.join(self.work_dir, "8_Regression_Modeling")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
existing_out = self.output_dir.get_path()
|
||||
if not existing_out or not existing_out.strip():
|
||||
self.output_dir.set_path(output_dir)
|
||||
# 借用父组件的 window() 方法,安全绕过当前类的命名冲突
|
||||
parent_widget = self.parentWidget()
|
||||
main_window = parent_widget.window() if parent_widget else None
|
||||
if main_window and hasattr(main_window, 'step5_panel'):
|
||||
step5_widget = getattr(main_window.step5_panel, 'output_file', None)
|
||||
step5_output_path = ""
|
||||
if hasattr(step5_widget, 'get_path'):
|
||||
step5_output_path = step5_widget.get_path() or ""
|
||||
elif hasattr(step5_widget, 'text'):
|
||||
step5_output_path = step5_widget.text() or ""
|
||||
|
||||
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)
|
||||
|
||||
# 2. 自动填充输出目录(8_Regression_Modeling)
|
||||
if self.work_dir:
|
||||
output_dir = os.path.join(self.work_dir, "8_Regression_Modeling")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
existing_out = self.output_dir.get_path()
|
||||
if not existing_out or not existing_out.strip():
|
||||
self.output_dir.set_path(output_dir)
|
||||
except Exception as e:
|
||||
import traceback
|
||||
print(f"【{self.__class__.__name__}】自动填充失败,跳过: {e}")
|
||||
traceback.print_exc()
|
||||
|
||||
def _get_default_work_dir(self):
|
||||
"""获取 work_dir,优先用 panel 自身缓存的,否则尝试从主窗口取"""
|
||||
if hasattr(self, 'work_dir') and self.work_dir:
|
||||
return str(self.work_dir)
|
||||
mw = self.window()
|
||||
# 借用父组件的 window() 方法,安全绕过当前类的命名冲突
|
||||
parent_widget = self.parentWidget()
|
||||
mw = parent_widget.window() if parent_widget else None
|
||||
if mw and hasattr(mw, 'work_dir') and mw.work_dir:
|
||||
return str(mw.work_dir)
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user