Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font-fixes #129

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified dist/EX-Installer-Linux64
Binary file not shown.
Binary file removed dist/EX-Installer-Win32.exe
Binary file not shown.
Binary file modified dist/EX-Installer-Win64.exe
Binary file not shown.
Binary file removed dist/EX-Installer-macOS
Binary file not shown.
73 changes: 73 additions & 0 deletions ex_installer/common_fonts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Module to define widgets used across the application

Every view should include this module and base the layout on WindowLayout

© 2024, Peter Cole. All rights reserved.

This file is part of EX-Installer.

This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

It is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
"""

# Import Python modules
import customtkinter as ctk
import sys


class CommonFonts(ctk.CTkFont):
"""
Class to define common fonts used across all application modules/classes
"""
default_font = "Arial"

if sys.platform.startswith("lin"):
default_font = "FreeSans"

def __init__(self, root):
super().__init__(family=self.default_font)

# Define fonts
self.instruction_font = ctk.CTkFont(family=self.default_font,
size=14,
weight="normal")

self.bold_instruction_font = ctk.CTkFont(family=self.default_font,
size=14,
weight="bold")

self.large_bold_instruction_font = ctk.CTkFont(family=self.default_font,
size=16,
weight="bold")

self.small_italic_instruction_font = ctk.CTkFont(family=self.default_font,
size=12,
weight="normal",
slant="italic")

self.title_font = ctk.CTkFont(family=self.default_font,
size=30,
weight="normal")

self.heading_font = ctk.CTkFont(family=self.default_font,
size=24,
weight="bold")

self.button_font = ctk.CTkFont(family=self.default_font,
size=13,
weight="bold")

self.action_button_font = ctk.CTkFont(family=self.default_font,
size=16,
weight="bold")
54 changes: 24 additions & 30 deletions ex_installer/common_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# Import local modules
from . import images
from .serial_monitor import SerialMonitor
from .common_fonts import CommonFonts


class WindowLayout(ctk.CTkFrame):
Expand All @@ -54,6 +55,9 @@ def __init__(self, parent, *args, **kwargs):
self.acli = parent.acli
self.git = parent.git

# Set up fonts
self.common_fonts = CommonFonts(self)

# Get application version
self.app_version = parent.app_version

Expand All @@ -76,31 +80,14 @@ def __init__(self, parent, *args, **kwargs):
self.widget_states = []

# Define fonts
self.instruction_font = ctk.CTkFont(family="Helvetica",
size=14,
weight="normal")
self.bold_instruction_font = ctk.CTkFont(family="Helvetica",
size=14,
weight="bold")
self.large_bold_instruction_font = ctk.CTkFont(family="Helvetica",
size=16,
weight="bold")
self.small_italic_instruction_font = ctk.CTkFont(family="Helvetica",
size=12,
weight="normal",
slant="italic")
self.title_font = ctk.CTkFont(family="Helvetica",
size=30,
weight="normal")
self.heading_font = ctk.CTkFont(family="Helvetica",
size=24,
weight="bold")
self.button_font = ctk.CTkFont(family="Helvetica",
size=13,
weight="bold")
self.action_button_font = ctk.CTkFont(family="Helvetica",
size=16,
weight="bold")
self.instruction_font = self.common_fonts.instruction_font
self.bold_instruction_font = self.common_fonts.bold_instruction_font
self.large_bold_instruction_font = self.common_fonts.large_bold_instruction_font
self.small_italic_instruction_font = self.common_fonts.small_italic_instruction_font
self.title_font = self.common_fonts.title_font
self.heading_font = self.common_fonts.heading_font
self.button_font = self.common_fonts.button_font
self.action_button_font = self.common_fonts.action_button_font

# Define top level frames
self.title_frame = ctk.CTkFrame(self, width=790, height=80)
Expand Down Expand Up @@ -252,7 +239,10 @@ def __init__(self, parent, *args, **kwargs):

self.grid_columnconfigure((0, 1, 2, 3, 4), weight=1)

button_font = ctk.CTkFont(family="Helvetica", size=14, weight="bold")
# Set up fonts
self.common_fonts = CommonFonts(self)

button_font = self.common_fonts.button_font
button_options = {"width": 220, "height": 30, "font": button_font}

self.back_arrow = Image.open(images.BACK_ARROW)
Expand Down Expand Up @@ -396,7 +386,10 @@ def __init__(self, *args, **kwargs):
"""
super().__init__(*args, **kwargs)

