fixes to cross platform saves
This commit is contained in:
11
flares.py
11
flares.py
@@ -3070,4 +3070,15 @@ 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
|
||||
|
||||
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
52
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,
|
||||
@@ -4295,6 +4309,17 @@ class MainApplication(QMainWindow):
|
||||
"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,8 +4353,19 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user