neu_draw.viewstate

Saved camera viewpoints, kept outside any one view so they outlive it.

Use them to show two cells from the same angle, return to a framing after a stray drag, or reopen a figure where the last one closed. views maps a slot name to a ViewState; View.save_view and View.restore_view write and read it. The camera state is whatever pygfx.Camera.get_state() returns, kept as an opaque dict. It is absolute (a world position, rotation and zoom), so it carries across scenes of any extent.

Attributes

Classes

ViewState

A camera, and the canvas size it was framed for. The size matters: a perspective

Functions

load_view_file(path[, name]) → ViewState

Read a JSON file written by save_view_file() into slot name of

save_view_file(path[, name, overwrite]) → pathlib.Path

Write the state in slot name of views to a JSON file.

Module Contents

class neu_draw.viewstate.ViewState

A camera, and the canvas size it was framed for. The size matters: a perspective camera’s horizontal field of view follows the canvas aspect ratio, so the same camera in a differently shaped canvas frames a different part of the scene.

classmethod load(path: str | pathlib.Path) → Self

Read a state written by save(). Camera vectors come back as lists, which pygfx.Camera.set_state accepts as it does arrays.

save(path: str | pathlib.Path, *, overwrite: bool = True) → pathlib.Path

Write this state to a JSON file, creating its directory. Returns the path.

camera: dict[str, Any]
size: tuple[int, int] = (0, 0)
neu_draw.viewstate.load_view_file(path: str | pathlib.Path, name: str = SAVED) → ViewState

Read a JSON file written by save_view_file() into slot name of views.

neu_draw.viewstate.save_view_file(path: str | pathlib.Path, name: str = SAVED, *, overwrite: bool = True) → pathlib.Path

Write the state in slot name of views to a JSON file.

neu_draw.viewstate.LAST = 'last'
neu_draw.viewstate.SAVED = 'saved'
neu_draw.viewstate.views: dict[str, ViewState]