renamed ThemeManage.single_color to _apply_appearance_mode and moved it to baseclass and windows

This commit is contained in:
Tom Schimansky
2022-10-29 01:20:32 +02:00
parent 08a0835fd0
commit e5484cb6cd
20 changed files with 315 additions and 330 deletions

View File

@ -5,7 +5,7 @@ import os
import platform
import ctypes
import re
from typing import Union, Tuple
from typing import Union, Tuple, List
from ..appearance_mode_tracker import AppearanceModeTracker
from ..theme_manager import ThemeManager
@ -57,7 +57,7 @@ class CTk(tkinter.Tk):
self._fg_color = ThemeManager.theme["color"]["window_bg_color"] if fg_color == "default_theme" else fg_color
super().configure(bg=ThemeManager.single_color(self._fg_color, self._appearance_mode))
super().configure(bg=self._apply_appearance_mode(self._fg_color))
super().title("CTk")
self.geometry(f"{self._current_width}x{self._current_height}")
@ -244,10 +244,20 @@ class CTk(tkinter.Tk):
else:
return value
def _apply_appearance_mode(self, color: Union[str, Tuple[str, str], List[str]]) -> str:
""" color can be either a single hex color string or a color name or it can be a
tuple color with (light_color, dark_color). The functions returns
always a single color string """
if type(color) == tuple or type(color) == list:
return color[self._appearance_mode]
else:
return color
def configure(self, **kwargs):
if "fg_color" in kwargs:
self._fg_color = kwargs.pop("fg_color")
super().configure(bg=ThemeManager.single_color(self._fg_color, self._appearance_mode))
super().configure(bg=self._apply_appearance_mode(self._fg_color))
for child in self.winfo_children():
try:
@ -354,4 +364,4 @@ class CTk(tkinter.Tk):
else:
self._windows_set_titlebar_color("light")
super().configure(bg=ThemeManager.single_color(self._fg_color, self._appearance_mode))
super().configure(bg=self._apply_appearance_mode(self._fg_color))

View File

@ -5,7 +5,7 @@ import os
import platform
import ctypes
import re
from typing import Union, Tuple
from typing import Union, Tuple, List
from ..appearance_mode_tracker import AppearanceModeTracker
from ..theme_manager import ThemeManager
@ -54,7 +54,7 @@ class CTkToplevel(tkinter.Toplevel):
self._fg_color = ThemeManager.theme["color"]["window_bg_color"] if fg_color == "default_theme" else fg_color
super().configure(bg=ThemeManager.single_color(self._fg_color, self._appearance_mode))
super().configure(bg=self._apply_appearance_mode(self._fg_color))
super().title("CTkToplevel")
self._state_before_windows_set_titlebar_color = None
@ -157,6 +157,16 @@ class CTkToplevel(tkinter.Toplevel):
else:
return value
def _apply_appearance_mode(self, color: Union[str, Tuple[str, str], List[str]]) -> str:
""" color can be either a single hex color string or a color name or it can be a
tuple color with (light_color, dark_color). The functions returns
always a single color string """
if type(color) == tuple or type(color) == list:
return color[self._appearance_mode]
else:
return color
def destroy(self):
AppearanceModeTracker.remove(self._set_appearance_mode)
ScalingTracker.remove_window(self._set_scaling, self)
@ -204,7 +214,7 @@ class CTkToplevel(tkinter.Toplevel):
def configure(self, **kwargs):
if "fg_color" in kwargs:
self._fg_color = kwargs.pop("fg_color")
super().configure(bg=ThemeManager.single_color(self._fg_color, self._appearance_mode))
super().configure(bg=self._apply_appearance_mode(self._fg_color))
for child in self.winfo_children():
try:
@ -314,4 +324,4 @@ class CTkToplevel(tkinter.Toplevel):
else:
self._windows_set_titlebar_color("light")
super().configure(bg=ThemeManager.single_color(self._fg_color, self._appearance_mode))
super().configure(bg=self._apply_appearance_mode(self._fg_color))