remove custom size for custom style so that text can scale, scale the remaining node icons from the node picker, scale node's name

This commit is contained in:
Huy Pham 2020-02-12 14:13:28 -08:00
parent 7fbbfa8c63
commit 3a466fd463
5 changed files with 50 additions and 56 deletions

View file

@ -23,6 +23,7 @@ class Application(tk.Frame):
NodeUtils.setup()
self.fonts_size = {name: font.nametofont(name)["size"] for name in font.names()}
self.icon_text_font = font.Font(family="TkIconFont", size=12)
# widgets
self.menubar = None

View file

@ -81,7 +81,6 @@ class PreferencesDialog(Dialog):
value=1,
orient=tk.HORIZONTAL,
variable=self.gui_scale,
command=self.scale_adjust,
)
scale.grid(row=0, column=0, sticky="ew")
entry = ttk.Entry(
@ -113,19 +112,28 @@ class PreferencesDialog(Dialog):
preferences["gui3d"] = self.gui3d.get()
preferences["theme"] = self.theme.get()
self.app.save_config()
self.scale_adjust()
self.destroy()
def scale_adjust(self, scale: str):
def scale_adjust(self):
self.gui_scale.set(round(self.gui_scale.get(), 2))
app_scale = self.gui_scale.get()
self.app.canvas.app_scale = app_scale
self.app.master.tk.call("tk", "scaling", app_scale)
# scale fonts
scale_fonts(self.app.fonts_size, app_scale)
# screen_width = self.app.master.winfo_screenwidth()
# screen_height = self.app.master.winfo_screenheight()
# scaled_width = WIDTH * app_scale
# scaled_height = HEIGHT * app_scale
# x = int(screen_width / 2 - scaled_width / 2)
# y = int(screen_height / 2 - scaled_height / 2)
# self.app.master.geometry(f"{int(scaled_width)}x{int(scaled_height)}+{x}+{y}")
#
# self.app.toolbar.scale(app_scale)
self.app.icon_text_font.config(size=int(12 * app_scale))
# scale application widow size
screen_width = self.app.master.winfo_screenwidth()
screen_height = self.app.master.winfo_screenheight()
scaled_width = WIDTH * app_scale
scaled_height = HEIGHT * app_scale
x = int(screen_width / 2 - scaled_width / 2)
y = int(screen_height / 2 - scaled_height / 2)
self.app.master.geometry(f"{int(scaled_width)}x{int(scaled_height)}+{x}+{y}")
# scale toolbar icons and picker icons
self.app.toolbar.scale()

View file

@ -1,6 +1,5 @@
import logging
import tkinter as tk
from tkinter import font
from typing import TYPE_CHECKING
import grpc
@ -42,14 +41,13 @@ class CanvasNode:
self.id = self.canvas.create_image(
x, y, anchor=tk.CENTER, image=self.image, tags=tags.NODE
)
text_font = font.Font(family="TkIconFont", size=12)
label_y = self._get_label_y()
self.text_id = self.canvas.create_text(
x,
label_y,
text=self.core_node.name,
tags=tags.NODE_NAME,
font=text_font,
font=self.app.icon_text_font,
fill="#0000CD",
)
self.tooltip = CanvasTooltip(self.canvas)

View file

@ -176,27 +176,27 @@ def style_listbox(widget: tk.Widget):
def theme_change(event: tk.Event):
style = ttk.Style()
style.configure(Styles.picker_button, font=("TkDefaultFont", 8, "normal"))
style.configure(Styles.picker_button, font="TkSmallCaptionFont")
style.configure(
Styles.green_alert,
background="green",
padding=0,
relief=tk.NONE,
font=("TkDefaultFont", 8, "normal"),
font="TkSmallCaptionFont",
)
style.configure(
Styles.yellow_alert,
background="yellow",
padding=0,
relief=tk.NONE,
font=("TkDefaultFont", 8, "normal"),
font="TkSmallCaptionFont",
)
style.configure(
Styles.red_alert,
background="red",
padding=0,
relief=tk.NONE,
font=("TkDefaultFont", 8, "normal"),
font="TkSmallCaptionFont",
)
@ -204,4 +204,7 @@ def scale_fonts(fonts_size, scale):
for name in font.names():
f = font.nametofont(name)
if name in fonts_size:
f.config(size=int(fonts_size[name] * scale))
if name == "TkSmallCaptionFont":
f.config(size=int(fonts_size[name] * scale * 8 / 9))
else:
f.config(size=int(fonts_size[name] * scale))

View file

@ -4,7 +4,6 @@ import tkinter as tk
from enum import Enum
from functools import partial
from tkinter import messagebox, ttk
from tkinter.font import Font
from typing import TYPE_CHECKING, Callable
from core.api.grpc import core_pb2
@ -50,9 +49,6 @@ class Toolbar(ttk.Frame):
self.master = app.master
self.time = None
# picker data
self.picker_font = Font(size=8)
# design buttons
self.play_button = None
self.select_button = None
@ -198,9 +194,7 @@ class Toolbar(ttk.Frame):
for node_draw in NodeUtils.NODES:
toolbar_image = icon(node_draw.image_enum)
# image = icon(node_draw.image_enum, PICKER_SIZE)
image = self.get_icon(
node_draw.image_enum, PICKER_SIZE * self.app.canvas.app_scale
)
image = self.get_icon(node_draw.image_enum, PICKER_SIZE)
func = partial(
self.update_button,
self.node_button,
@ -214,9 +208,7 @@ class Toolbar(ttk.Frame):
for name in sorted(self.app.core.custom_nodes):
node_draw = self.app.core.custom_nodes[name]
toolbar_image = Images.get_custom(node_draw.image_file, TOOLBAR_SIZE)
image = Images.get_custom(
node_draw.image_file, int(PICKER_SIZE * self.app.canvas.app_scale)
)
image = Images.get_custom(node_draw.image_file, PICKER_SIZE)
func = partial(
self.update_button,
self.node_button,
@ -228,9 +220,7 @@ class Toolbar(ttk.Frame):
self.create_picker_button(image, func, self.node_picker, name)
# draw edit node
# image = icon(ImageEnum.EDITNODE, PICKER_SIZE)
image = self.get_icon(
ImageEnum.EDITNODE, PICKER_SIZE * self.app.canvas.app_scale
)
image = self.get_icon(ImageEnum.EDITNODE, PICKER_SIZE)
self.create_picker_button(
image, self.click_edit_node, self.node_picker, "Custom"
)
@ -386,7 +376,7 @@ class Toolbar(ttk.Frame):
self.network_picker = ttk.Frame(self.master)
for node_draw in NodeUtils.NETWORK_NODES:
toolbar_image = icon(node_draw.image_enum)
image = icon(node_draw.image_enum, PICKER_SIZE)
image = self.get_icon(node_draw.image_enum, PICKER_SIZE)
self.create_picker_button(
image,
partial(
@ -433,7 +423,7 @@ class Toolbar(ttk.Frame):
]
for image_enum, shape_type in nodes:
toolbar_image = icon(image_enum)
image = icon(image_enum, PICKER_SIZE)
image = self.get_icon(image_enum, PICKER_SIZE)
self.create_picker_button(
image,
partial(self.update_annotation, toolbar_image, shape_type, image_enum),
@ -538,29 +528,23 @@ class Toolbar(ttk.Frame):
def click_two_node_button(self):
logging.debug("Click TWONODE button")
@classmethod
def scale_button(cls, button, image_enum, scale):
image = icon(image_enum, int(TOOLBAR_SIZE * scale))
# def scale_button(cls, button, image_enum, scale):
def scale_button(self, button, image_enum):
image = icon(image_enum, int(TOOLBAR_SIZE * self.app.canvas.app_scale))
button.config(image=image)
button.image = image
def scale(self, scale):
self.scale_button(self.play_button, ImageEnum.START, scale)
self.scale_button(self.select_button, ImageEnum.SELECT, scale)
self.scale_button(self.link_button, ImageEnum.LINK, scale)
self.scale_button(self.node_button, self.node_enum, scale)
self.scale_button(self.network_button, self.network_enum, scale)
self.scale_button(self.annotation_button, self.annotation_enum, scale)
def scale(self):
self.scale_button(self.play_button, ImageEnum.START)
self.scale_button(self.select_button, ImageEnum.SELECT)
self.scale_button(self.link_button, ImageEnum.LINK)
self.scale_button(self.node_button, self.node_enum)
self.scale_button(self.network_button, self.network_enum)
self.scale_button(self.annotation_button, self.annotation_enum)
self.scale_button(self.runtime_select_button, ImageEnum.SELECT, scale)
self.scale_button(self.stop_button, ImageEnum.STOP, scale)
self.scale_button(self.plot_button, ImageEnum.PLOT, scale)
self.scale_button(self.runtime_marker_button, ImageEnum.MARKER, scale)
self.scale_button(self.node_command_button, ImageEnum.TWONODE, scale)
self.scale_button(self.run_command_button, ImageEnum.RUN, scale)
# self.stop_button = None
# self.plot_button = None
# self.runtime_marker_button = None
# self.node_command_button = None
# self.run_command_button = None
self.scale_button(self.runtime_select_button, ImageEnum.SELECT)
self.scale_button(self.stop_button, ImageEnum.STOP)
self.scale_button(self.plot_button, ImageEnum.PLOT)
self.scale_button(self.runtime_marker_button, ImageEnum.MARKER)
self.scale_button(self.node_command_button, ImageEnum.TWONODE)
self.scale_button(self.run_command_button, ImageEnum.RUN)