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. |
|
Maintains undo and redo history with an optional size limit. |
API¶
- class simvx.core.undo.Command¶
Bases:
typing.ProtocolInterface for undoable operations.
- property description: str¶
- execute() None¶
- undo() None¶
- __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 = '')¶
Sets obj.attr to new_value; undoes by restoring old_value.
Initialization
- property description: str¶
- execute() None¶
- undo() None¶
- class simvx.core.undo.CallableCommand(do_fn: collections.abc.Callable[[], None], undo_fn: collections.abc.Callable[[], None], description: str = '')¶
Wraps a do_fn / undo_fn pair as a command.
Initialization
- property description: str¶
- execute() None¶
- undo() None¶
- class simvx.core.undo.BatchCommand(commands: collections.abc.Sequence[simvx.core.undo.Command], description: str = '')¶
Groups several commands into a single undo step.
Commands are executed in order and undone in reverse order.
Initialization
- property description: str¶
- execute() None¶
- undo() None¶
- class simvx.core.undo.UndoStack(max_size: int = 100)¶
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¶
Execute command and record it on the undo stack.
- undo() bool¶
Undo the most recent command. Returns True if an action was undone.
- redo() bool¶
Redo the most recently undone command. Returns True if an action was redone.
- clear() None¶
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¶