import os import unicodedata from exporter import export from canvas import * from project import * ##### CONFIG ##### WINDOW_SIZE = ( (1280,720), (1920,1019) )[0] cross_color = (255, 60, 25) pixel_color = (255,) * 3 ################## project=Project() def menu_file_open_project_click(): global project global canvas_editor file_path = tkinter.filedialog.askopenfilename( title="Open font project", filetypes=[("Font project (json)", "*.fontproj")] ) if file_path == "" or file_path==(): return # save last path to cache with open("last_path_cache.txt", "w") as f: f.write(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() def menu_file_save_project_click(): 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=="" or file_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(): pass def button_prev_glyph_click(): canvas_editor.prev_glyph() def button_next_glyph_click(): canvas_editor.next_glyph() def number_only_validate(val): return str.isdigit(val) or val=="" window=tkinter.Tk() window.title("fonteditor") window.geometry(f"{WINDOW_SIZE[0]}x{WINDOW_SIZE[1]}") 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) canvas_editor=EditorCanvas(project,window,bg="black") canvas_editor.pack(side="left",fill="both",expand=True) frame_controls=tkinter.Frame(window) frame_controls.pack(side="right") canvas_preview=tkinter.Canvas(frame_controls,width=100,height=200,bg="black") canvas_preview.pack(side="top") label_glyph_name=tkinter.Label(frame_controls,text="Placeholder") label_glyph_name.pack(side="top") frame_nav=tkinter.Frame(frame_controls) frame_nav.pack(side="top",pady=10) button_prev_glyph=tkinter.Button(frame_nav,width=10,text="Previous",command=button_prev_glyph_click) button_prev_glyph.pack(side="left") button_next_glyph=tkinter.Button(frame_nav,width=10,text="Next",command=button_next_glyph_click) 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()