Skip to content

warn when gcode field contains only a number - #396

Open
knipknap wants to merge 5 commits into
mainfrom
fix/393-number-only-gcode-warning
Open

knipknap wants to merge 5 commits into
mainfrom
fix/393-number-only-gcode-warning

Conversation

@knipknap

@knipknap knipknap commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #393

A bare number like 6000 in a macro, hook, or dialect command field is not a valid G-code command. It is passed through verbatim and sent to the machine as-is, producing the error reported in #393.

This PR shows an unobtrusive, non-blocking warning in the dialogs whenever a G-code field contains only a numeric literal (e.g. 6000, -296.429, .5):

  • Macro editor (GcodeEditorDialog, used for user macros and hooks): an Adw.Banner under the header bar names the offending line and suggests a prefixed command (e.g. M4 S6000). It updates live as the text changes.
  • Dialect editor (DialectEditorDialog): the same banner for script fields (preamble/postscript) and command template rows, plus a warning icon with tooltip on the affected row, mirroring the existing error-icon pattern.

The warning never disables the Save button, so it stays purely advisory. Comment lines (;6000) and lines with inline values (G1 X10 F6000) do not trigger it.

Continuous laser mode validation (ref. #403)

Enabling "Continuous laser mode" on a dialect whose movement templates have no {s_command} placeholder makes the exporter compute laser power for every segment and then silently drop it — continuous mode also suppresses the separate laser-on power updates, so the machine never sees any power at all (M4 S0 with no S value anywhere).

The dialect editor now warns for that combination, using the same non-blocking pattern:

  • Movement template rows that carry power in continuous mode (travel_move, linear_move, arc_cw, arc_ccw, bezier_cubic) get a warning icon when they lack {s_command} (empty templates are ignored).
  • The "Continuous laser mode" toggle itself gets a warning icon naming the affected templates.
  • The banner shows the first offending template. Both update live when templates are edited or the toggle flips, and never block saving.

Test plan

  • New tests/ui_gtk/machine/test_number_only_warning.py covers the pure detection helpers and both dialogs (warning shown/cleared, save stays enabled, errors still block save), plus the continuous-laser-mode warning (shown when templates lack {s_command}, cleared by adding the placeholder or toggling the mode off, quiet for the built-in Grbl (Raster) dialect).
  • pixi run uitest: machine + varset suites pass.
  • pixi run lint equivalents (ruff format/check, flake8, pyflakes) pass; pyright reports no new errors vs. baseline.

A bare number like '6000' in a macro, hook, or dialect command
field is not a valid G-code command and gets sent to the machine
as-is, producing errors like in #393.

Show a non-blocking warning (banner and row icon) in the macro
editor and dialect editor dialogs when a field contains only a
numeric literal, suggesting a prefixed command instead.

Fixes #393
Pass a real parent window to the dialogs and avoid direct attribute
access on PreferencesRow for dynamically attached attributes.
@knipknap knipknap changed the title fix(machine): warn when gcode field contains only a number warn when gcode field contains only a number Sep 10, 2026
Enabling 'Continuous laser mode' on a dialect whose movement
templates have no {s_command} placeholder makes the exporter
compute laser power for every segment and then silently drop
it: continuous mode also suppresses the separate laser_on power
updates, so the machine never sees any power at all (seen in
#403: 'M4 S0' with no S value anywhere).

Show a non-blocking warning in the dialect editor for that
combination: the affected movement template rows and the toggle
itself get a warning icon, and the banner names the first
offending template. The warning updates live when templates are
edited or the toggle flips, and never blocks saving.

Ref #403
widget_map values are typed as Adw.PreferencesRow, so pyright
(rightly) rejects the set_text call without an isinstance check,
mirroring the other tests.
The check for movement templates that would silently drop laser
power in continuous laser mode is domain logic, not UI logic:
move POWER_MOVE_TEMPLATE_KEYS, has_s_command() and the new
find_missing_s_command_templates() onto GcodeDialect. The dialog
now applies the current editor values to a throwaway copy and
delegates the detection to the model, keeping only the warning
wording in the UI layer.
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.

Incorrect Gcode command

1 participant