2024-02-29 22:12:14 +01:00
|
|
|
import os
|
|
|
|
import unicodedata
|
|
|
|
from exporter import export
|
|
|
|
|
2024-03-02 12:28:14 +01:00
|
|
|
from canvas import *
|
|
|
|
from project import *
|
|
|
|
|
2024-02-29 22:12:14 +01:00
|
|
|
##### CONFIG #####
|
|
|
|
|
2024-03-01 20:37:08 +01:00
|
|
|
WINDOW_SIZE = (
|
2024-03-01 21:40:25 +01:00
|
|
|
(1280,720),
|
|
|
|
(1920,1019)
|
2024-02-29 22:12:14 +01:00
|
|
|
)[0]
|
|
|
|
|
|
|
|
cross_color = (255, 60, 25)
|
|
|
|
pixel_color = (255,) * 3
|
|
|
|
|
|
|
|
##################
|
|
|
|
|
2024-03-02 12:28:14 +01:00
|
|
|
project=Project()
|
2024-03-01 21:40:25 +01:00
|
|
|
|
2024-03-01 20:37:08 +01:00
|
|
|
def menu_file_open_project_click():
|
2024-03-02 12:28:14 +01:00
|
|
|
global project
|
2024-03-01 21:40:25 +01:00
|
|
|
global canvas_editor
|
|
|
|
|
|
|
|
file_path = tkinter.filedialog.askopenfilename(
|
|
|
|
title="Open font project",
|
|
|
|
filetypes=[("Font project (json)", "*.fontproj")]
|
|
|
|
)
|
|
|
|
if file_path == "":
|
|
|
|
return
|
|
|
|
|
|
|
|
# save last path to cache
|
|
|
|
with open("last_path_cache.txt", "w") as f:
|
|
|
|
f.write(file_path)
|
|
|
|
|
2024-03-02 12:28:14 +01:00
|
|
|
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()
|
2024-03-01 21:40:25 +01:00
|
|
|
|
2024-02-29 22:12:14 +01:00
|
|
|
|
2024-03-01 20:37:08 +01:00
|
|
|
def menu_file_save_project_click():
|
|
|
|
pass
|
2024-02-29 22:12:14 +01:00
|
|
|
|
2024-03-01 20:37:08 +01:00
|
|
|
def menu_file_save_project_as_click():
|
|
|
|
pass
|
2024-02-29 22:12:14 +01:00
|
|
|
|
2024-03-01 21:52:39 +01:00
|
|
|
def button_prev_glyph_click():
|
2024-03-02 12:28:14 +01:00
|
|
|
canvas_editor.prev_glyph()
|
2024-03-01 21:52:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
def button_next_glyph_click():
|
2024-03-02 12:28:14 +01:00
|
|
|
canvas_editor.next_glyph()
|
2024-03-01 21:52:39 +01:00
|
|
|
|
|
|
|
|
2024-03-01 20:37:08 +01:00
|
|
|
def number_only_validate(val):
|
|
|
|
return str.isdigit(val) or val==""
|
2024-02-29 22:12:14 +01:00
|
|
|
|
2024-03-01 21:52:39 +01:00
|
|
|
|
2024-03-01 20:37:08 +01:00
|
|
|
window=tkinter.Tk()
|
|
|
|
window.title("fonteditor")
|
2024-03-01 21:40:25 +01:00
|
|
|
window.geometry(f"{WINDOW_SIZE[0]}x{WINDOW_SIZE[1]}")
|
2024-02-29 22:12:14 +01:00
|
|
|
|
2024-03-01 20:37:08 +01:00
|
|
|
menubar=tkinter.Menu(window)
|
|
|
|
menu_file=tkinter.Menu(menubar,tearoff=False)
|
|
|
|
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 as",command=menu_file_save_project_as_click)
|
|
|
|
menubar.add_cascade(label="File",menu=menu_file)
|
2024-02-29 22:12:14 +01:00
|
|
|
|
2024-03-02 12:28:14 +01:00
|
|
|
canvas_editor=EditorCanvas(project,window,bg="black")
|
2024-03-01 21:40:25 +01:00
|
|
|
canvas_editor.pack(side="left")
|
2024-02-29 22:12:14 +01:00
|
|
|
|
2024-03-01 20:37:08 +01:00
|
|
|
frame_controls=tkinter.Frame(window)
|
|
|
|
frame_controls.pack()
|
2024-02-29 22:12:14 +01:00
|
|
|
|
2024-03-01 20:37:08 +01:00
|
|
|
canvas_preview=tkinter.Canvas(frame_controls,width=100,height=200,bg="black")
|
|
|
|
canvas_preview.pack(side="top")
|
2024-02-29 22:12:14 +01:00
|
|
|
|
2024-03-01 20:37:08 +01:00
|
|
|
label_glyph_name=tkinter.Label(frame_controls,text="Placeholder")
|
|
|
|
label_glyph_name.pack(side="top")
|
2024-02-29 22:12:14 +01:00
|
|
|
|
2024-03-01 20:37:08 +01:00
|
|
|
frame_nav=tkinter.Frame(frame_controls)
|
|
|
|
frame_nav.pack(side="top",pady=10)
|
2024-02-29 22:12:14 +01:00
|
|
|
|
2024-03-01 21:52:39 +01:00
|
|
|
button_prev_glyph=tkinter.Button(frame_nav,width=10,text="Previous",command=button_prev_glyph_click)
|
2024-03-01 20:37:08 +01:00
|
|
|
button_prev_glyph.pack(side="left")
|
2024-02-29 22:12:14 +01:00
|
|
|
|
2024-03-01 21:52:39 +01:00
|
|
|
button_next_glyph=tkinter.Button(frame_nav,width=10,text="Next",command=button_next_glyph_click)
|
2024-03-01 20:37:08 +01:00
|
|
|
button_next_glyph.pack(side="left")
|
|
|
|
|
|
|
|
frame_glyph_id=tkinter.Frame(frame_controls)
|
|
|
|
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.pack(side="left")
|
|
|
|
|
|
|
|
button_glyph_search=tkinter.Button(frame_glyph_id,width=10,text="Search")
|
|
|
|
button_glyph_search.pack(side="left")
|
|
|
|
|
|
|
|
window.config(menu=menubar)
|
|
|
|
window.mainloop()
|