simvx.core.undo

Undo/redo system using the Command pattern.

Provides an UndoStack that tracks reversible operations, with pre-built command types for property changes, arbitrary callables, and batched operations.

Example: stack = UndoStack() cmd = PropertyCommand(node, “position”, (0, 0, 0), (1, 2, 3), description=”Move node”) stack.push(cmd) # executes + records stack.undo() # reverts to (0, 0, 0) stack.redo() # re-applies (1, 2, 3)

Module Contents

Classes

Command

Interface for undoable operations.

PropertyCommand

Sets obj.attr to new_value; undoes by restoring old_value.

CallableCommand

Wraps a do_fn / undo_fn pair as a command.

BatchCommand

Groups several commands into a single undo step.

AddChildCommand

Add child under parent. Undo removes the child.

RemoveChildCommand

Remove child from parent. Undo re-adds at the original index.

ReparentCommand

Move node from old_parent to new_parent. Undo restores both the original parent and the original sibling order via old_index.

UndoStack

Maintains undo and redo history with an optional size limit.

Data

log

API

simvx.core.undo.log

‘getLogger(…)’

class simvx.core.undo.Command[source]

Bases: typing.Protocol

Interface for undoable operations.

property description: str[source]
execute() None[source]
undo() None[source]
__slots__

()

classmethod __init_subclass__(*args, **kwargs)
classmethod __class_getitem__(item)
class simvx.core.undo.PropertyCommand(obj: Any, attr: str, old_value: Any, new_value: Any, description: str = '')[source]

Sets obj.attr to new_value; undoes by restoring old_value.

Initialization

property description: str[source]
execute() None[source]
undo() None[source]
class simvx.core.undo.CallableCommand(do_fn: collections.abc.Callable[[], None], undo_fn: collections.abc.Callable[[], None], description: str = '')[source]

Wraps a do_fn / undo_fn pair as a command.

Initialization

property description: str[source]
execute() None[source]
undo() None[source]
class simvx.core.undo.BatchCommand(commands: collections.abc.Sequence[simvx.core.undo.Command], description: str = '')[source]

Groups several commands into a single undo step.

Commands are executed in order and undone in reverse order.

Initialization

property description: str[source]
execute() None[source]
undo() None[source]
class simvx.core.undo.AddChildCommand(parent: Any, child: Any, index: int = -1, description: str = '')[source]

Add child under parent. Undo removes the child.

If index is provided (>= 0), the child is moved to that slot after the append so order is preserved on redo.

Initialization

property description: str[source]
execute() None[source]
undo() None[source]
class simvx.core.undo.RemoveChildCommand(parent: Any, child: Any, description: str = '')[source]

Remove child from parent. Undo re-adds at the original index.

The original index is captured at construction so the undo always restores the exact slot: even if siblings have shifted by the time the undo runs.

Initialization

property description: str[source]
execute() None[source]
undo() None[source]
class simvx.core.undo.ReparentCommand(node: Any, new_parent: Any, old_parent: Any, old_index: int, description: str = '')[source]

Move node from old_parent to new_parent. Undo restores both the original parent and the original sibling order via old_index.

Initialization

property description: str[source]
execute() None[source]
undo() None[source]
class simvx.core.undo.UndoStack(max_size: int = 100)[source]

Maintains undo and redo history with an optional size limit.

Parameters

max_size: Maximum number of commands kept in the undo history. When exceeded the oldest entry is silently dropped. Defaults to 100.

Initialization

push(command: simvx.core.undo.Command) None[source]

Execute command and record it on the undo stack.

push_without_execute(command: simvx.core.undo.Command) None[source]

Record command on the undo stack without executing it.

Use for operations whose effect has already been applied directly (e.g. gizmo drag, where intermediate frames mutated state). The command’s undo() must still restore the pre-operation state.

undo() bool[source]

Undo the most recent command. Returns True if an action was undone.

redo() bool[source]

Redo the most recently undone command. Returns True if an action was redone.

clear() None[source]

Discard all undo and redo history.

property can_undo: bool[source]
property can_redo: bool[source]
property undo_description: str | None[source]

Description of the next action that would be undone, or None.

property redo_description: str | None[source]

Description of the next action that would be redone, or None.

property max_size: int[source]