New shared helper widgets/tools/widget_count.py parses the canonical widget list from widgets/common/registry.h (kWidgetNames, with the \#include lines as fallback); every driver, composite tool, palette / layout check and test now derives the count from it, so the tooling keeps working as the Stock Market section lands instead of breaking the composite grid, palette counts and PLACE_ALL. - sections.py: new 10th section Stock Market (teal), assigned by Stock*/Ind* prefix rule derived from the component dirs, so it grows as widgets land with no hand-maintained list. - build/verify_composite.py: tiles are the widget screenshots on disk; grid is ceil(sqrt(n)) columns, spare slots allowed; fails only if tiles are fewer than registry widgets. - gen_registry.py / gen_xframe_palette_data.py / verify_icons.py / gen_icons.py: counts derived; registry generator filters to real widget dirs (excludes the shared StockData.h header, which is not a widget); palette-data generator keeps sections.py order and skips widgets not yet in the registry. - palette/main_palette.cpp: window title from kWidgetCount; section accent table unsized with a fallback instead of a hard-coded [9]. - designer/src/main.cpp: self-test counts use kXFramePaletteCount. - tests + run_tests.py: all expectations derived (palette 194/194, PLACE_ALL 194/194, combined 36+194=230 today, seam 136/58). - all_widgets.png re-rendered: 223 tiles (194 registry + 29 Stock screenshots ahead of the registry) on a 15x15 grid. - verify_composite: label-bar check is majority-dark (white label text occupies the rest); GtkInvisible is blank by design. Registry itself is intentionally NOT regenerated here: it stays at 194 until phase-2 integration lands icons/screenshots for all new widgets, at which point every derived check follows automatically.
74 lines
3.2 KiB
Python
74 lines
3.2 KiB
Python
import os, sys
|
|
from PIL import Image
|
|
from collections import Counter
|
|
|
|
_HERE = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.insert(0, os.path.join(_HERE, "tools"))
|
|
from widget_count import (composite_cols, composite_rows, composite_tiles,
|
|
widget_count)
|
|
|
|
SHOT_DIR = os.path.join(_HERE, "screenshots")
|
|
SHEET = os.path.join(SHOT_DIR, "all_widgets.png")
|
|
TILE_W, TILE_H, LABEL_H, COLS_UNUSED, GAP, MARGIN = 240, 180, 26, 14, 4, 8
|
|
CELL_W, CELL_H = TILE_W, TILE_H + LABEL_H
|
|
|
|
# Same tile set and grid derivation as build_composite.py (never
|
|
# hard-coded): cols = ceil(sqrt(n)) over the widget screenshots on disk.
|
|
files = composite_tiles(SHOT_DIR)
|
|
n = len(files)
|
|
COLS = composite_cols(n)
|
|
ROWS = composite_rows(n, COLS)
|
|
reg_n = widget_count()
|
|
sheet = Image.open(SHEET).convert("RGB")
|
|
print("sheet size:", sheet.size, "tiles:", n, "registry:", reg_n)
|
|
exp_w = MARGIN*2 + COLS*CELL_W + (COLS-1)*GAP
|
|
exp_h = MARGIN*2 + ROWS*CELL_H + (ROWS-1)*GAP
|
|
if sheet.size != (exp_w, exp_h):
|
|
raise SystemExit(
|
|
f"FAIL: sheet size {sheet.size}, expected {(exp_w, exp_h)} "
|
|
f"for a {COLS}x{ROWS} grid over {n} tiles")
|
|
if n < reg_n:
|
|
raise SystemExit(
|
|
f"FAIL: only {n} tiles, registry has {reg_n} widgets — "
|
|
"render the missing screenshots first")
|
|
if n > reg_n:
|
|
print(f"note: {n} tiles but registry has {reg_n} widgets — "
|
|
"screenshots are ahead of the registry (mid-landing)")
|
|
|
|
blank, mismatched, bad_label = [], [], []
|
|
for i, path in enumerate(files):
|
|
name = os.path.splitext(os.path.basename(path))[0]
|
|
r, c = divmod(i, COLS)
|
|
x = MARGIN + c*(CELL_W+GAP); y = MARGIN + r*(CELL_H+GAP)
|
|
tile = sheet.crop((x, y, x+TILE_W, y+TILE_H))
|
|
# fidelity: tile must equal downscaled source
|
|
src = Image.open(path).convert("RGB").resize((TILE_W, TILE_H), Image.LANCZOS)
|
|
diff = sum(1 for a, b in zip(tile.getdata(), src.getdata()) if a != b)
|
|
if diff > 0:
|
|
mismatched.append((name, diff))
|
|
# blank check: pixels differing from tile's dominant color
|
|
counts = Counter(tile.getdata())
|
|
dom, dom_n = counts.most_common(1)[0]
|
|
differing = TILE_W*TILE_H - dom_n
|
|
if differing <= 20:
|
|
blank.append((name, differing, dom))
|
|
# label bar: strip below tile must be dark fill (30,30,30). The
|
|
# white label text sits on the bar, so it is only ~75-90% dark, not
|
|
# 100%: majority-dark is the correct bar-present signal.
|
|
bar = sheet.crop((x, y+TILE_H, x+TILE_W, y+TILE_H+LABEL_H))
|
|
bar_counts = Counter(bar.getdata())
|
|
bar_dom, bar_n = bar_counts.most_common(1)[0]
|
|
if bar_dom != (30, 30, 30) or bar_n < TILE_W*LABEL_H*0.7:
|
|
bad_label.append((name, bar_dom, bar_n))
|
|
|
|
print("blank tiles (<=20 differing px):", blank)
|
|
print("fidelity mismatches:", mismatched[:10], "count:", len(mismatched))
|
|
print("bad label bars:", bad_label)
|
|
# GtkInvisible draws nothing by design, so its tile is blank on
|
|
# purpose; any other blank tile is a real failure.
|
|
BLANK_OK = {"GtkInvisible"}
|
|
real_blank = [b for b in blank if b[0] not in BLANK_OK]
|
|
print(f"RESULT: {n-len(blank)} non-blank, {len(blank)} blank, {len(bad_label)} bad labels, {len(mismatched)} mismatched")
|
|
if real_blank or mismatched or bad_label:
|
|
raise SystemExit(1)
|