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.

UndoStack

Maintains undo and redo history with an optional size limit.

Data

log

API

simvx.core.undo.log[source]

‘getLogger(…)’

class simvx.core.undo.Command[source]

Bases: typing.Protocol

Interface for undoable operations.

property description: str
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
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
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
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.

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
property can_redo: bool
property undo_description: str | None

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

property redo_description: str | None

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

property max_size: int