From 50a8bb140e8234b9832562745bedba2f9d60a723 Mon Sep 17 00:00:00 2001 From: TomSchimansky Date: Wed, 30 Nov 2022 21:51:36 +0100 Subject: [PATCH] fixed assets font path --- customtkinter/windows/widgets/__init__.py | 4 ---- .../windows/widgets/core_rendering/__init__.py | 2 ++ customtkinter/windows/widgets/font/__init__.py | 10 +++++----- examples/image_example.py | 12 ++++++------ 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/customtkinter/windows/widgets/__init__.py b/customtkinter/windows/widgets/__init__.py index 6da9aec..2e21484 100644 --- a/customtkinter/windows/widgets/__init__.py +++ b/customtkinter/windows/widgets/__init__.py @@ -13,7 +13,3 @@ from .ctk_slider import CTkSlider from .ctk_switch import CTkSwitch from .ctk_tabview import CTkTabview from .ctk_textbox import CTkTextbox - -# init canvas font character map for current platform -from .core_rendering import CTkCanvas -CTkCanvas.init_font_character_mapping() diff --git a/customtkinter/windows/widgets/core_rendering/__init__.py b/customtkinter/windows/widgets/core_rendering/__init__.py index 571adc7..ccadbc7 100644 --- a/customtkinter/windows/widgets/core_rendering/__init__.py +++ b/customtkinter/windows/widgets/core_rendering/__init__.py @@ -3,6 +3,8 @@ import sys from .ctk_canvas import CTkCanvas from .draw_engine import DrawEngine +CTkCanvas.init_font_character_mapping() + # determine draw method based on current platform if sys.platform == "darwin": DrawEngine.preferred_drawing_method = "polygon_shapes" diff --git a/customtkinter/windows/widgets/font/__init__.py b/customtkinter/windows/widgets/font/__init__.py index 9c3d6ff..64a49f1 100644 --- a/customtkinter/windows/widgets/font/__init__.py +++ b/customtkinter/windows/widgets/font/__init__.py @@ -10,15 +10,15 @@ from ..core_rendering import DrawEngine FontManager.init_font_manager() # load Roboto fonts (used on Windows/Linux) -script_directory = os.path.dirname(os.path.abspath(__file__)) -FontManager.load_font(os.path.join(script_directory, "assets", "fonts", "Roboto", "Roboto-Regular.ttf")) -FontManager.load_font(os.path.join(script_directory, "assets", "fonts", "Roboto", "Roboto-Medium.ttf")) +customtkinter_directory = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +FontManager.load_font(os.path.join(customtkinter_directory, "assets", "fonts", "Roboto", "Roboto-Regular.ttf")) +FontManager.load_font(os.path.join(customtkinter_directory, "assets", "fonts", "Roboto", "Roboto-Medium.ttf")) # load font necessary for rendering the widgets (used on Windows/Linux) -if FontManager.load_font(os.path.join(script_directory, "assets", "fonts", "CustomTkinter_shapes_font.otf")) is False: +if FontManager.load_font(os.path.join(customtkinter_directory, "assets", "fonts", "CustomTkinter_shapes_font.otf")) is False: # change draw method if font loading failed if DrawEngine.preferred_drawing_method == "font_shapes": - sys.stderr.write("customtkinter.__init__ warning: " + + sys.stderr.write("customtkinter.windows.widgets.font warning: " + "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 bad!\n") DrawEngine.preferred_drawing_method = "circle_shapes" diff --git a/examples/image_example.py b/examples/image_example.py index 42c5340..f2e3b60 100644 --- a/examples/image_example.py +++ b/examples/image_example.py @@ -16,12 +16,12 @@ class App(customtkinter.CTk): # load images with light and dark mode image current_path = os.path.dirname(os.path.realpath(__file__)) - self.home_image = customtkinter.CTkImage(light_image=Image.open(current_path + "/test_images/home_dark.png"), - dark_image=Image.open(current_path + "/test_images/home_light.png"), size=(20, 20)) - self.chat_image = customtkinter.CTkImage(light_image=Image.open(current_path + "/test_images/chat_dark.png"), - dark_image=Image.open(current_path + "/test_images/chat_light.png"), size=(20, 20)) - self.add_user_image = customtkinter.CTkImage(light_image=Image.open(current_path + "/test_images/add_user_dark.png"), - dark_image=Image.open(current_path + "/test_images/add_user_light.png"), size=(20, 20)) + self.home_image = customtkinter.CTkImage(light_image=Image.open(os.path.join(current_path, "test_images", "home_dark.png")), + dark_image=Image.open(os.path.join(current_path, "test_images", "home_light.png")), size=(20, 20)) + self.chat_image = customtkinter.CTkImage(light_image=Image.open(os.path.join(current_path, "test_images", "chat_dark.png")), + dark_image=Image.open(os.path.join(current_path, "test_images", "chat_light.png")), size=(20, 20)) + self.add_user_image = customtkinter.CTkImage(light_image=Image.open(os.path.join(current_path, "test_images", "add_user_dark.png")), + dark_image=Image.open(os.path.join(current_path, "test_images", "add_user_light.png")), size=(20, 20)) # create navigation frame self.navigation_frame = customtkinter.CTkFrame(self, corner_radius=0)