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¶
Interface for undoable operations. |
|
Sets obj.attr to new_value; undoes by restoring old_value. |
|
Wraps a do_fn / undo_fn pair as a command. |
|
Groups several commands into a single undo step. |
|
Add child under parent. Undo removes the child. |
|
Remove child from parent. Undo re-adds at the original index. |
|
Move node from old_parent to new_parent. Undo restores both the original parent and the original sibling order via old_index. |
|
Maintains undo and redo history with an optional size limit. |
Data¶
API¶
- simvx.core.undo.log¶
‘getLogger(…)’
- class simvx.core.undo.Command[source]¶
Bases:
typing.ProtocolInterface for undoable operations.
- __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
- 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
- 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
- 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
- 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
- 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
- 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.
- property undo_description: str | None[source]¶
Description of the next action that would be undone, or None.