pycrossword  0.4
Pure-Python implementation of a crossword puzzle generator and editor
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
pycross.utils.undo.CommandManager Class Reference

Stack-like Undo / Redo history manager: lets the app manage undoable actions. More...

Public Member Functions

def __init__ (self, histsize=1e4, cyclic=True, on_update=None, on_pop_undo=None, on_push_undo=None, on_pop_redo=None, on_push_redo=None)
 Constructor. More...
 
def canundo (self)
 Checks if there are undoable operations in the Undo stack. More...
 
def canredo (self)
 Checks if there are redoable operations in the Redo stack. More...
 
def undoable (self, pos=-1)
 Returns an operation from the Undo stack. More...
 
def redoable (self, pos=-1)
 Returns an operation from the Redo stack. More...
 
def do (self, command)
 Executes the given command, adding it to the Undo stack so it can be undone later. More...
 
def undo (self, n=1)
 Undoes a given number of operations stored in the Undo stack. More...
 
def redo (self, n=1)
 Redoes a given number of operations stored in the Redo stack. More...
 

Public Attributes

 histsize
 int Undo / Redo history size More...
 
 cyclic
 bool if True (default) the Undo / Redo stack will automatically remove the oldest operation when the threshold size is reached More...
 
 on_update
 callable callback fired when the Undo or Redo stack is updated More...
 
 on_pop_undo
 callable callback fired when an operation is removed from the Undo stack More...
 
 on_push_undo
 callable callback fired when an operation is added to the Undo stack More...
 
 on_pop_redo
 callable callback fired when an operation is removed from the Redo stack More...
 
 on_push_redo
 callable callback fired when an operation is added to the Redo stack More...
 

Private Member Functions

def _push_undo_command (self, command)
 Stores (appends) a new command in the Undo stack. More...
 
def _pop_undo_command (self)
 Removes the latest operation from the Undo stack and returns it. More...
 
def _push_redo_command (self, command)
 Stores (appends) a command in the Redo stack. More...
 
def _pop_redo_command (self)
 Removes the latest operation from the Redo stack and returns it. More...
 

Private Attributes

 _undo_commands
 list Undo stack More...
 
 _redo_commands
 list Redo stack More...
 

Detailed Description

Stack-like Undo / Redo history manager: lets the app manage undoable actions.

Constructor & Destructor Documentation

◆ __init__()

def pycross.utils.undo.CommandManager.__init__ (   self,
  histsize = 1e4,
  cyclic = True,
  on_update = None,
  on_pop_undo = None,
  on_push_undo = None,
  on_pop_redo = None,
  on_push_redo = None 
)

Constructor.

Parameters
histsizeint Undo / Redo history size (max number of operations stored in each stack); default is 10k
cyclicbool if True (default) the Undo / Redo stack will automatically remove the oldest operation when the threshold size is reached; if False, the HistoryOverflowError excetion will be raised.
on_updatecallable callback fired when the Undo or Redo stack is updated
on_pop_undocallable callback fired when an operation is removed from the Undo stack
on_push_undocallable callback fired when an operation is added to the Undo stack
on_pop_redocallable callback fired when an operation is removed from the Redo stack
on_push_redocallable callback fired when an operation is added to the Redo stack

Member Function Documentation

◆ _pop_redo_command()

def pycross.utils.undo.CommandManager._pop_redo_command (   self)
private

Removes the latest operation from the Redo stack and returns it.

Returns
Operation the removed command

◆ _pop_undo_command()

def pycross.utils.undo.CommandManager._pop_undo_command (   self)
private

Removes the latest operation from the Undo stack and returns it.

Returns
Operation the removed command

◆ _push_redo_command()

def pycross.utils.undo.CommandManager._push_redo_command (   self,
  command 
)
private

Stores (appends) a command in the Redo stack.

The Redo stack adds operations removed from the Undo stack (so they can be redone later). If the max stack size is reached, the history will remove the oldest operation if CommandManager::cyclic is True or raise the HistoryOverflowError error.

Parameters
commandOperation the command to store

◆ _push_undo_command()

def pycross.utils.undo.CommandManager._push_undo_command (   self,
  command 
)
private

Stores (appends) a new command in the Undo stack.

If the max stack size is reached, the history will remove the oldest operation if CommandManager::cyclic is True or raise the HistoryOverflowError error.

Parameters
commandOperation the new command to store

◆ canredo()

def pycross.utils.undo.CommandManager.canredo (   self)

Checks if there are redoable operations in the Redo stack.

Returns
bool whether there are redoable operations in the Redo stack
See also
CommandManager::canundo()

◆ canundo()

def pycross.utils.undo.CommandManager.canundo (   self)

Checks if there are undoable operations in the Undo stack.

Returns
bool whether there are undoable operations in the Undo stack
See also
CommandManager::canredo()

◆ do()

def pycross.utils.undo.CommandManager.do (   self,
  command 
)

Executes the given command, adding it to the Undo stack so it can be undone later.

Parameters
commandOperation the command to execute

◆ redo()

def pycross.utils.undo.CommandManager.redo (   self,
  n = 1 
)

Redoes a given number of operations stored in the Redo stack.

Parameters
nint number of operations to redo (rewinding the stack)
Returns
bool True on success, False on failure to redo

◆ redoable()

def pycross.utils.undo.CommandManager.redoable (   self,
  pos = -1 
)

Returns an operation from the Redo stack.

Parameters
posint index of the operation
Returns
Command redoable operation

◆ undo()

def pycross.utils.undo.CommandManager.undo (   self,
  n = 1 
)

Undoes a given number of operations stored in the Undo stack.

Parameters
nint number of operations to undo (rewinding the stack)
Returns
bool True on success, False on failure to undo

◆ undoable()

def pycross.utils.undo.CommandManager.undoable (   self,
  pos = -1 
)

Returns an operation from the Undo stack.

Parameters
posint index of the operation
Returns
Command undoable operation

Member Data Documentation

◆ _redo_commands

pycross.utils.undo.CommandManager._redo_commands
private

list Redo stack

◆ _undo_commands

pycross.utils.undo.CommandManager._undo_commands
private

list Undo stack

◆ cyclic

pycross.utils.undo.CommandManager.cyclic

bool if True (default) the Undo / Redo stack will automatically remove the oldest operation when the threshold size is reached

◆ histsize

pycross.utils.undo.CommandManager.histsize

int Undo / Redo history size

◆ on_pop_redo

pycross.utils.undo.CommandManager.on_pop_redo

callable callback fired when an operation is removed from the Redo stack

◆ on_pop_undo

pycross.utils.undo.CommandManager.on_pop_undo

callable callback fired when an operation is removed from the Undo stack

◆ on_push_redo

pycross.utils.undo.CommandManager.on_push_redo

callable callback fired when an operation is added to the Redo stack

◆ on_push_undo

pycross.utils.undo.CommandManager.on_push_undo

callable callback fired when an operation is added to the Undo stack

◆ on_update

pycross.utils.undo.CommandManager.on_update

callable callback fired when the Undo or Redo stack is updated


The documentation for this class was generated from the following file: