# tools/ — data extraction from the C++ sources The widget catalog is DATA, not hand-written Rust. These Python scripts read the C++ sources in `/opt/lightgui` (read-only) and generate the JSON tables under `data/` that the Rust port builds from. Python is tooling here, not the product. ## Regenerate / verify ```sh make regen # re-run every extractor, rewriting data/*.json make check # re-derive every table from the C++ sources; exit 1 on drift ``` `make check` requires all five tables to exist (the full state). While landing the tables one piece at a time, check one table instead: ```sh make check-registry | check-palette | check-props | check-events | check-indicators ``` `LIGHTGUI_SRC` overrides the C source location (default `/opt/lightgui`). ## Extractors | Script | Source(s) | Output | Contents | |---|---|---|---| | `extract_registry.py` | `widgets/common/registry.h`, `widgets/components/`, `widgets/tools/sections.py`, `widgets/tools/gen_registry.py` | `data/registry.json` | 562 widgets: name, family, section, default size, header path | | `extract_palette.py` | `src/xframe_palette.h`, `src/model.h`, `data/registry.json` | `data/palette.json` | 600 palette entries: 38 LightGUI + 562 XFrame | | `extract_props.py` | `src/props.h`, `src/model.h` | `data/props.json` | 6 PropKinds, 25 enum tables, 37 per-type tables (270 props), 35 common props | | `extract_events.py` | `src/events.h`, `src/model.h` | `data/events.json` | 10 EventKinds, 29 per-type tables (34 events), 9 no-events notes | | `extract_indicators.py` | `src/indicators.h` | `data/indicators.json` | 250 indicator catalog entries (name, group, plot kind, style, colour, defaults, function) | `common.py` holds the shared C++ parsing helpers (braced-initializer splitting, string literals, provenance stamping) and `parse_ktypes()` for the 38 LightGUI types in `src/model.h`. `extract_all.py` runs the five extractors in dependency order. `check.py` re-derives each table fresh and deep-compares it against the committed JSON. ## Guarantees - **No hand edits.** Every generated file carries a `_provenance` block (source repo + HEAD, source files, regenerating command). Regeneration is byte-identical unless a source changed (no timestamps). - **Three-way cross-checks.** The registry extractor derives the same numbers from `registry.h`, the on-disk component directories, `sections.py`, and the `default_size()` rule, and fails if they disagree. The palette extractor verifies every entry against the registry (name set, index, section). Props/events verify full coverage of the 38 `kTypes` keys. Indicators verify every referenced compute function is defined in the header. - **Counts are derived, never hard-coded.** The scripts fail loudly on any mismatch instead of warning. ## Re-derived counts (lightgui e474894) - Widgets: **562** — families Gtk 102, Ind 250, Inst 66, Stock 37, T 90, X 17. (The survey's Stock 38 / Inst 67 counted the shared non-widget headers `StockData.h` / `InstData.h`; the X family was 2 at survey time — XGraph, XSpreadsheet — and is 17 now with the 15 monitor widgets.) - Sections: 11 — Windows & Dialogs 28, Containers & Layout 34, Buttons 24, Display 33, Text & Entry 28, Choosers 10, Views & Lists 17, Menus & Toolbars 16, Misc / X 19, Stock Market 287, Instrumentation 66. - Palette: **600** = 38 LightGUI + 562 XFrame. - PropKinds: 6. EventKinds: **10**, not 11 as the survey stated (Simple, SwitchPage, RowActivated, RowSelected, BufferChanged, DeleteEvent, Draw, ItemClicked, ItemActivate, CellChanged). - Indicators: **250** — averages 32, bands 28, momentum 52, volume 20, volatility 43, patterns 66, final 9.