- tools/extract_palette.py: kTypes expectation 36->38 (ToggleButton and CheckListBox added in C); palette total 598->600 - tools/extract_events.py: parse 6th EventDef field `lazarus` (Flag 10 Lazarus Object Inspector name); scope table/dispatch parsing to events_for() (raw_events_for() has its own `raw` table, deliberately excluded); dispatch now tests the normalised key `t`, not `type` - data/*.json regenerated via `make regen`: registry default sizes per the C rule (incl. the 15 monitor widgets' hand-written sizes), palette Misc/X order per C xframe_palette.h, props 37 types / 270 props / 25 enum tables / 35 common props, events 29 types with lazarus names; indicators provenance head only - crates/xframe-common: palette asserts 598->600, LightGUI 36->38 - crates/xframe-widgets: *_gen.rs regenerated; gen_data.py opt_f now emits float literals for Option<f64> lo/hi (pre-existing latent bug: running it on the old data also emitted Some(0)); stale eb0b5fc / 547 / 9 / 35 / 27 counts updated to e474894 / 562 / 25 / 37 / 29 make check: all 5 tables OK. cargo build warning-free. cargo test --workspace --no-fail-fast: all suites green except 5 pre-existing environmental failures, verified identical on HEAD: lightgui-debug console (37) + gtk (7) need /usr/bin/gdb (not installed on dallas), lightgui-support font/theme need a display (gtk::init fails), and lightgui-gen fixtures is stale vs the Task 4 event routing in gen.rs.
112 lines
4.1 KiB
Python
112 lines
4.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Extract the combined 600-entry palette into data/palette.json.
|
|
|
|
Sources (read-only, /opt/lightgui):
|
|
- src/xframe_palette.h — the 562 XFrame widgets in section order,
|
|
each with its registry index (the index the palette -> layout
|
|
selection file carries)
|
|
- src/model.h (kTypes) — the 38 LightGUI designer types (the palette
|
|
buttons in ui/designer.ui, ids pal_button ... pal_plot)
|
|
- data/registry.json — the registry this palette must agree with
|
|
(run tools/extract_registry.py first)
|
|
|
|
The combined palette is what LIGHTGUI_PALETTE_SELFTEST drives: 38
|
|
LightGUI buttons each add one widget, 562 XFrame buttons each write
|
|
name+index to the selection file. Total 600.
|
|
|
|
Usage: python3 tools/extract_palette.py
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
import re
|
|
import sys
|
|
from collections import Counter
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
from common import (DATA_DIR, ExtractError, fail, load_json, parse_ktypes,
|
|
provenance, read_source, write_json)
|
|
|
|
PALETTE_H = "src/xframe_palette.h"
|
|
GENERATOR = "python3 tools/extract_palette.py"
|
|
|
|
|
|
def parse_xframe_palette():
|
|
text = read_source(PALETTE_H)
|
|
m = re.search(r"kXFramePaletteCount\s*=\s*(\d+)", text)
|
|
declared = int(m.group(1)) if m else None
|
|
entries = re.findall(
|
|
r'\{\s*"([^"]+)",\s*"([^"]+)",\s*(\d+)\s*\}', text)
|
|
if not entries:
|
|
fail("no palette entries parsed from %s" % PALETTE_H)
|
|
return declared, [{"name": n, "section": s, "registry_index": int(i)}
|
|
for n, s, i in entries]
|
|
|
|
|
|
def build():
|
|
declared, xframe = parse_xframe_palette()
|
|
if declared is not None and declared != len(xframe):
|
|
fail("kXFramePaletteCount=%s but %d entries parsed"
|
|
% (declared, len(xframe)))
|
|
|
|
# Cross-check against the registry (the authority for names/sections).
|
|
reg_path = os.path.join(DATA_DIR, "registry.json")
|
|
if not os.path.isfile(reg_path):
|
|
fail("data/registry.json not found — run extract_registry.py first")
|
|
reg = load_json(reg_path)
|
|
by_name = {w["name"]: w for w in reg["widgets"]}
|
|
if set(by_name) != set(e["name"] for e in xframe):
|
|
fail("palette name set != registry name set")
|
|
if len(set(e["name"] for e in xframe)) != len(xframe):
|
|
fail("duplicate names in xframe palette")
|
|
for e in xframe:
|
|
w = by_name[e["name"]]
|
|
if e["registry_index"] != w["index"]:
|
|
fail("palette index mismatch for %s: palette=%d registry=%d"
|
|
% (e["name"], e["registry_index"], w["index"]))
|
|
if e["section"] != w["section"]:
|
|
fail("palette section mismatch for %s: palette=%r registry=%r"
|
|
% (e["name"], e["section"], w["section"]))
|
|
# Palette order is section order (SECTIONS order, then the order
|
|
# sections.py lists names within the section). Verify the section
|
|
# sequence is non-decreasing in section index.
|
|
sec_order = [s["name"] for s in reg["sections"]]
|
|
idx_seq = [sec_order.index(e["section"]) for e in xframe]
|
|
if idx_seq != sorted(idx_seq):
|
|
fail("xframe palette is not in section order")
|
|
|
|
lightgui = parse_ktypes()
|
|
if len(lightgui) != 38:
|
|
fail("expected 38 LightGUI types in kTypes, got %d" % len(lightgui))
|
|
|
|
sec_counts = Counter(e["section"] for e in xframe)
|
|
sections = [{"name": s["name"], "count": sec_counts.get(s["name"], 0)}
|
|
for s in reg["sections"]]
|
|
|
|
return {
|
|
"_provenance": provenance(
|
|
[PALETTE_H, "src/model.h", "data/registry.json"], GENERATOR),
|
|
"total": len(lightgui) + len(xframe),
|
|
"lightgui_count": len(lightgui),
|
|
"xframe_count": len(xframe),
|
|
"sections": sections,
|
|
"lightgui": lightgui,
|
|
"xframe": xframe,
|
|
}
|
|
|
|
|
|
def main():
|
|
try:
|
|
data = build()
|
|
except ExtractError as e:
|
|
print("extract_palette: ERROR: %s" % e, file=sys.stderr)
|
|
return 1
|
|
write_json(os.path.join(DATA_DIR, "palette.json"), data)
|
|
print("palette: %d entries (%d LightGUI + %d XFrame)"
|
|
% (data["total"], data["lightgui_count"], data["xframe_count"]))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|