feat(python): expose viewport scale and pan atoms#302
Open
richardssam wants to merge 2 commits into
Open
Conversation
Register viewport_scale_atom and viewport_pan_atom in py_atoms.cpp (both already existed in C++ viewport.cpp but were not Python- accessible). Register Imath::V2f as Vec2f message type so the pan getter/setter round-trip correctly. Add Viewport.scale (float read/write) and Viewport.pan (tuple(float,float) read/write) properties. Avoids the serialise_atom/deserialise_atom crash path entirely. Signed-off-by: Sam.Richards@taurich.org <Sam.Richards@taurich.org>
Signed-off-by: Sam.Richards@taurich.org <Sam.Richards@taurich.org>
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.
What
Exposes the existing C++
viewport_scale_atom/viewport_pan_atomto thePython API as read/write
Viewport.scale(float) andViewport.pan((x, y))properties, and registers
Imath::V2fas a Python message type (V2f) so panvalues marshal across the C++/Python boundary.
Inspired from tedwaine@2f6c66a (extensions_for_sam branch) but ensuring we can get numbers back rather than just strings.
Why
Both atoms already exist in
viewport.cppbut were not reachable from Python,so scripts/plugins had no direct way to read or drive viewport zoom/pan — the
only path was
serialise_atom/deserialise_atom, which is heavier and crasheson the
Imath::V2fpan payload. This adds a direct, typed accessor.Changes
py_atoms.cpp: registerviewport_scale_atom,viewport_pan_atompy_messages.cpp/py_register.cpp: registerImath::V2fasV2f, withreadable
.x/.ymembersviewport.py:Viewport.scaleandViewport.panproperties.pangetterreturns a plain
(x, y)tuple; setters use fire-and-forgetsendNotes
V2fnaming to match the viewport-transform convention already inuse, while adding the
.x/.yaccessors and tuple-returningpangetterneeded to read a value back (not just set one), plus
send-based setters soa set doesn't block waiting on a reply.
Testing
Verified a read → transport → apply round-trip: read
Viewport.scale/Viewport.panfrom one xStudio instance and re-applied them on a peer via thenew setters, with values preserved.
Generated with assistance from Claude Code.