From 87a59a52079364cf9ba22bae54ff361126f1b58a Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Tue, 5 Mar 2024 11:33:38 +0100 Subject: [PATCH] Bring back opening last project --- main.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 430f4df..395ca51 100644 --- a/main.py +++ b/main.py @@ -62,6 +62,19 @@ def menu_file_new_project_click(): button_create.pack(side="bottom",fill="x",padx=5) +def open_project(file_path): + try: + project.load(file_path) + except AttributeError as e: + tkinter.messagebox.showerror("Opening project",f"Project '{file_path}' is invalid: {e}") + except IOError as e: + tkinter.messagebox.showerror("Opening project",f"Failed to open project '{file_path}': {e}") + finally: + canvas_editor.after_project_load() + canvas_editor.draw() + update_glyph_preview() + + def menu_file_open_project_click(): global project global canvas_editor @@ -77,16 +90,17 @@ def menu_file_open_project_click(): with open("last_path_cache.txt", "w") as f: f.write(file_path) + open_project(file_path) + + +def menu_file_open_last_project_click(): try: - project.load(file_path) - except AttributeError as e: - tkinter.messagebox.showerror("Opening project",f"Project '{file_path}' is invalid: {e}") - except IOError as e: - tkinter.messagebox.showerror("Opening project",f"Failed to open project '{file_path}': {e}") - finally: - canvas_editor.after_project_load() - canvas_editor.draw() - update_glyph_preview() + cache=open("last_path_cache.txt","r") + file_path=cache.read() + cache.close() + open_project(file_path) + except IOError: + tkinter.messagebox.showerror("Opening last project","Failed to load last project cache") def save_project(ask): @@ -109,6 +123,10 @@ def save_project(ask): if path=="" or path==(): return + # save last path to cache + with open("last_path_cache.txt", "w") as f: + f.write(path) + canvas_editor.save_char() try: project.save(path) @@ -201,6 +219,7 @@ menubar=tkinter.Menu(window) menu_file=tkinter.Menu(menubar,tearoff=False) menu_file.add_command(label="New project",command=menu_file_new_project_click) menu_file.add_command(label="Open project",command=menu_file_open_project_click) +menu_file.add_command(label="Open last project",command=menu_file_open_last_project_click) menu_file.add_command(label="Save project",command=lambda: save_project(False)) menu_file.add_command(label="Save project as",command=lambda: save_project(True)) menu_export=tkinter.Menu(menubar,tearoff=False)