From d2d28b07821e6d99dac8218ba8de1dfa2cb4f54f Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Fri, 8 Mar 2024 18:38:17 +0100 Subject: [PATCH] Move zooming to View menu in menubar and use mouse scroll for changing glyphs --- canvas.py | 15 ++++++--------- main.py | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/canvas.py b/canvas.py index 3a622ed..3ea2c70 100644 --- a/canvas.py +++ b/canvas.py @@ -1,5 +1,4 @@ import base64 -import platform import tkinter GRID_COLOR = "#808080" @@ -25,12 +24,6 @@ class EditorCanvas(tkinter.Canvas): self.bind("",self.handle_move) self.bind("",self.handle_erase) self.bind("",self.handle_erase) - if platform.system()=="Windows" or platform.system()=="Darwin": - self.bind("",lambda event: self.handle_zoom(event.delta//120)) - else: - # This will probably work only on X11 - self.bind("",lambda _: self.handle_zoom(1)) - self.bind("",lambda _: self.handle_zoom(-1)) def draw(self): @@ -88,8 +81,12 @@ class EditorCanvas(tkinter.Canvas): self.draw() - def handle_zoom(self,delta): - self.grid_size+=delta + def zoom_by(self,amount): + self.grid_size+=amount + if self.grid_size<12: + self.grid_size=12 + elif self.grid_size>102: + self.grid_size=102 self.width=self.project.char_res[0]*self.grid_size self.height=self.project.char_res[1]*self.grid_size self.draw() diff --git a/main.py b/main.py index 395ca51..9238e88 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import os +import platform import tkinter.filedialog import unicodedata @@ -211,6 +212,18 @@ def update_glyph_preview(): label_glyph_name.config(text=f"{name} U+{canvas_editor.current_char:04x}") +def canvas_editor_handle_scroll(delta): + global canvas_editor + global project + if not project.loaded: + return + if delta>0: + canvas_editor.prev_glyph() + else: + canvas_editor.next_glyph() + update_glyph_preview() + + window=tkinter.Tk() window.title("fonteditor") window.geometry(f"{WINDOW_SIZE[0]}x{WINDOW_SIZE[1]}") @@ -225,11 +238,21 @@ menu_file.add_command(label="Save project as",command=lambda: save_project(True) menu_export=tkinter.Menu(menubar,tearoff=False) menu_export.add_command(label="Export",command=lambda: export_project(False)) menu_export.add_command(label="Export as",command=lambda: export_project(True)) +menu_view=tkinter.Menu(menubar,tearoff=False) +menu_view.add_command(label="Zoom in",command=lambda: canvas_editor.zoom_by(10)) +menu_view.add_command(label="Zoom out",command=lambda: canvas_editor.zoom_by(-10)) menubar.add_cascade(label="File",menu=menu_file) menubar.add_cascade(label="Export",menu=menu_export) +menubar.add_cascade(label="View",menu=menu_view) canvas_editor=EditorCanvas(project,window,bg="black") canvas_editor.pack(side="left",fill="both",expand=True) +if platform.system()=="Windows" or platform.system()=="Darwin": + canvas_editor.bind("",lambda event: canvas_editor_handle_scroll(event.delta)) +else: + # This will probably work only on X11 + canvas_editor.bind("",lambda _: canvas_editor_handle_scroll(1)) + canvas_editor.bind("",lambda _: canvas_editor_handle_scroll(-1)) frame_controls=tkinter.Frame(window) frame_controls.pack(side="right")