@dataclass(frozen=True)
class ViewerColors:
"""Cohesive color tokens derived from a QPalette (works in light & dark themes)."""
base: gui.QColor
alt_row: gui.QColor
text: gui.QColor
muted_text: gui.QColor
header_bg: gui.QColor
header_outer_bg: gui.QColor
header_fg: gui.QColor
header_selected_bg: gui.QColor
selection_bg: gui.QColor
selection_fg: gui.QColor
grid: gui.QColor
divider: gui.QColor
accent: gui.QColor
@classmethod
def from_palette(cls, palette: gui.QPalette) -> ViewerColors:
role = gui.Palette.ColorRole
base = gui.QColor(palette.color(role.Base))
text = gui.QColor(palette.color(role.Text))
window_text = gui.QColor(palette.color(role.WindowText))
highlight = gui.QColor(palette.color(role.Highlight))
header_bg = blend(window_text, base, 0.055)
return cls(
base=base,
alt_row=blend(window_text, base, 0.03),
text=text,
muted_text=blend(text, base, 0.42),
header_bg=header_bg,
header_outer_bg=blend(window_text, base, 0.09),
header_fg=window_text,
header_selected_bg=blend(highlight, header_bg, 0.18),
selection_bg=blend(highlight, base, 0.20),
selection_fg=text,
grid=blend(window_text, base, 0.13),
divider=blend(window_text, base, 0.28),
accent=highlight,
)