Add partial save and load

This commit is contained in:
2026-02-12 19:47:17 +10:00
parent bfd42b330f
commit 1099339b35
+50
View File
@@ -1,3 +1,4 @@
import pickle
import tkinter as tk
from tkinter import StringVar, filedialog, messagebox, ttk
@@ -73,6 +74,9 @@ class MainWindow(ThemedTk):
menu_file.add_command(label="Save Rules", command=self.do_save_rules)
menu_file.add_command(label="Reload Rules", command=self.do_reload_rules)
menu_file.add_separator()
menu_file.add_command(label="Save Partial Transactions", command=self.do_save_partial)
menu_file.add_command(label="Load Partial Transactions", command=self.do_load_partial)
menu_file.add_separator()
menu_file.add_command(label="Exit", command=lambda: self.destroy())
self.menubar.add_cascade(menu=menu_file, label="File")
@@ -359,3 +363,49 @@ class MainWindow(ThemedTk):
"""
self.ruleset.reload_rules()
self.regenerate_rows()
def do_save_partial(self):
"""
Save all partial entries to be loaded later.
"""
flattened = {
"converter": self.converter.qual_name(),
"rows": self.rows,
"custom": self.custom,
}
result = pickle.dumps(flattened)
path = filedialog.asksaveasfilename(
defaultextension=".pickle",
filetypes=[
("All Files", "*.*"),
],
)
if path:
with open(path, "wb") as f:
f.write(result)
message = f"Saved progress to {path}"
else:
message = "Save cancelled"
self.update_status(message)
def do_load_partial(self):
# Prompt for file to ingest
path = filedialog.askopenfilename(
defaultextension=".pickle",
filetypes=[("Pickle Files", ".pickle"), ("All Files", "*.*")],
)
with open(path, "rb") as f:
result = pickle.load(f)
if result["converter"] != self.converter.qual_name():
messagebox.showerror(
"Load Error",
f"Cannot load partial data for converter '{result['converter']}'"
)
return
self.rows |= result["rows"]
self.custom |= result["custom"]
self.rowtree.update_rows(self.rows)
self.show_ingest_summary([path], self.rows)
self.rebuild_account_cache()