feat: consolidate test structure and enhance header visibility across themes

This commit is contained in:
William Valentin
2025-08-05 15:48:15 -07:00
parent a521ed6e9a
commit 5a375e0d21
10 changed files with 734 additions and 2 deletions
+70 -2
View File
@@ -77,6 +77,56 @@ class ThemeManager:
"""Get the currently active theme."""
return self.current_theme
def _get_contrasting_colors(self, colors: dict[str, str]) -> dict[str, str]:
"""Get contrasting colors for headers with improved visibility."""
def get_luminance(color_str: str) -> float:
"""Calculate relative luminance of a color."""
if not color_str or not color_str.startswith("#"):
return 0.5
try:
rgb = tuple(int(color_str[i : i + 2], 16) for i in (1, 3, 5))
# Calculate relative luminance
return (0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]) / 255
except (ValueError, IndexError):
return 0.5
def get_contrast_ratio(bg: str, fg: str) -> float:
"""Calculate contrast ratio between two colors."""
bg_lum = get_luminance(bg)
fg_lum = get_luminance(fg)
lighter = max(bg_lum, fg_lum)
darker = min(bg_lum, fg_lum)
return (lighter + 0.05) / (darker + 0.05)
# Start with the provided select colors
header_bg = colors["select_bg"]
header_fg = colors["select_fg"]
# Calculate contrast ratio
contrast = get_contrast_ratio(header_bg, header_fg)
# If contrast is poor (less than 3:1), use high-contrast alternatives
if contrast < 3.0:
bg_luminance = get_luminance(colors["bg"])
if bg_luminance > 0.5: # Light theme
header_bg = "#1e1e1e" # Very dark gray background for maximum contrast
header_fg = "#ffffff" # Pure white for maximum contrast
else: # Dark theme - use dark background with light text
header_bg = "#1e1e1e" # Very dark gray for consistency
header_fg = "#ffffff" # Pure white for maximum contrast
self.logger.debug(
f"Poor header contrast ({contrast:.2f}), using fallback colors: "
f"bg={header_bg}, fg={header_fg}"
)
return {
"header_bg": header_bg,
"header_fg": header_fg,
}
def _configure_custom_styles(self) -> None:
"""Configure custom styles for better appearance."""
if not self.style:
@@ -86,6 +136,9 @@ class ThemeManager:
# Get current theme colors for consistent styling
colors = self.get_theme_colors()
# Get improved header colors with better contrast
header_colors = self._get_contrasting_colors(colors)
# Configure frame styles with better padding and borders
self.style.configure(
"Card.TFrame",
@@ -155,11 +208,26 @@ class ThemeManager:
padding=(8, 6),
relief="flat",
borderwidth=1,
background=colors["select_bg"],
foreground=colors["select_fg"],
background=header_colors["header_bg"],
foreground=header_colors["header_fg"],
font=("TkDefaultFont", 9, "bold"),
)
# Ensure header style mapping to override theme defaults
self.style.map(
"Modern.Treeview.Heading",
background=[
("active", header_colors["header_bg"]),
("pressed", header_colors["header_bg"]),
("", header_colors["header_bg"]),
],
foreground=[
("active", header_colors["header_fg"]),
("pressed", header_colors["header_fg"]),
("", header_colors["header_fg"]),
],
)
# Configure comprehensive row selection colors for better visibility
self.style.map(
"Modern.Treeview",