Skip to content

feat(python): expose viewport scale and pan atoms#302

Open
richardssam wants to merge 2 commits into
AcademySoftwareFoundation:developfrom
richardssam:pr/expose-viewport-scale-pan
Open

feat(python): expose viewport scale and pan atoms#302
richardssam wants to merge 2 commits into
AcademySoftwareFoundation:developfrom
richardssam:pr/expose-viewport-scale-pan

Conversation

@richardssam

Copy link
Copy Markdown
Contributor

What

Exposes the existing C++ viewport_scale_atom / viewport_pan_atom to the
Python API as read/write Viewport.scale (float) and Viewport.pan ((x, y))
properties, and registers Imath::V2f as a Python message type (V2f) so pan
values 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.cpp but 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 crashes
on the Imath::V2f pan payload. This adds a direct, typed accessor.

Changes

  • py_atoms.cpp: register viewport_scale_atom, viewport_pan_atom
  • py_messages.cpp / py_register.cpp: register Imath::V2f as V2f, with
    readable .x / .y members
  • viewport.py: Viewport.scale and Viewport.pan properties. pan getter
    returns a plain (x, y) tuple; setters use fire-and-forget send

Notes

  • Uses the V2f naming to match the viewport-transform convention already in
    use, while adding the .x/.y accessors and tuple-returning pan getter
    needed to read a value back (not just set one), plus send-based setters so
    a set doesn't block waiting on a reply.

Testing

Verified a read → transport → apply round-trip: read Viewport.scale /
Viewport.pan from one xStudio instance and re-applied them on a peer via the
new setters, with values preserved.

Generated with assistance from Claude Code.

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>
@richardssam richardssam changed the base branch from main to develop July 4, 2026 18:52
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