Skip to content

feat(elements): make Slider's cb argument optional - #134

Merged
petercorke merged 1 commit into
jhavl:mainfrom
petercorke:feat/slider-callback-kwarg
Aug 22, 2026
Merged

feat(elements): make Slider's cb argument optional#134
petercorke merged 1 commit into
jhavl:mainfrom
petercorke:feat/slider-callback-kwarg

Conversation

@petercorke

Copy link
Copy Markdown
Collaborator

Summary

  • Slider(cb, ...) required a callback positionally, forcing every named slider used with the env.values/handle.callback idiom (the common case — see examples/box_sliders.py, panda_ik_sliders.py, two_link_arm.py) to pass a throwaway lambda v: None
  • cb now defaults to None and falls back to a no-op internally, so it can be omitted entirely or passed as a keyword — Swift.process_events()'s unconditional self.elements[event].cb(...) call stays safe either way
  • Cleaned up the now-unnecessary dummy lambda in the three examples that only ever used the named-slider pattern

Test plan

  • pytest tests/test_swift_element.py tests/test_assembly_handle.py — added test_slider_cb_is_optional, all existing tests (which still pass an explicit cb) untouched
  • Full pytest — no regressions (one pre-existing, unrelated failure: test_add_path_sends_points_radius_and_linewidth, caused by the installed spatialgeometry PyPI release lagging behind an unreleased Polyline rename)

🤖 Generated with Claude Code

Slider(cb, ...) required a callback positionally, forcing every named
slider used with the env.values/handle.callback idiom (the common case)
to pass a throwaway `lambda v: None`. cb now defaults to None and falls
back to a no-op internally, so it can be omitted or passed as a keyword.

Cleaned up the now-unnecessary dummy lambda in the examples that only
ever used the named-slider pattern.
@petercorke
petercorke merged commit 7bb9990 into jhavl:main Aug 22, 2026
1 check passed
petercorke added a commit to petercorke/swift that referenced this pull request Aug 22, 2026
- Link "this release's changelog" to CHANGELOG.md (was plain text)
- Drop the now-unneeded Slider(lambda v: None, ...) positional cb and
  manual while-True/step/sleep loops in both examples, in favour of
  cb=None (default since jhavl#134) and env.run(dt=...) -- matches the
  Sphinx tutorial's current style. Verified both still run headless.
- Rewrite the pip extras section following bdsim's pattern (concrete
  "to include X:" + real extra name) rather than RTB's generic
  optionlist placeholder + install matrix -- swift only has one real
  extra (nb), so RTB's matrix would be overkill.
- Drop a stray double blank line before the first example.
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.

1 participant