pyface.undo.command_stack module

class pyface.undo.command_stack.CommandStack[source]

Bases: HasTraits

The CommandStack class is the default implementation of the ICommandStack interface.

clean = Property(Bool)

This is the clean state of the stack. Its value changes as commands are undone and redone. It can also be explicity set to mark the current stack position as being clean (when the data is saved to disk for example).

redo_name = Property(Str)

This is the name of the command that can be redone. It will be empty if there is no command that can be redone. It is maintained by the undo stack.

undo_manager = Instance(IUndoManager)

This is the undo manager that manages this stack.

undo_name = Property(Str)

This is the name of the command that can be undone. It will be empty if there is no command that can be undone. It is maintained by the undo stack.

begin_macro(name)[source]

This begins a macro by creating an empty command with the given ‘name’. All subsequent calls to ‘push()’ create commands that will be children of the empty command until the next call to ‘end_macro()’. Macros may be nested. The stack is disabled (ie. nothing can be undone or redone) while a macro is being created (ie. while there is an outstanding ‘end_macro()’ call).

clear()[source]

This clears the stack, without undoing or redoing any commands, and leaves the stack in a clean state. It is typically used when all changes to the data have been abandoned.

end_macro()[source]

This ends a macro.

push(command)[source]

This executes a command and saves it on the command stack so that it can be subsequently undone and redone. ‘command’ is an instance that implements the ICommand interface. Its ‘do()’ method is called to execute the command. If any value is returned by ‘do()’ then it is returned by ‘push()’.

redo(sequence_nr=0)[source]

If ‘sequence_nr’ is 0 then the last command that was undone is redone and any result returned. Otherwise commands are redone up to and including the given ‘sequence_nr’ and any result of the last of these is returned.

undo(sequence_nr=0)[source]

If ‘sequence_nr’ is 0 then the last command is undone. Otherwise commands are undone up to and including the given ‘sequence_nr’.