Refactor: modernize helper_methods + port Mainsail layer formulas to jobStatusPage#208
Merged
Conversation
- 40 unit tests across 8 test classes covering all public slots: on_print_start, _handle_print_state, on_print_stats_update, on_gcode_move_update, virtual_sdcard_update, pause_resume_print, handleCancel, on_fileinfo - tests/widgets/conftest.py: fix cross-suite isolation (clears empty lib.* stubs registered by network conftest, ensures BlocksScreen/on sys.path) - jobStatusPage: frozenset class constants, compound guard, if/elif chains, _post_event helper, walrus list comprehension, removed no-op QPixmap.scaled, removed spurious show() on collapse
HugoCLSC
approved these changes
Jul 1, 2026
4 tasks
HugoCLSC
added a commit
that referenced
this pull request
Jul 3, 2026
…slots (#258) # Description Select the type: - [ ] Feature - [x] Bug fix - [ ] Code refactor - [ ] Documentation Follow-up hardening for the `jobStatusPage` layer logic introduced in **#208**. Fixes a field-observed bug where the current-layer counter jumped whenever the toolhead raised Z (travel moves / Z-hop) to reach another region of the plate, and aligns the layer-source priority with Mainsail's getters. - Reject transient Z rises: the current layer now commits an advance only once Z has settled (confirmed across two samples) and never regresses, so Z-hop and travel moves no longer bump the layer number. - Respect reported totals: a Klipper-reported `print_stats.info.total_layer` (or `current_file.layer_count`) is no longer overwritten by the geometry estimate, matching Mainsail's `getPrintMaxLayers` priority. - `on_flowguard_update`: renamed params that shadowed the `str`/`dict` builtins, added type hints, and applied each key independently so a partial delta no longer raises `KeyError`. - `handleCancel`: replaced the disconnect+reconnect dance with a single `UniqueConnection` (guarded) connect. - `showEvent`: now calls `super().showEvent()`. - Simplified `toggle_thumbnail_expansion`, merged the duplicate valid-state branch in `_handle_print_state`, and tidied the print-stats dispatch. # Motivation The Z-based layer fallback read the instantaneous `gcode_move.gcode_position[2]`, so any non-print Z motion (Z-hop, travel to a taller area) was interpreted as a layer change and the counter flickered. Since `gcode_position` is published on essentially every move, a two-sample "Z settled" filter reliably distinguishes a real layer advance from a transient hop while keeping the counter monotonic. The layer-source priority was also corrected to match Mainsail so a reported total layer count is never clobbered by the geometry estimate. # Tests New/updated cases: transient Z-hop does not bump the layer, layer never regresses, reported `total_layer` not overridden by estimate, flowguard partial vs full payload, plus the two-sample settle behavior. Co-authored-by: Hugo Costa <hugo.santos.costa@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Refactors
helper_methods.pyandjobStatusPage.py, and adds a full unit test suite forJobStatusWidget.jobStatusPage.py
_VALID_STATES/_INVALID_STATES->frozensetclass constants (avoid per-call realloc)on_gcode_move_update- 7 individual guards collapsed into one compoundorguardon_print_stats_update-if/if->if/elifchains (mutually exclusive branches)_post_eventhelper - DRY up duplicatedQApplication.postEventpattern_load_thumbnails- manual loop -> walrus list comprehensionQPixmap.scaled()to identical dimensionsself.show()on thumbnail collapsehelper_methods.py
calculate_current_layer/calculate_max_layerstests/widgets/test_job_status_page_unit.py - 40 unit tests
TestOnPrintStart(4),TestHandlePrintState(7),TestOnPrintStatsUpdate(6)TestOnGcodeMoveUpdate(8),TestVirtualSdcardUpdate(3)TestPauseResumePrint(6),TestHandleCancel(4),TestOnFileInfo(5)tests/widgets/conftest.py
BlocksScreen/onsys.pathforlib.*importslib.*namespace stubs registered by the network conftest so widget tests can coexist in the fullmake test-fastrunMotivation
The refactors reduce duplicated code and allocation overhead in the hottest print-progress paths. The test suite documents the expected slot behaviour and will catch regressions in the state machine, signal wiring, and layer-calculation logic.
Tests
Widget tests alone:
40 passed