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)
|
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():
|
def menu_file_open_project_click():
|
||||||
global project
|
global project
|
||||||
global canvas_editor
|
global canvas_editor
|
||||||
@ -77,16 +90,17 @@ def menu_file_open_project_click():
|
|||||||
with open("last_path_cache.txt", "w") as f:
|
with open("last_path_cache.txt", "w") as f:
|
||||||
f.write(file_path)
|
f.write(file_path)
|
||||||
|
|
||||||
|
open_project(file_path)
|
||||||
|
|
||||||
|
|
||||||
|
def menu_file_open_last_project_click():
|
||||||
try:
|
try:
|
||||||
project.load(file_path)
|
cache=open("last_path_cache.txt","r")
|
||||||
except AttributeError as e:
|
file_path=cache.read()
|
||||||
tkinter.messagebox.showerror("Opening project",f"Project '{file_path}' is invalid: {e}")
|
cache.close()
|
||||||
except IOError as e:
|
open_project(file_path)
|
||||||
tkinter.messagebox.showerror("Opening project",f"Failed to open project '{file_path}': {e}")
|
except IOError:
|
||||||
finally:
|
tkinter.messagebox.showerror("Opening last project","Failed to load last project cache")
|
||||||
canvas_editor.after_project_load()
|
|
||||||
canvas_editor.draw()
|
|
||||||
update_glyph_preview()
|
|
||||||
|
|
||||||
|
|
||||||
def save_project(ask):
|
def save_project(ask):
|
||||||
@ -109,6 +123,10 @@ def save_project(ask):
|
|||||||
if path=="" or path==():
|
if path=="" or path==():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# save last path to cache
|
||||||
|
with open("last_path_cache.txt", "w") as f:
|
||||||
|
f.write(path)
|
||||||
|
|
||||||
canvas_editor.save_char()
|
canvas_editor.save_char()
|
||||||
try:
|
try:
|
||||||
project.save(path)
|
project.save(path)
|
||||||
@ -201,6 +219,7 @@ menubar=tkinter.Menu(window)
|
|||||||
menu_file=tkinter.Menu(menubar,tearoff=False)
|
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="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 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",command=lambda: save_project(False))
|
||||||
menu_file.add_command(label="Save project as",command=lambda: save_project(True))
|
menu_file.add_command(label="Save project as",command=lambda: save_project(True))
|
||||||
menu_export=tkinter.Menu(menubar,tearoff=False)
|
menu_export=tkinter.Menu(menubar,tearoff=False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user