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.
107 lines
3.9 KiB
Python
107 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Single shared derivation of the XFrame widget count.
|
|
|
|
The canonical widget list is widgets/common/registry.h, GENERATED by
|
|
tools/gen_registry.py from the widgets/components/ directories. Every
|
|
driver, composite tool, palette/layout check and test in this tree must
|
|
derive the count from that registry -- never hard-code it. The Stock
|
|
Market section is adding hundreds of widgets; a baked-in number (the
|
|
old 194) breaks the composite grid, palette counts and PLACE_ALL the
|
|
moment the registry is regenerated.
|
|
|
|
Two views of the same truth:
|
|
- registry_names() / widget_count(): the integrated set -- what the
|
|
C++ palette/layout apps actually build from (kWidgetCount). This is
|
|
what drivers and tests must use.
|
|
- component_names() / component_count(): every component directory on
|
|
disk that holds a real widget (<name>/<name>.h). This is what
|
|
gen_registry.py feeds on, and the cross-check that the registry is
|
|
current. It deliberately excludes stray files in components/
|
|
(e.g. the shared StockData.h header, which is not a widget).
|
|
During a landing the component count runs ahead of the registry
|
|
count; that gap closes when the registry is regenerated.
|
|
|
|
Paths resolve relative to this file, so callers work from any cwd.
|
|
"""
|
|
import math
|
|
import os
|
|
import re
|
|
|
|
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
WIDGETS_DIR = os.path.dirname(TOOLS_DIR)
|
|
REPO_DIR = os.path.dirname(WIDGETS_DIR)
|
|
REGISTRY_H = os.path.join(WIDGETS_DIR, "common", "registry.h")
|
|
COMPONENTS_DIR = os.path.join(WIDGETS_DIR, "components")
|
|
|
|
|
|
def registry_names(registry_h=REGISTRY_H):
|
|
"""Widget names in registry order, parsed from registry.h."""
|
|
with open(registry_h) as f:
|
|
text = f.read()
|
|
m = re.search(r"kWidgetNames\[kWidgetCount\] = \{(.*?)\};", text, re.S)
|
|
if m:
|
|
names = re.findall(r'"([^"]+)"', m.group(1))
|
|
if names:
|
|
return names
|
|
# Fallback: the #include lines list the same widgets in the same order.
|
|
names = re.findall(r'#include "components/([^/"]+)/[^"]+\.h"', text)
|
|
if names:
|
|
return names
|
|
m = re.search(r"kWidgetCount\s*=\s*(\d+)", text)
|
|
raise ValueError("cannot derive widget names from %s%s"
|
|
% (registry_h,
|
|
(" (kWidgetCount=%s)" % m.group(1)) if m else ""))
|
|
|
|
|
|
def widget_count(registry_h=REGISTRY_H):
|
|
"""Number of widgets in the registry -- the derived count."""
|
|
return len(registry_names(registry_h))
|
|
|
|
|
|
def is_widget_dir(name, components_dir=COMPONENTS_DIR):
|
|
"""True if components/<name>/ holds a real widget (<name>/<name>.h)."""
|
|
return (os.path.isdir(os.path.join(components_dir, name))
|
|
and os.path.isfile(os.path.join(components_dir, name,
|
|
name + ".h")))
|
|
|
|
|
|
def component_names(components_dir=COMPONENTS_DIR):
|
|
"""Every real widget directory on disk, sorted (gen_registry order)."""
|
|
if not os.path.isdir(components_dir):
|
|
return []
|
|
return sorted(n for n in os.listdir(components_dir)
|
|
if is_widget_dir(n, components_dir))
|
|
|
|
|
|
def component_count(components_dir=COMPONENTS_DIR):
|
|
return len(component_names(components_dir))
|
|
|
|
|
|
def composite_cols(n):
|
|
"""Grid columns for n tiles: near-square, so the sheet grows evenly."""
|
|
if n <= 0:
|
|
return 0
|
|
return int(math.ceil(math.sqrt(n)))
|
|
|
|
|
|
def composite_rows(n, cols=None):
|
|
if n <= 0:
|
|
return 0
|
|
if cols is None:
|
|
cols = composite_cols(n)
|
|
return (n + cols - 1) // cols
|
|
|
|
|
|
def composite_tiles(shot_dir):
|
|
"""Screenshot tiles: PNGs whose stem is a real widget directory.
|
|
|
|
Excludes the composite sheet itself and the palette/layout
|
|
screenshots (all_widgets/palette/layout*.png), which are not tiles.
|
|
"""
|
|
widgets = set(component_names())
|
|
out = []
|
|
for fn in sorted(os.listdir(shot_dir)):
|
|
if fn.endswith(".png") and fn[:-4] in widgets:
|
|
out.append(os.path.join(shot_dir, fn))
|
|
return out
|