fixes to cross platform saves
This commit is contained in:
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,
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user