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

Added the ability to recognize custom fonts for MacOS #2575

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 16 additions & 7 deletions customtkinter/windows/widgets/font/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class FontManager:

linux_font_path = "~/.fonts/"
darwin_font_path = "~/Library/Fonts/"

@classmethod
def init_font_manager(cls):
Expand All @@ -24,6 +25,15 @@ def init_font_manager(cls):
else:
return True

@classmethod
def copy_fonts(cls, font_path: str, system_font_path: str) -> bool:
try:
shutil.copy(font_path, system_font_path)
return True
except Exception as err:
sys.stderr.write("FontManager error: " + str(err) + "\n")
return False

@classmethod
def windows_load_font(cls, font_path: Union[str, bytes], private: bool = True, enumerable: bool = False) -> bool:
""" Function taken from: https://stackoverflow.com/questions/11993290/truly-custom-font-in-tkinter/30631309#30631309 """
Expand Down Expand Up @@ -54,13 +64,12 @@ def load_font(cls, font_path: str) -> bool:

# Linux
elif sys.platform.startswith("linux"):
try:
shutil.copy(font_path, os.path.expanduser(cls.linux_font_path))
return True
except Exception as err:
sys.stderr.write("FontManager error: " + str(err) + "\n")
return False
return cls.copy_fonts(font_path, os.path.expanduser(cls.linux_font_path))

# macOS
elif sys.platform.startswith("darwin"):
return cls.copy_fonts(font_path, os.path.expanduser(cls.darwin_font_path))

# macOS and others
# others
else:
return False