Implement new project creation
This commit is contained in:
parent
2b9505b7b3
commit
7b07074989
@ -54,10 +54,11 @@ class EditorCanvas(tkinter.Canvas):
|
|||||||
|
|
||||||
|
|
||||||
def handle_draw(self,event):
|
def handle_draw(self,event):
|
||||||
self.current_char_modified=True
|
|
||||||
pixel_pos=self.cursor_pos_to_pixel((event.x,event.y))
|
pixel_pos=self.cursor_pos_to_pixel((event.x,event.y))
|
||||||
if not pixel_pos:
|
if not pixel_pos:
|
||||||
return
|
return
|
||||||
|
self.current_char_modified=True
|
||||||
|
self.project.modified=True
|
||||||
self.current_char_pixels[pixel_pos[0]*self.project.char_res[1]+pixel_pos[1]]=1
|
self.current_char_pixels[pixel_pos[0]*self.project.char_res[1]+pixel_pos[1]]=1
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
|
61
main.py
61
main.py
@ -19,6 +19,49 @@ pixel_color = (255,) * 3
|
|||||||
|
|
||||||
project=Project()
|
project=Project()
|
||||||
|
|
||||||
|
def button_create_project_click(subwindow,w,h):
|
||||||
|
try:
|
||||||
|
width=int(w)
|
||||||
|
except ValueError as e:
|
||||||
|
tkinter.messagebox.showerror("Creating new project", f"Invalid value {w}: {e}")
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
height=int(h)
|
||||||
|
except ValueError as e:
|
||||||
|
tkinter.messagebox.showerror("Creating new project", f"Invalid value {h}: {e}")
|
||||||
|
return
|
||||||
|
project.chars={}
|
||||||
|
project.char_res=(width,height)
|
||||||
|
project.loaded=True
|
||||||
|
canvas_editor.after_project_load()
|
||||||
|
canvas_editor.draw()
|
||||||
|
update_glyph_preview()
|
||||||
|
subwindow.destroy()
|
||||||
|
|
||||||
|
|
||||||
|
def menu_file_new_project_click():
|
||||||
|
global window
|
||||||
|
if project.modified and not tkinter.messagebox.askyesno("Creating new project","You have unsaved changes, are you sure?"):
|
||||||
|
return
|
||||||
|
subwindow=tkinter.Toplevel(window)
|
||||||
|
subwindow.title("New project")
|
||||||
|
|
||||||
|
label_width=tkinter.Label(subwindow,text="Character width")
|
||||||
|
label_width.pack(side="top")
|
||||||
|
|
||||||
|
entry_width=tkinter.Entry(subwindow,validate="all",validatecommand=((subwindow.register(number_only_validate)),"%P"))
|
||||||
|
entry_width.pack(side="top",fill="x",padx=5)
|
||||||
|
|
||||||
|
label_height=tkinter.Label(subwindow,text="Character height")
|
||||||
|
label_height.pack(side="top")
|
||||||
|
|
||||||
|
entry_height=tkinter.Entry(subwindow,validate="all",validatecommand=((subwindow.register(number_only_validate)),"%P"))
|
||||||
|
entry_height.pack(side="top",fill="x",padx=5)
|
||||||
|
|
||||||
|
button_create=tkinter.Button(subwindow,text="Create",command=lambda: button_create_project_click(subwindow,entry_width.get(),entry_height.get()))
|
||||||
|
button_create.pack(side="bottom",fill="x",padx=5)
|
||||||
|
|
||||||
|
|
||||||
def menu_file_open_project_click():
|
def menu_file_open_project_click():
|
||||||
global project
|
global project
|
||||||
global canvas_editor
|
global canvas_editor
|
||||||
@ -47,21 +90,26 @@ def menu_file_open_project_click():
|
|||||||
|
|
||||||
|
|
||||||
def menu_file_save_project_click():
|
def menu_file_save_project_click():
|
||||||
|
global canvas_editor
|
||||||
global project
|
global project
|
||||||
|
|
||||||
|
if not project.loaded:
|
||||||
|
return
|
||||||
|
|
||||||
path=None
|
path=None
|
||||||
if project.loaded:
|
if project.path:
|
||||||
path=project.path
|
path=project.path
|
||||||
else:
|
else:
|
||||||
# show file save dialog
|
# show file save dialog
|
||||||
path=filedialog.asksaveasfilename(
|
path=tkinter.filedialog.asksaveasfilename(
|
||||||
title="Save font project",
|
title="Save font project",
|
||||||
filetypes=[("Font project (json)", "*.fontproj")],
|
filetypes=[("Font project (json)", "*.fontproj")],
|
||||||
defaultextension=".fontproj"
|
defaultextension=".fontproj"
|
||||||
)
|
)
|
||||||
if path=="" or file_path==():
|
if path=="" or path==():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
canvas_editor.save_char()
|
||||||
try:
|
try:
|
||||||
project.save(path)
|
project.save(path)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
@ -107,6 +155,10 @@ def button_glyph_search_click():
|
|||||||
|
|
||||||
|
|
||||||
def number_only_validate(val):
|
def number_only_validate(val):
|
||||||
|
return val.isdigit()
|
||||||
|
|
||||||
|
|
||||||
|
def hex_only_validate(val):
|
||||||
for x in val:
|
for x in val:
|
||||||
if not x.isdigit() and (ord(x)<ord("a") or ord(x)>ord("f")) and (ord(x)<ord("A") or ord(x)>ord("F")):
|
if not x.isdigit() and (ord(x)<ord("a") or ord(x)>ord("f")) and (ord(x)<ord("A") or ord(x)>ord("F")):
|
||||||
return False
|
return False
|
||||||
@ -129,6 +181,7 @@ window.geometry(f"{WINDOW_SIZE[0]}x{WINDOW_SIZE[1]}")
|
|||||||
|
|
||||||
menubar=tkinter.Menu(window)
|
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="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="Save project",command=menu_file_save_project_click)
|
menu_file.add_command(label="Save project",command=menu_file_save_project_click)
|
||||||
menu_file.add_command(label="Save project as",command=menu_file_save_project_as_click)
|
menu_file.add_command(label="Save project as",command=menu_file_save_project_as_click)
|
||||||
@ -158,7 +211,7 @@ button_next_glyph.pack(side="left")
|
|||||||
frame_glyph_id=tkinter.Frame(frame_controls)
|
frame_glyph_id=tkinter.Frame(frame_controls)
|
||||||
frame_glyph_id.pack(side="top",pady=10)
|
frame_glyph_id.pack(side="top",pady=10)
|
||||||
|
|
||||||
entry_glyph_id=tkinter.Entry(frame_glyph_id,validate="all",validatecommand=((window.register(number_only_validate)),"%P"))
|
entry_glyph_id=tkinter.Entry(frame_glyph_id,validate="all",validatecommand=((window.register(hex_only_validate)),"%P"))
|
||||||
entry_glyph_id.pack(side="left")
|
entry_glyph_id.pack(side="left")
|
||||||
|
|
||||||
button_glyph_search=tkinter.Button(frame_glyph_id,width=10,text="Search",command=button_glyph_search_click)
|
button_glyph_search=tkinter.Button(frame_glyph_id,width=10,text="Search",command=button_glyph_search_click)
|
||||||
|
@ -6,6 +6,7 @@ class Project:
|
|||||||
self.char_res=(0,0)
|
self.char_res=(0,0)
|
||||||
self.path=None
|
self.path=None
|
||||||
self.loaded=False
|
self.loaded=False
|
||||||
|
self.modified=False
|
||||||
|
|
||||||
|
|
||||||
def load(self,path):
|
def load(self,path):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user