From b5afcec37d49fe333856cc18e332966cf6054af9 Mon Sep 17 00:00:00 2001 From: Tyler Date: Wed, 15 Oct 2025 17:09:51 -0700 Subject: [PATCH] fixes to cross platform saves --- flares.py | 13 ++++++++++++- main.py | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/flares.py b/flares.py index edb7f6d..21e4733 100644 --- a/flares.py +++ b/flares.py @@ -3069,5 +3069,16 @@ def process_participant(file_path, progress_callback=None): if progress_callback: progress_callback(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 \ No newline at end of file + 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] \ No newline at end of file diff --git a/main.py b/main.py index 08627ed..2b09069 100644 --- a/main.py +++ b/main.py @@ -19,7 +19,7 @@ import zipfile import platform import traceback import subprocess -from pathlib import Path +from pathlib import Path, PurePosixPath from datetime import datetime from multiprocessing import Process, current_process, freeze_support, Manager @@ -4276,12 +4276,26 @@ class MainApplication(QMainWindow): return try: - project_data = { - "file_list": [bubble.file_path for bubble in self.bubble_widgets.values()], - "progress_states": { - bubble.file_path: bubble.current_step for bubble in self.bubble_widgets.values() - }, + # Ensure the filename has the proper extension + if not filename.endswith(".flare"): + filename += ".flare" + 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, "epochs_dict": self.epochs_dict, "fig_bytes_dict": self.fig_bytes_dict, @@ -4294,6 +4308,17 @@ class MainApplication(QMainWindow): "group_dict": self.group_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: pickle.dump(project_data, f) @@ -4328,9 +4353,20 @@ class MainApplication(QMainWindow): self.group_dict = data.get("group_dict", {}) self.valid_dict = data.get("valid_dict", {}) - # Restore bubbles and progress - self.show_files_as_bubbles_from_list(data["file_list"], data.get("progress_states", {}), filename) + project_dir = Path(filename).parent + # 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 # self.button1.setVisible(True) self.button3.setVisible(True)