fixes to cross platform saves

This commit is contained in:
2025-10-15 17:09:51 -07:00
parent 5361f6ea21
commit b5afcec37d
2 changed files with 56 additions and 9 deletions

View File

@@ -3070,4 +3070,15 @@ def process_participant(file_path, progress_callback=None):
if progress_callback: progress_callback(20) if progress_callback: progress_callback(20)
logger.info("20") logger.info("20")
sanitize_paths_for_pickle(raw_haemo, epochs)
return raw_haemo, epochs, fig_bytes, cha, contrast_results, df_ind, design_matrix, AGE, GENDER, GROUP, True return raw_haemo, epochs, fig_bytes, cha, contrast_results, df_ind, design_matrix, AGE, GENDER, GROUP, True
def sanitize_paths_for_pickle(raw_haemo, epochs):
# Fix raw_haemo._filenames
if hasattr(raw_haemo, '_filenames'):
raw_haemo._filenames = [str(p) for p in raw_haemo._filenames]
# Fix epochs._raw._filenames
if hasattr(epochs, '_raw') and hasattr(epochs._raw, '_filenames'):
epochs._raw._filenames = [str(p) for p in epochs._raw._filenames]

52
main.py
View File

@@ -19,7 +19,7 @@ import zipfile
import platform import platform
import traceback import traceback
import subprocess import subprocess
from pathlib import Path from pathlib import Path, PurePosixPath
from datetime import datetime from datetime import datetime
from multiprocessing import Process, current_process, freeze_support, Manager from multiprocessing import Process, current_process, freeze_support, Manager
@@ -4276,12 +4276,26 @@ class MainApplication(QMainWindow):
return return
try: try:
project_data = { # Ensure the filename has the proper extension
"file_list": [bubble.file_path for bubble in self.bubble_widgets.values()], if not filename.endswith(".flare"):
"progress_states": { filename += ".flare"
bubble.file_path: bubble.current_step for bubble in self.bubble_widgets.values()
},
project_path = Path(filename).resolve()
project_dir = project_path.parent
file_list = [
str(PurePosixPath(Path(bubble.file_path).resolve().relative_to(project_dir)))
for bubble in self.bubble_widgets.values()
]
progress_states = {
str(PurePosixPath(Path(bubble.file_path).resolve().relative_to(project_dir))): bubble.current_step
for bubble in self.bubble_widgets.values()
}
project_data = {
"file_list": file_list,
"progress_states": progress_states,
"raw_haemo_dict": self.raw_haemo_dict, "raw_haemo_dict": self.raw_haemo_dict,
"epochs_dict": self.epochs_dict, "epochs_dict": self.epochs_dict,
"fig_bytes_dict": self.fig_bytes_dict, "fig_bytes_dict": self.fig_bytes_dict,
@@ -4295,6 +4309,17 @@ class MainApplication(QMainWindow):
"valid_dict": self.valid_dict, "valid_dict": self.valid_dict,
} }
def sanitize(obj):
if isinstance(obj, Path):
return str(PurePosixPath(obj))
elif isinstance(obj, dict):
return {sanitize(k): sanitize(v) for k, v in obj.items()}
elif isinstance(obj, list):
return [sanitize(i) for i in obj]
return obj
project_data = sanitize(project_data)
with open(filename, "wb") as f: with open(filename, "wb") as f:
pickle.dump(project_data, f) pickle.dump(project_data, f)
@@ -4328,8 +4353,19 @@ class MainApplication(QMainWindow):
self.group_dict = data.get("group_dict", {}) self.group_dict = data.get("group_dict", {})
self.valid_dict = data.get("valid_dict", {}) self.valid_dict = data.get("valid_dict", {})
# Restore bubbles and progress project_dir = Path(filename).parent
self.show_files_as_bubbles_from_list(data["file_list"], data.get("progress_states", {}), filename)
# Convert saved relative paths to absolute paths
file_list = [str((project_dir / Path(rel_path)).resolve()) for rel_path in data["file_list"]]
# Also resolve progress_states with updated paths
raw_progress = data.get("progress_states", {})
progress_states = {
str((project_dir / Path(rel_path)).resolve()): step
for rel_path, step in raw_progress.items()
}
self.show_files_as_bubbles_from_list(file_list, progress_states, filename)
# Re-enable buttons # Re-enable buttons
# self.button1.setVisible(True) # self.button1.setVisible(True)