default_font = ctk.CTkFont(family="Helvetica", size=14, weight="normal")
# Set up fonts
self.common_fonts = CommonFonts(self)

default_font = self.common_fonts.instruction_font
em = default_font.measure("m")
lmargin2 = em + default_font.measure("\u2022")
self.tag_config("bullet", lmargin1=em, lmargin2=lmargin2, spacing1=1, spacing2=1, spacing3=1)
Expand Down Expand Up @@ -435,6 +428,9 @@ def __init__(self, widget, text='widget info', url=None):
self.id = None
self.tw = None

# Set up fonts
self.common_fonts = CommonFonts(self)

def enter_widget(self, event=None):
"""
When hovered/entered widget, schedule it to start
Expand Down Expand Up @@ -470,9 +466,7 @@ def show_tooltip(self, event=None):
"""
Show the tooltip
"""
tooltip_font = ctk.CTkFont(family="Helvetica",
size=16,
weight="bold")
tooltip_font = self.common_fonts.bold_instruction_font
x = y = 0
x, y, cx, cy = self.widget.bbox("insert")
x += self.widget.winfo_rootx() + 25
Expand Down
6 changes: 5 additions & 1 deletion ex_installer/ex_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from .advanced_config import AdvancedConfig
from .compile_upload import CompileUpload
from ex_installer.version import ex_installer_version
from .common_fonts import CommonFonts

# Set theme and appearance, and deactive screen scaling
ctk.set_default_color_theme(theme.DCC_EX_THEME)
Expand Down Expand Up @@ -81,6 +82,9 @@ def __init__(self, *args, **kwargs):
# Dictionary to retain views once created for switching between them while retaining options
self.frames = {}

# Set up fonts
self.common_fonts = CommonFonts(self)

# Set window geometry, title, and icon
self.title("EX-Installer")

Expand Down Expand Up @@ -246,7 +250,7 @@ def about(self):
about_box = CTkMessagebox(master=self, title="About EX-Installer", icon="info",
message=about_message, border_width=3, cancel_button=None,
option_2="OK", option_1="Show log", icon_size=(30, 30),
font=ctk.CTkFont(family="Helvetica", size=14, weight="normal"))
font=self.common_fonts.instruction_font)
if about_box.get() == "Show log":
log_file = None
for handler in self.log.parent.handlers:
Expand Down
8 changes: 6 additions & 2 deletions ex_installer/serial_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

# Import local modules
from . import images
from .common_fonts import CommonFonts

# Define valid monitor highlights
monitor_highlights = {
Expand Down Expand Up @@ -83,6 +84,9 @@ def __init__(self, parent, *args, **kwargs):
self.log.debug("Open window")
self.report_callback_exception = self.exception_handler

# Set up fonts
self.common_fonts = CommonFonts(self)

# Set up event handlers
event_callbacks = {
"<<Monitor>>": self.monitor
Expand Down Expand Up @@ -125,8 +129,8 @@ def __init__(self, parent, *args, **kwargs):
self.window_frame.grid(column=0, row=0, sticky="nsew")

# Define fonts for use
button_font = ctk.CTkFont(family="Helvetica", size=13, weight="bold")
instruction_font = ctk.CTkFont(family="Helvetica", size=14, weight="normal")
button_font = self.common_fonts.button_font
instruction_font = self.common_fonts.instruction_font

self.command_frame = ctk.CTkFrame(self.window_frame, width=790, height=40)
self.monitor_frame = ctk.CTkFrame(self.window_frame, width=790, height=420)
Expand Down
6 changes: 3 additions & 3 deletions ex_installer/theme/dcc-ex-theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@
},
"CTkFont": {
"macOS": {
"family": "Helvetica",
"family": "Arial",
"size": 13,
"weight": "normal"
},
"Windows": {
"family": "Helvetica",
"family": "Arial",
"size": 13,
"weight": "normal"
},
"Linux": {
"family": "Helvetica",
"family": "FreeSans",
"size": 13,
"weight": "normal"
}
Expand Down
4 changes: 3 additions & 1 deletion ex_installer/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
read by the application build process to embed in the application details
"""

ex_installer_version = "0.0.16"
ex_installer_version = "0.0.17"

"""
Version history:

0.0.17 - Move fonts to a separate common class
- Change default font to Arial for Windows/Mac and FreeSans for Linux
0.0.16 - Implement less restrictive matching for context highlights in Device Monitor
- Implement device specific restrictions and recommendations:
- Uno/Nano disable TrackManager, select disable EEPROM/PROG options by default
Expand Down
Loading