Bring back opening last project
This commit is contained in:
parent
8c4eb2ddf9
commit
87a59a5207
37
main.py
37
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)
|
||||
|
Loading…
Reference in New Issue
Block a user