collections_undo package

Submodules

collections_undo.abc module

collections_undo.abc.UndoableABC[source]

alias of collections_undo.abc.UndoableABC

collections_undo.abc.undo_def(func_fw: collections_undo.abc._F) Callable[[Callable], collections_undo.abc._F][source]

Mark a function as the undo function of a already defined function.

collections_undo.abc.undoablemethod(func: collections_undo.abc._F) collections_undo.abc._F[source]

A decorator indicating undoable methods.

collections_undo.containers module

Using UndoManager in a way similar to Python object.

class collections_undo.containers.AbstractUndoableDict[source]

Bases: MutableMapping[collections_undo._containers._dict._K, collections_undo._containers._dict._V]

clear() None[source]

Clear the dictonary.

redo()[source]

Redo the last undo operation.

undo()[source]

Undo the last operation.

update(other=(), /, **kwargs)[source]

Update the dictionary with the given arguments.

class collections_undo.containers.AbstractUndoableList[source]

Bases: MutableSequence[collections_undo._containers._list._T]

An undoable mutable sequence.

  • __getitem__(self, key) -> _T … Get item at key. You must return a copy of the item if the item is mutable, such as a numpy array.

  • _raw_setitem(self, key, val) -> None … Set item at key.

  • _raw_delitem(self, key) -> None … Delete item at key.

  • _raw_insert(self, index, val) … Insert val at index.

  • __len__(self) -> int … Get length of list.

  • __iter__(self) -> Iterator … Iterate over list.

clear() None[source]

Clear the list.

extend(values: Iterable[collections_undo._containers._list._T]) None[source]

Extend the list with given values.

insert(index: int, val: collections_undo._containers._list._T)[source]

S.insert(index, value) – insert value before index

redo()[source]

Redo the last undo operation.

reverse() None[source]

S.reverse() – reverse IN PLACE

undo()[source]

Undo the last operation.

class collections_undo.containers.AbstractUndoableSet[source]

Bases: MutableSet[collections_undo._containers._set._T]

add(value: collections_undo._containers._set._T) None[source]

Add an element.

clear() None[source]

Clear the set.

discard(value: collections_undo._containers._set._T) None[source]

Remove an element. Do not raise an exception if absent.

redo()[source]

Redo the last undo operation.

undo()[source]

Undo the last operation.

class collections_undo.containers.UndoableDict(*args, **kwargs)[source]

Bases: collections_undo._containers._dict.AbstractUndoableDict[collections_undo._containers._dict._K, collections_undo._containers._dict._V]

class collections_undo.containers.UndoableList(iterable=(), /)[source]

Bases: collections_undo._containers._list.AbstractUndoableList[collections_undo._containers._list._T]

sort(*, key=None, reverse=False)[source]
class collections_undo.containers.UndoableSet(iterable: Iterable[collections_undo._containers._set._T] = (), /)[source]

Bases: collections_undo._containers._set.AbstractUndoableSet[collections_undo._containers._set._T]

collections_undo.fmt module

collections_undo.fmt.get_formatter(func: Callable)
collections_undo.fmt.map_object(value: collections_undo._formatter._T) str

Map object to string.

collections_undo.fmt.register_type(formatter, type=None, *, overwrite: bool = False) Callable[[collections_undo._formatter._T], str]

Module contents

class collections_undo.UndoManager(*, measure: Callable[..., float] = <function always_zero>, maxsize: float | Literal['inf'] = 'inf')[source]

Bases: object

append(cmd: collections_undo._command._CommandBase) None[source]

Append new command to the undo stack.

blocked()[source]

Block new command from being appended to the stack.

property called: collections_undo._stack_utils.CallbackList[Callable[[collections_undo._command._CommandBase, collections_undo._stack_utils.CallType], Any]]

Callback list for called events.

catch_errors()[source]

Catch all the errors in this context and evoke callbacks.

clear() None[source]

Clear the stack.

property empty: bool

True if stack is empty.

property errored: collections_undo._stack_utils.CallbackList[Callable[[collections_undo._command._CommandBase, Exception], Any]]

Callback list for errored events.

interface(func: Callable[_P, _R], name: str | None = None) UndoableInterface[_P, _R, Any][source]
interface(func: Literal[None], name: str | None = None) Callable[[Callable[_P, _R]], UndoableInterface[_P, _R, Any]]

Decorator for undoable setter function construction.

property is_blocked: bool

True if manager is blocked.

merge_commands(start: int, stop: int, formatter: Callable | None = None) None[source]

Merge a command set into the undo stack.

merging(formatter: Callable | None = None) None[source]

Merge all the commands into a single command in this context.

property(fget: Callable[[Any], Any] | None = None, fset: Callable[[Any, Any], None] | None = None, fdel: Callable[[Any], None] | None = None, doc: str | None = None) UndoableProperty[source]

Decorator for undoable property construction.

redo() Any[source]

Redo last command and update undo/redo stacks.

reducing()[source]

Enable command reduction in this context.

set_merging(enabled: bool) None[source]

Enable/disable merging.

set_reducing(enabled: bool)[source]

Enable/disable command reduction.

property stack_lengths: collections_undo._stack_utils.LengthPair

Return length of undo and redo stack

property stack_redo: list[collections_undo._command._CommandBase]

List of redo stack.

property stack_size: float

Return size of undo and redo stack

property stack_undo: list[collections_undo._command._CommandBase]

List of undo stack.

undef(undef: collections_undo._stack._F) collections_undo._stack._F[source]

Mark an function as an undo-undefined function.

When marked function is called, undo/redo stack get cleared.

undo() Any[source]

Undo last command and update undo/redo stacks.

undoable(f: Callable[_P, _R], name: str | None = None) ReversibleFunction[_P, _R, Any][source]
undoable(f: property, name: str | None = None) collections_undo._undoable.UndoableProperty
undoable(f: Literal[None], name: str | None = None) Callable[[Callable[_P, _R]], ReversibleFunction[_P, _R, Any]] | Callable[[property], UndoableProperty]

Decorator for undoable object construction.

collections_undo.arguments(*args, **kwargs)[source]

Function that makes returning arguments from a function easier.

Examples

>>> arguments(1, 2)  # returns (1, 2), {}
>>> arguments(1, 2, a=3)  # returns (1, 2), {'a': 3}