From 37b375d58b35d53f254d73605d5c68d38f8a5b75 Mon Sep 17 00:00:00 2001 From: Tom Schimansky Date: Sat, 27 May 2023 13:25:30 +0200 Subject: [PATCH] fixed wrong json class names and added fix for backwards compatibility in ThemeManager #1538 --- customtkinter/assets/themes/blue.json | 4 ++-- customtkinter/assets/themes/dark-blue.json | 4 ++-- customtkinter/assets/themes/green.json | 4 ++-- customtkinter/windows/widgets/ctk_checkbox.py | 16 ++++++++-------- customtkinter/windows/widgets/ctk_radiobutton.py | 16 ++++++++-------- .../windows/widgets/theme/theme_manager.py | 6 ++++++ 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/customtkinter/assets/themes/blue.json b/customtkinter/assets/themes/blue.json index db3b1d2..192c136 100644 --- a/customtkinter/assets/themes/blue.json +++ b/customtkinter/assets/themes/blue.json @@ -34,7 +34,7 @@ "text_color":["gray10", "#DCE4EE"], "placeholder_text_color": ["gray52", "gray62"] }, - "CTkCheckbox": { + "CTkCheckBox": { "corner_radius": 6, "border_width": 3, "fg_color": ["#3B8ED0", "#1F6AA5"], @@ -55,7 +55,7 @@ "text_color": ["gray10", "#DCE4EE"], "text_color_disabled": ["gray60", "gray45"] }, - "CTkRadiobutton": { + "CTkRadioButton": { "corner_radius": 1000, "border_width_checked": 6, "border_width_unchecked": 3, diff --git a/customtkinter/assets/themes/dark-blue.json b/customtkinter/assets/themes/dark-blue.json index f78766c..54ff211 100644 --- a/customtkinter/assets/themes/dark-blue.json +++ b/customtkinter/assets/themes/dark-blue.json @@ -34,7 +34,7 @@ "text_color": ["gray14", "gray84"], "placeholder_text_color": ["gray52", "gray62"] }, - "CTkCheckbox": { + "CTkCheckBox": { "corner_radius": 6, "border_width": 3, "fg_color": ["#3a7ebf", "#1f538d"], @@ -55,7 +55,7 @@ "text_color": ["gray14", "gray84"], "text_color_disabled": ["gray60", "gray45"] }, - "CTkRadiobutton": { + "CTkRadioButton": { "corner_radius": 1000, "border_width_checked": 6, "border_width_unchecked": 3, diff --git a/customtkinter/assets/themes/green.json b/customtkinter/assets/themes/green.json index a10ada4..200012f 100644 --- a/customtkinter/assets/themes/green.json +++ b/customtkinter/assets/themes/green.json @@ -34,7 +34,7 @@ "text_color":["gray10", "#DCE4EE"], "placeholder_text_color": ["gray52", "gray62"] }, - "CTkCheckbox": { + "CTkCheckBox": { "corner_radius": 6, "border_width": 3, "fg_color": ["#2CC985", "#2FA572"], @@ -55,7 +55,7 @@ "text_color": ["gray10", "#DCE4EE"], "text_color_disabled": ["gray60", "gray45"] }, - "CTkRadiobutton": { + "CTkRadioButton": { "corner_radius": 1000, "border_width_checked": 6, "border_width_unchecked": 3, diff --git a/customtkinter/windows/widgets/ctk_checkbox.py b/customtkinter/windows/widgets/ctk_checkbox.py index aedd005..57723ac 100644 --- a/customtkinter/windows/widgets/ctk_checkbox.py +++ b/customtkinter/windows/widgets/ctk_checkbox.py @@ -51,20 +51,20 @@ class CTkCheckBox(CTkBaseClass): self._checkbox_height = checkbox_height # color - self._fg_color = ThemeManager.theme["CTkCheckbox"]["fg_color"] if fg_color is None else self._check_color_type(fg_color) - self._hover_color = ThemeManager.theme["CTkCheckbox"]["hover_color"] if hover_color is None else self._check_color_type(hover_color) - self._border_color = ThemeManager.theme["CTkCheckbox"]["border_color"] if border_color is None else self._check_color_type(border_color) - self._checkmark_color = ThemeManager.theme["CTkCheckbox"]["checkmark_color"] if checkmark_color is None else self._check_color_type(checkmark_color) + self._fg_color = ThemeManager.theme["CTkCheckBox"]["fg_color"] if fg_color is None else self._check_color_type(fg_color) + self._hover_color = ThemeManager.theme["CTkCheckBox"]["hover_color"] if hover_color is None else self._check_color_type(hover_color) + self._border_color = ThemeManager.theme["CTkCheckBox"]["border_color"] if border_color is None else self._check_color_type(border_color) + self._checkmark_color = ThemeManager.theme["CTkCheckBox"]["checkmark_color"] if checkmark_color is None else self._check_color_type(checkmark_color) # shape - self._corner_radius = ThemeManager.theme["CTkCheckbox"]["corner_radius"] if corner_radius is None else corner_radius - self._border_width = ThemeManager.theme["CTkCheckbox"]["border_width"] if border_width is None else border_width + self._corner_radius = ThemeManager.theme["CTkCheckBox"]["corner_radius"] if corner_radius is None else corner_radius + self._border_width = ThemeManager.theme["CTkCheckBox"]["border_width"] if border_width is None else border_width # text self._text = text self._text_label: Union[tkinter.Label, None] = None - self._text_color = ThemeManager.theme["CTkCheckbox"]["text_color"] if text_color is None else self._check_color_type(text_color) - self._text_color_disabled = ThemeManager.theme["CTkCheckbox"]["text_color_disabled"] if text_color_disabled is None else self._check_color_type(text_color_disabled) + self._text_color = ThemeManager.theme["CTkCheckBox"]["text_color"] if text_color is None else self._check_color_type(text_color) + self._text_color_disabled = ThemeManager.theme["CTkCheckBox"]["text_color_disabled"] if text_color_disabled is None else self._check_color_type(text_color_disabled) # font self._font = CTkFont() if font is None else self._check_font_type(font) diff --git a/customtkinter/windows/widgets/ctk_radiobutton.py b/customtkinter/windows/widgets/ctk_radiobutton.py index d797be9..63e1e03 100644 --- a/customtkinter/windows/widgets/ctk_radiobutton.py +++ b/customtkinter/windows/widgets/ctk_radiobutton.py @@ -50,20 +50,20 @@ class CTkRadioButton(CTkBaseClass): self._radiobutton_height = radiobutton_height # color - self._fg_color = ThemeManager.theme["CTkRadiobutton"]["fg_color"] if fg_color is None else self._check_color_type(fg_color) - self._hover_color = ThemeManager.theme["CTkRadiobutton"]["hover_color"] if hover_color is None else self._check_color_type(hover_color) - self._border_color = ThemeManager.theme["CTkRadiobutton"]["border_color"] if border_color is None else self._check_color_type(border_color) + self._fg_color = ThemeManager.theme["CTkRadioButton"]["fg_color"] if fg_color is None else self._check_color_type(fg_color) + self._hover_color = ThemeManager.theme["CTkRadioButton"]["hover_color"] if hover_color is None else self._check_color_type(hover_color) + self._border_color = ThemeManager.theme["CTkRadioButton"]["border_color"] if border_color is None else self._check_color_type(border_color) # shape - self._corner_radius = ThemeManager.theme["CTkRadiobutton"]["corner_radius"] if corner_radius is None else corner_radius - self._border_width_unchecked = ThemeManager.theme["CTkRadiobutton"]["border_width_unchecked"] if border_width_unchecked is None else border_width_unchecked - self._border_width_checked = ThemeManager.theme["CTkRadiobutton"]["border_width_checked"] if border_width_checked is None else border_width_checked + self._corner_radius = ThemeManager.theme["CTkRadioButton"]["corner_radius"] if corner_radius is None else corner_radius + self._border_width_unchecked = ThemeManager.theme["CTkRadioButton"]["border_width_unchecked"] if border_width_unchecked is None else border_width_unchecked + self._border_width_checked = ThemeManager.theme["CTkRadioButton"]["border_width_checked"] if border_width_checked is None else border_width_checked # text self._text = text self._text_label: Union[tkinter.Label, None] = None - self._text_color = ThemeManager.theme["CTkRadiobutton"]["text_color"] if text_color is None else self._check_color_type(text_color) - self._text_color_disabled = ThemeManager.theme["CTkRadiobutton"]["text_color_disabled"] if text_color_disabled is None else self._check_color_type(text_color_disabled) + self._text_color = ThemeManager.theme["CTkRadioButton"]["text_color"] if text_color is None else self._check_color_type(text_color) + self._text_color_disabled = ThemeManager.theme["CTkRadioButton"]["text_color_disabled"] if text_color_disabled is None else self._check_color_type(text_color_disabled) # font self._font = CTkFont() if font is None else self._check_font_type(font) diff --git a/customtkinter/windows/widgets/theme/theme_manager.py b/customtkinter/windows/widgets/theme/theme_manager.py index f871d49..cf22858 100644 --- a/customtkinter/windows/widgets/theme/theme_manager.py +++ b/customtkinter/windows/widgets/theme/theme_manager.py @@ -37,6 +37,12 @@ class ThemeManager: else: cls.theme[key] = cls.theme[key]["Linux"] + # fix name inconsistencies + if "CTkCheckbox" in cls.theme.keys(): + cls.theme["CTkCheckBox"] = cls.theme.pop("CTkCheckbox") + if "CTkRadiobutton" in cls.theme.keys(): + cls.theme["CTkRadioButton"] = cls.theme.pop("CTkRadiobutton") + @classmethod def save_theme(cls): if cls._currently_loaded_theme is not None: