132 lines
7.2 KiB
Markdown
132 lines
7.2 KiB
Markdown
# LightGUI Python port — architecture notes
|
||
|
||
## Sources
|
||
|
||
- C designer (canonical behaviour): /opt/lightgui, https://github.com/cnmcdee/lightgui
|
||
- Rust designer (structural reference): /opt/lightgui_rust, https://github.com/cnmcdee/lightgui_rust
|
||
- Property model: /root/lightgui-inspector-properties.md on the server
|
||
(Lazarus RTTI audit; generic set + per-widget custom props + 13 §4 flag decisions)
|
||
|
||
## Key design decisions
|
||
|
||
- **Widget model = Rust archetypes, not C's 547 headers.** A small set of archetype
|
||
classes parameterised by `kind`, with data-driven property tables. The C property
|
||
tables live in `src/props.h` and `tools/gen_phase4_props.py`; the Rust tables in
|
||
`crates/lightgui-core/src/props.rs` (4239 lines) and
|
||
`crates/xframe-indicators/src/generated.rs`. The Python tables were generated
|
||
or transcribed from those, not re-invented (`tools/gen_props.py`,
|
||
`tools/gen_props_phase6.py`).
|
||
- **Canvas**: Gtk.DrawingArea + Cairo. XFrame widgets draw themselves with Cairo;
|
||
the canvas handles placement, selection, handles (13px), drag, and double-click.
|
||
- **Generated apps are Python scripts** using the Python XFrame widgets. There is no
|
||
CMake build for them: the Build/Run flow runs `python3` on the generated script
|
||
(syntax check + run), and the build console shows that output.
|
||
- **Debugger**: the C debugger is GDB/MI over C++ apps. The Python equivalent drives
|
||
`pdb` in a subprocess over the generated Python script, mirroring the session
|
||
architecture (breakpoints, step in/out/over, watch, call stack).
|
||
- **Setters are state-only; the host redraws** (same convention as C/Rust).
|
||
- **Theme is for the layout designer only.** The generated app has its own properties.
|
||
- **Inspector refreshes are split by cause.** Selection changes rebuild the rows
|
||
(`CanvasState.on_selection_change` → `Inspector.refresh`); a bounds change
|
||
under the same selection only re-syncs the four geometry spins
|
||
(`CanvasState.on_bounds_change` → `Inspector.refresh_geometry`, Phase 7),
|
||
so a programmatic resize is reflected without rebuilding rows or stealing
|
||
focus while typing. Handle drags fire the same bounds hook.
|
||
|
||
## Phase plan actually used
|
||
|
||
All phases landed Nov 30 – Dec 1, 2026, each verified live under Xvfb with
|
||
screenshots before the next started, each committed + pushed as it landed
|
||
(remote `refs/heads/main` == local HEAD).
|
||
|
||
0. **Skeleton + environment** (`e2ee6f8`) — repo on `main`, PyGObject/GTK IDE
|
||
chrome, XFrame-native canvas, runs under Xvfb.
|
||
1. **XFrame core + canvas + palette data** (`cef7988`, fixes `ff1cadb`) —
|
||
widget base/registry/draw dispatch, `CanvasState` (placement, selection,
|
||
handles, drag, double-click), 583-entry palette, project model.
|
||
2. **Generic widgets + property tables + live-apply** (`eeccee6`, `7717194`,
|
||
fix `5692908`) — property tables generated from C `props.h`, faithful
|
||
generic drawings, `Widget.set_prop` live-apply plumbing.
|
||
3. **Inspector + properties + font picker + bulk parameter** (`0cd61a3`,
|
||
fix `9383299`) — Object Inspector window, geometry spins, generic +
|
||
custom props, Lazarus events as editable text, font picker button,
|
||
bulk set/clear, colour palette; rows expand to panel width.
|
||
4. **Code view + codegen + project I/O + build/run** (`caaebd9`, `9c52f53`,
|
||
`45037b2`, `12ac322`, `b2ea94c`, `2a99acb`, `c22ff10`) — deterministic
|
||
Python codegen, code view (gutter outside the scroller, folding,
|
||
Monokai, tabs, Ctrl+S), `.fdj` load/save, build/run flow with a
|
||
filling scrolling console, menus in the Code window, dirty tracking.
|
||
5. **Debugger + Install Libraries** (`b6702c3`, follow-up `ba3b144`) — pdb
|
||
session + debugger window (breakpoints, step in/out/over, watches,
|
||
locals, stack, output console), step-over lands in the caller, Hits
|
||
column syncs; Install Libraries (pkexec/sudo root prompt, package +
|
||
launcher + `.desktop` install). The eight documented C debugger bugs
|
||
are addressed in `debugger_ui.py` / `debugger.py` docstrings.
|
||
6. **Stock (37) + Instrumentation (66) widgets** (`4333f72`, `11c380d`,
|
||
`6d2dae2`) — drawing + property tables, 103-kind table tests, draw
|
||
smoke tests, anchor + short-plot guards, 14/16-segment maps and
|
||
geometry verbatim from C.
|
||
7. **Polish + verification + README + screenshots** (`6eabe93`, `c8263b2`,
|
||
`7513673`, `4f1e907` (plus this file's final touch-up)) — debugger pane labels moved above their lists (the bottom-placed
|
||
"Breakpoints" label had crowded the "Output" label); Inspector
|
||
geometry rows refresh on programmatic resize via a bounds-change
|
||
hook; README + this file brought up to date; fresh screenshots;
|
||
fresh-clone install check; full test suite + every window verified
|
||
under Xvfb.
|
||
|
||
## Final module layout
|
||
|
||
```
|
||
ide launcher (checks DISPLAY, runs python3 -m lightgui)
|
||
lightgui/
|
||
__init__.py version (0.1.0)
|
||
__main__.py entry point
|
||
app.py Application, main window assembly (IDE chrome)
|
||
model.py project model: placed widgets, selection, .fdj place file
|
||
project_io.py .fdj load/save
|
||
props.py property tables (generic set + per-widget), data-driven
|
||
props_phase6.py Stock + Instrumentation property tables
|
||
xframe/
|
||
core.py XFrame core: widget base, registry, draw dispatch,
|
||
archetype draw implementations
|
||
canvas.py canvas (Gtk.DrawingArea), placement, selection, handles,
|
||
drag, double-click, bounds-change hook
|
||
palette.py palette data (583 entries)
|
||
stock.py Stock widgets (37)
|
||
instruments.py Instrumentation widgets (66)
|
||
inspector.py Object Inspector window
|
||
codeview.py code view with gutter/folding
|
||
generator.py Python codegen
|
||
debugger.py pdb-based step debugger session
|
||
debugger_ui.py debugger UI
|
||
build.py run/build flow for Python apps (replaces CMake build)
|
||
install_libs.py Install Libraries flow (system-wide install, root prompt)
|
||
tests/ unittest suites, one file per module area
|
||
tools/ property-table generators (gen_props.py, gen_props_phase6.py)
|
||
docs/
|
||
architecture.md this file
|
||
screenshots/ fresh Xvfb screenshots of the current UI
|
||
```
|
||
|
||
Notes on the layout as built (vs the Phase 0 sketch): there is no separate
|
||
`theme.py` / `preferences.py` — the code-view theme lives in `codeview.py`
|
||
and there is no preferences dialog; archetype draw implementations live in
|
||
`xframe/core.py` rather than separate `archetypes.py` / `widgets.py` /
|
||
`drawings.py` / `indicators.py` files.
|
||
|
||
## Final state
|
||
|
||
- All 7 phases complete; 278 tests passing under Xvfb (`DISPLAY=:99
|
||
python3 -m unittest discover -s tests`), 0 failures.
|
||
- Every window verified rendering under Xvfb: designer + Inspector, Code
|
||
window with generated Python, debugger stopped at a breakpoint,
|
||
Install Libraries dialog. Fresh screenshots in `screenshots/`.
|
||
- Fresh-clone check: a clean checkout to a scratch directory runs the
|
||
full suite and launches the designer under Xvfb with nothing hidden
|
||
in the working tree.
|
||
- Known limits are listed honestly in `README.md` (Install Libraries
|
||
root prompt unverified — no pkexec on the server; no debugger
|
||
logpoint UI — pdb has no dprintf; breakpoint on a `def` line fires
|
||
at definition time per pdb; generated scripts need `lightgui` on
|
||
`PYTHONPATH` unless installed system-wide).
|