Implement project saving
This commit is contained in:
parent
f552becc18
commit
164b71a0c3
21
main.py
21
main.py
@ -46,7 +46,26 @@ def menu_file_open_project_click():
|
|||||||
|
|
||||||
|
|
||||||
def menu_file_save_project_click():
|
def menu_file_save_project_click():
|
||||||
pass
|
global project
|
||||||
|
|
||||||
|
path=None
|
||||||
|
if project.loaded:
|
||||||
|
path=project.path
|
||||||
|
else:
|
||||||
|
# show file save dialog
|
||||||
|
path=filedialog.asksaveasfilename(
|
||||||
|
title="Save font project",
|
||||||
|
filetypes=[("Font project (json)", "*.fontproj")],
|
||||||
|
defaultextension=".fontproj"
|
||||||
|
)
|
||||||
|
if path=="":
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
project.save(path)
|
||||||
|
except IOError as e:
|
||||||
|
tkinter.messagebox.showerror("Saving project",f"Failed to save project '{path}': {e}")
|
||||||
|
|
||||||
|
|
||||||
def menu_file_save_project_as_click():
|
def menu_file_save_project_as_click():
|
||||||
pass
|
pass
|
||||||
|
12
project.py
12
project.py
@ -25,5 +25,17 @@ class Project:
|
|||||||
self.loaded=True
|
self.loaded=True
|
||||||
|
|
||||||
|
|
||||||
|
def save(self,path):
|
||||||
|
# save project data to file
|
||||||
|
with open(path, "w") as f:
|
||||||
|
json.dump({
|
||||||
|
"char_width": self.char_res[0],
|
||||||
|
"char_height": self.char_res[1],
|
||||||
|
"chars": self.chars
|
||||||
|
}, f, indent=4)
|
||||||
|
self.path=path
|
||||||
|
self.loaded=True
|
||||||
|
|
||||||
|
|
||||||
def does_char_exist(self,c):
|
def does_char_exist(self,c):
|
||||||
return chr(c) in self.chars
|
return chr(c) in self.chars
|
||||||
|
Loading…
x
Reference in New Issue
Block a user