Skip to content

Selection History State

app.ui.view_state.selection_history_state

View source code

Module for selection history state; stores transient interaction state.

See Also

Layer: Presentation. Context: Stores transient interaction state at this architectural boundary.

SelectionHistoryEntry dataclass

Store the selected box keys before and after one selection change.

ATTRIBUTE DESCRIPTION
before_keys

Selection to restore when undoing the change.

TYPE: list[str]

after_keys

Selection to restore when redoing the change.

TYPE: list[str]

Layer: Presentation. Context: Supports user interaction and delegates application work through presentation contracts.

after_keys: list[str] instance-attribute

before_keys: list[str] instance-attribute

__init__(before_keys: list[str], after_keys: list[str]) -> None

BoxMutationEntry dataclass

Store one frame's box and selection snapshots for undo or redo.

ATTRIBUTE DESCRIPTION
frame_index

Frame whose boxes were mutated.

TYPE: int

before_boxes

Boxes captured before the mutation.

TYPE: list

after_boxes

Boxes captured after the mutation.

TYPE: list

before_selection

Selected keys captured before the mutation.

TYPE: list[str]

after_selection

Selected keys captured after the mutation.

TYPE: list[str]

Layer: Presentation. Context: Supports user interaction and delegates application work through presentation contracts.

after_boxes: list instance-attribute

after_selection: list[str] instance-attribute

before_boxes: list instance-attribute

before_selection: list[str] instance-attribute

frame_index: int instance-attribute

__init__(frame_index: int, before_boxes: list, after_boxes: list, before_selection: list[str], after_selection: list[str]) -> None

CopiedBBoxSnapshot dataclass

Store the box fields needed to paste a copied annotation.

ATTRIBUTE DESCRIPTION
label

Classification label to copy.

TYPE: str

bbox_xyxy

Image-space (x1, y1, x2, y2) coordinates.

TYPE: tuple[int, int, int, int]

color_hex

Display color to apply to the pasted box.

TYPE: str

Layer: Presentation. Context: Supports user interaction and delegates application work through presentation contracts.

bbox_xyxy: tuple[int, int, int, int] instance-attribute

color_hex: str instance-attribute

label: str instance-attribute

__init__(label: str, bbox_xyxy: tuple[int, int, int, int], color_hex: str) -> None

SelectionHistoryState

Represent selection history state.

Layer: Presentation. Context: Supports user interaction and delegates application work through presentation contracts.

has_clipboard_boxes: bool property

Return whether the clipboard contains any copied boxes.

RETURNS DESCRIPTION
bool

True when at least one copied box is stored.

__init__() -> None

get_clipboard_boxes() -> list[CopiedBBoxSnapshot]

Return a shallow copy of the copied-box clipboard.

RETURNS DESCRIPTION
list[CopiedBBoxSnapshot]

List of clipboard snapshots; the list is copied, but its entries are shared.

record_box_mutation(*, session_id: str, tab_index: int, frame_index: int, before_boxes: list, after_boxes: list, before_selection: list[str], after_selection: list[str]) -> None

Record before/after box and selection snapshots for undo.

PARAMETER DESCRIPTION
session_id

Session whose boxes changed.

TYPE: str

tab_index

Data tab where the mutation occurred.

TYPE: int

frame_index

Zero-based index of the edited frame.

TYPE: int

before_boxes

Box list captured before the edit.

TYPE: list

after_boxes

Box list captured after the edit.

TYPE: list

before_selection

Selected keys before the edit.

TYPE: list[str]

after_selection

Selected keys after the edit.

TYPE: list[str]

Side Effects

Appends an undo entry and clears redo history for this session and tab.

record_selection_change(*, session_id: str, tab_index: int, before_keys: list[str], after_keys: list[str]) -> None

Push a selection change onto the undo stack for one session and tab.

PARAMETER DESCRIPTION
session_id

Session whose selection changed.

TYPE: str

tab_index

Data tab whose selection changed.

TYPE: int

before_keys

Selected box keys before the change.

TYPE: list[str]

after_keys

Selected box keys after the change.

TYPE: list[str]

Side Effects

Does nothing for equal selections; otherwise records the change and clears redo history.

redo_box_mutation(*, session_id: str, tab_index: int) -> BoxMutationEntry | None

Move the latest undone box mutation back to undo history.

PARAMETER DESCRIPTION
session_id

Session whose mutation history is traversed.

TYPE: str

tab_index

Data tab whose mutation history is traversed.

TYPE: int

RETURNS DESCRIPTION
BoxMutationEntry | None

Mutation snapshot to reapply, or None when no redo entry exists.

redo_selection(*, session_id: str, tab_index: int) -> list[str] | None

Move the latest undone selection change back to undo history.

PARAMETER DESCRIPTION
session_id

Session whose selection history is traversed.

TYPE: str

tab_index

Data tab whose selection history is traversed.

TYPE: int

RETURNS DESCRIPTION
list[str] | None

Copy of the restored selected keys, or None when no redo entry exists.

set_clipboard_boxes(*, boxes: list[CopiedBBoxSnapshot], tab_index: int) -> None

Replace the copied-box clipboard with snapshots from one data tab.

PARAMETER DESCRIPTION
boxes

Box snapshots available for pasting.

TYPE: list[CopiedBBoxSnapshot]

tab_index

Tab index from which the boxes were copied.

TYPE: int

undo_box_mutation(*, session_id: str, tab_index: int) -> BoxMutationEntry | None

Move the latest box mutation to redo history and return its snapshots.

PARAMETER DESCRIPTION
session_id

Session whose mutation history is traversed.

TYPE: str

tab_index

Data tab whose mutation history is traversed.

TYPE: int

RETURNS DESCRIPTION
BoxMutationEntry | None

Mutation snapshot to restore, or None when no undo entry exists.

undo_selection(*, session_id: str, tab_index: int) -> list[str] | None

Move the latest selection change to redo history and return its prior selection.

PARAMETER DESCRIPTION
session_id

Session whose selection history is traversed.

TYPE: str

tab_index

Data tab whose selection history is traversed.

TYPE: int

RETURNS DESCRIPTION
list[str] | None

Copy of the prior selected keys, or None when no undo entry exists.