Files
thechart/scripts/analyze_themes.py

96 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""Test script to analyze all theme header colors."""
import sys
import tkinter as tk
from pathlib import Path
from init import logger
from theme_manager import ThemeManager
# Add src directory to Python path
src_path = Path(__file__).parent / "src"
sys.path.insert(0, str(src_path))
def analyze_all_themes():
"""Analyze header colors for all available themes."""
print("Analyzing table header colors for all themes...")
root = tk.Tk()
root.withdraw() # Hide the window
theme_manager = ThemeManager(root, logger)
available_themes = theme_manager.get_available_themes()
print(f"Available themes: {available_themes}")
print("-" * 80)
for theme in available_themes:
print(f"\n=== {theme.upper()} THEME ===")
# Apply theme
success = theme_manager.apply_theme(theme)
if not success:
print(f"Failed to apply theme: {theme}")
continue
# Get theme colors
colors = theme_manager.get_theme_colors()
# Check base theme header colors
style = theme_manager.style
if style:
try:
base_header_bg = style.lookup("Treeview.Heading", "background")
base_header_fg = style.lookup("Treeview.Heading", "foreground")
custom_header_bg = style.lookup("Modern.Treeview.Heading", "background")
custom_header_fg = style.lookup("Modern.Treeview.Heading", "foreground")
print(f"Base theme BG: {colors['bg']}, FG: {colors['fg']}")
print(f"Base header BG: {base_header_bg}, FG: {base_header_fg}")
print(f"Custom header BG: {custom_header_bg}, FG: {custom_header_fg}")
print(
f"Select colors: BG: {colors['select_bg']}, "
f"FG: {colors['select_fg']}"
)
# Calculate contrast ratio (simplified)
def get_luminance(color):
"""Get relative luminance of a color."""
if not color or not color.startswith("#"):
return 0.5
try:
rgb = tuple(int(color[i : i + 2], 16) for i in (1, 3, 5))
# Simplified luminance calculation
return (0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]) / 255
except (ValueError, IndexError):
return 0.5
base_bg_lum = get_luminance(str(base_header_bg))
base_fg_lum = get_luminance(str(base_header_fg))
custom_bg_lum = get_luminance(str(custom_header_bg))
custom_fg_lum = get_luminance(str(custom_header_fg))
base_contrast = abs(base_bg_lum - base_fg_lum)
custom_contrast = abs(custom_bg_lum - custom_fg_lum)
print(f"Base contrast ratio: {base_contrast:.3f}")
print(f"Custom contrast ratio: {custom_contrast:.3f}")
# Check if problematic
if base_contrast < 0.3:
print("⚠️ BASE THEME HAS POOR CONTRAST!")
if custom_contrast < 0.3:
print("⚠️ CUSTOM STYLE HAS POOR CONTRAST!")
except Exception as e:
print(f"Error analyzing {theme}: {e}")
root.destroy()
if __name__ == "__main__":
analyze_all_themes()