Skip to content

Feature/982 lua form designer - #1064

Merged
AgreeDK merged 4 commits into
OpenSAK-Org:betafrom
nagisml:feature/982-lua-form-designer
Oct 16, 2026
Merged

AgreeDK merged 4 commits into
OpenSAK-Org:betafrom
nagisml:feature/982-lua-form-designer

Conversation

@nagisml

@nagisml nagisml commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Lua macros: visual form designer (#982)

@AgreeDK ⚠️ Depends on #. Merge that one first.
This branch builds on feature/982-lua-ui-forms (macro UI functions and opensak.form{}). Until that PR is merged, this PR's diff also shows its commits.

Part of #938 / #982. The form designer was split off from the UI-functions PR so the runtime API could be reviewed on its own.

What it does

Tools → Form designer… (Ctrl+Shift+D) in the macro window builds opensak.form{} dialogs with the mouse:

  • Edits forms in place. If the cursor is inside an opensak.form{…} table, the designer opens that form and Update macro writes it back. Otherwise Insert into macro puts a new form at the cursor, indented to match.
  • Doesn't run the macro. The table is parsed as Lua source (macro/form_code.py). Callbacks and other Lua expressions are shown as (Lua expression) and written back unchanged.
  • GSAK-like canvas for layout = "absolute":
    • double-click to add a control
    • drag to move, drag the handles to resize
    • rubber-band and multi-select, with property changes applying to all selected controls
    • grid and snap-to-grid
    • align and same-size tools
    • copy, paste and duplicate
    • Ctrl/Shift+arrow keys to move or resize
  • Automatic layout (layout = "auto"): an outline shows the fields top to bottom. Up/Down and Into/Out of group rearrange them.
  • Tab order, button row (default OK/Cancel, none, or custom buttons), undo/redo, and Preview with the real FormDialog.
  • Validation: before inserting, the form is checked with the same validation the runtime uses. If the macro would stop at an error, the designer warns you.
  • GSAK import: paste a GSAK form (<Data> VarName=$form … <enddata>) from the clipboard, or import one from a .gsk/.txt macro (macro/gsak_form.py). The designer then lists what changed in the conversion so you can check it.

Changes

  • src/opensak/gui/dialogs/form_designer.py: the designer dialog (new)
  • src/opensak/macro/form_code.py: finds, parses and writes the Lua table without running it (new, Qt-free)
  • src/opensak/macro/gsak_form.py: GSAK form → opensak.form{} converter (new, Qt-free)
  • src/opensak/gui/dialogs/macro_dialog.py: new Tools menu and the insert/update logic
  • src/opensak/macro/api_docs.py: the Forms section mentions the designer (CI regenerates api.md)
  • New example macros/examples/corrected_coords_form.lua, with a form built in the designer
  • Translations for all 11 languages

Tests

  • tests/unit-tests/test_macro_forms.py: Lua table parse/write round trip, expressions kept as written, GSAK conversion
  • tests/unit-tests/test_macro_form_dialog.py: designer canvas, selection, align tools, insert/update

How to try it

  1. Open corrected_coords_form.lua, put the cursor inside the opensak.form{…} table, and open Tools → Form designer.
  2. Move a control, click Update macro, then run the macro.
  3. On an empty line, design a new form and click Insert into macro.
  4. Paste a GSAK <Data> VarName=$form block through Paste form from clipboard and check the conversion notes.

Closes #982

nagisml and others added 4 commits October 15, 2026 19:17
The designer edits the table passed to opensak.form{} inside a macro: it
finds the table around the cursor, reads it without running the macro and
writes the edited form back as Lua (opensak.macro.form_code). GSAK macro
forms can be converted to opensak.form{} (opensak.macro.gsak_form).

Split off from the macro UI functions branch (feature/982-lua-ui-forms),
which this branch builds on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve import conflict in src/opensak/macro/api_docs.py: keep both the
editor-support/stdlib imports from beta (OpenSAK-Org#1060) and the form-doc imports
from this branch. Generated macro docs are left to the docs bot.
@AgreeDK
AgreeDK merged commit 5f86493 into OpenSAK-Org:beta Oct 16, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants