2021-03-05 02:32:17 +03:00
|
|
|
import sys
|
2021-03-04 20:27:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
class CTkColorManager:
|
2021-09-13 15:27:29 +03:00
|
|
|
|
2022-01-08 02:29:53 +03:00
|
|
|
WINDOW_BG = None
|
|
|
|
MAIN = None
|
|
|
|
MAIN_HOVER = None
|
|
|
|
ENTRY = None
|
|
|
|
TEXT = None
|
|
|
|
LABEL_BG = None
|
|
|
|
SLIDER_BG = None
|
|
|
|
SLIDER_PROGRESS = None
|
|
|
|
PROGRESS_BG = None
|
|
|
|
FRAME = None
|
|
|
|
FRAME_2 = None
|
|
|
|
CHECKBOX_LINES = None
|
|
|
|
DARKEN_COLOR_FACTOR = None
|
2021-03-04 20:27:46 +03:00
|
|
|
|
2022-01-08 02:29:53 +03:00
|
|
|
@classmethod
|
|
|
|
def initialize_color_theme(cls, theme_name):
|
|
|
|
print("set theme", theme_name)
|
|
|
|
|
|
|
|
if theme_name.lower() == "blue":
|
|
|
|
cls.WINDOW_BG = ("#ECECEC", "#323232") # macOS standard light and dark window bg colors
|
|
|
|
cls.MAIN = ("#1C94CF", "#1C94CF")
|
|
|
|
cls.MAIN_HOVER = ("#5FB4DD", "#5FB4DD")
|
|
|
|
cls.ENTRY = ("white", "#222222")
|
|
|
|
cls.TEXT = ("black", "white")
|
|
|
|
cls.LABEL_BG = ("white", "#626061")
|
|
|
|
cls.SLIDER_BG = ("#6B6B6B", "#222222")
|
|
|
|
cls.SLIDER_PROGRESS = ("#A5A6A5", "#555555")
|
|
|
|
cls.PROGRESS_BG = ("#6B6B6B", "#222222")
|
|
|
|
cls.FRAME = ("#D4D5D6", "#3F3F3F")
|
|
|
|
cls.FRAME_2 = ("#BFBEC1", "#505050")
|
|
|
|
cls.CHECKBOX_LINES = ("black", "#ededed")
|
|
|
|
cls.DARKEN_COLOR_FACTOR = 0.8 # used to generate color for disabled button
|
|
|
|
|
|
|
|
elif theme_name.lower() == "green":
|
|
|
|
cls.WINDOW_BG = ("#ECECEC", "#323232") # macOS standard light and dark window bg colors
|
|
|
|
cls.MAIN = ("#29B57E", "#29B57E")
|
|
|
|
cls.MAIN_HOVER = ("#6ACBA5", "#6ACBA5")
|
|
|
|
cls.ENTRY = ("#656565", "#222223")
|
|
|
|
cls.TEXT = ("black", "white")
|
|
|
|
cls.LABEL_BG = ("white", "#626061")
|
|
|
|
cls.SLIDER_BG = ("#636363", "#0D1321")
|
|
|
|
cls.SLIDER_PROGRESS = ("white", "#727578")
|
|
|
|
cls.PROGRESS_BG = ("#636363", "#0D1321")
|
|
|
|
cls.FRAME = ("#D4D5D6", "#3F3F3F")
|
|
|
|
cls.FRAME_2 = ("#BFBEC1", "#505050")
|
|
|
|
cls.CHECKBOX_LINES = ("#414141", "#EDEDED")
|
|
|
|
cls.DARKEN_COLOR_FACTOR = 0.8 # used to generate color for disabled button
|
|
|
|
|
|
|
|
elif theme_name.lower() == "dark-blue":
|
|
|
|
cls.WINDOW_BG = ("#F1F1F1", "#192026") # macOS standard light and dark window bg colors
|
|
|
|
cls.MAIN = ("#608BD5", "#395E9C")
|
|
|
|
cls.MAIN_HOVER = ("#A4BDE6", "#748BB3")
|
|
|
|
cls.ENTRY = ("#FCFCFC", "#111116")
|
|
|
|
cls.TEXT = ("black", "white")
|
|
|
|
cls.LABEL_BG = ("white", "#444444")
|
|
|
|
cls.SLIDER_BG = ("#444444", "#444444")
|
|
|
|
cls.SLIDER_PROGRESS = ("white", "#AAAAAA")
|
|
|
|
cls.PROGRESS_BG = ("#636363", "#0D1321")
|
|
|
|
cls.FRAME = ("#DADADA", "#2B2C2E")
|
|
|
|
cls.FRAME_2 = ("#C4C4C4", "#383838")
|
|
|
|
cls.CHECKBOX_LINES = ("#313131", "white")
|
|
|
|
cls.DARKEN_COLOR_FACTOR = 0.8 # used to generate color for disabled button
|
2021-07-23 01:44:13 +03:00
|
|
|
|
|
|
|
@staticmethod
|
2021-09-13 15:27:29 +03:00
|
|
|
def single_color(color, appearance_mode: int) -> 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 then returns
|
|
|
|
always a single color string """
|
|
|
|
|
|
|
|
if type(color) == tuple:
|
|
|
|
return color[appearance_mode]
|
|
|
|
else:
|
|
|
|
return color
|
|
|
|
|
|
|
|
@staticmethod
|
2021-11-06 02:35:07 +03:00
|
|
|
def rgb2hex(rgb_color: tuple) -> str:
|
2021-07-23 01:44:13 +03:00
|
|
|
return "#{:02x}{:02x}{:02x}".format(round(rgb_color[0]), round(rgb_color[1]), round(rgb_color[2]))
|
|
|
|
|
|
|
|
@staticmethod
|
2021-11-06 02:35:07 +03:00
|
|
|
def hex2rgb(hex_color: str) -> tuple:
|
2021-07-23 01:44:13 +03:00
|
|
|
return tuple(int(hex_color.strip("#")[i:i+2], 16) for i in (0, 2, 4))
|
|
|
|
|
|
|
|
@staticmethod
|
2021-09-13 15:27:29 +03:00
|
|
|
def darken_hex_color(hex_color: str) -> str:
|
2021-07-23 01:44:13 +03:00
|
|
|
try:
|
|
|
|
rgb_color = CTkColorManager.hex2rgb(hex_color)
|
|
|
|
dark_rgb_color = (rgb_color[0] * CTkColorManager.DARKEN_COLOR_FACTOR,
|
|
|
|
rgb_color[1] * CTkColorManager.DARKEN_COLOR_FACTOR,
|
|
|
|
rgb_color[2] * CTkColorManager.DARKEN_COLOR_FACTOR)
|
|
|
|
return CTkColorManager.rgb2hex(dark_rgb_color)
|
|
|
|
except Exception as err:
|
2021-09-13 15:27:29 +03:00
|
|
|
sys.stderr.write("ERROR (CTkColorManager): failed to darken the following color: " + str(hex_color) + " " + str(err))
|
2021-07-23 01:44:13 +03:00
|
|
|
return hex_color
|
|
|
|
|
2021-03-04 20:27:46 +03:00
|
|
|
@classmethod
|
2022-01-08 02:29:53 +03:00
|
|
|
def set_main_color(cls, main_color, main_color_hover):
|
|
|
|
cls.MAIN = main_color
|
|
|
|
cls.MAIN_HOVER = main_color_hover
|
2021-03-04 20:27:46 +03:00
|
|
|
|
|
|
|
|
2022-01-08 02:29:53 +03:00
|
|
|
CTkColorManager.initialize_color_theme("blue")
|