From f78eda9744ef42709557ad78df27957ca2970c3d Mon Sep 17 00:00:00 2001 From: Tom Schimansky Date: Fri, 11 Mar 2022 13:15:47 +0100 Subject: [PATCH] fixed font loading for linux --- customtkinter/__init__.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/customtkinter/__init__.py b/customtkinter/__init__.py index fb13f79..85e8356 100644 --- a/customtkinter/__init__.py +++ b/customtkinter/__init__.py @@ -22,6 +22,7 @@ from distutils.version import StrictVersion as Version import tkinter import os import sys +import shutil def enable_macos_darkmode(): @@ -64,8 +65,9 @@ def set_default_color_theme(color_string): CTkThemeManager.load_theme(color_string) -if not sys.platform == "darwin": +if sys.platform.startswith("win"): import warnings + warnings.simplefilter("ignore", category=UserWarning) import pyglet.font @@ -86,3 +88,27 @@ if not sys.platform == "darwin": "Preferred drawing method 'font_shapes' can not be used because the font file could not be loaded.\n" + "Using 'circle_shapes' instead. The rendering quality will be very bad!") CTkSettings.preferred_drawing_method = "circle_shapes" + +elif sys.platform == "linux": + try: + if not os.path.isdir(os.path.expanduser('~/.fonts/')): + os.mkdir(os.path.expanduser('~/.fonts/')) + + script_directory = os.path.dirname(os.path.abspath(__file__)) + + # copy fonts in user font folder + shutil.copy(os.path.join(script_directory, "assets", "fonts", "Roboto", "Roboto-Regular.ttf"), + os.path.expanduser("~/.fonts/")) + shutil.copy(os.path.join(script_directory, "assets", "fonts", "Roboto", "Roboto-Medium.ttf"), + os.path.expanduser("~/.fonts/")) + shutil.copy(os.path.join(script_directory, "assets", "fonts", "CustomTkinter_shapes_font-fine.otf"), + os.path.expanduser("~/.fonts/")) + + except Exception as err: + sys.stderr.write(str(err) + "\n") + sys.stderr.write("WARNING (customtkinter.CTkSettings): " + + "Preferred drawing method 'font_shapes' can not be used because the font file could not be copied to ~/.fonts/.\n" + + "Using 'circle_shapes' instead. The rendering quality will be very bad!\n") + CTkSettings.preferred_drawing_method = "circle_shapes" + +