diplomat.wx_gui.fpe_editor.History

class diplomat.wx_gui.fpe_editor.History(max_size: int = 2000)[source]

Bases: object

History Object, represents a navigable history, allowing for doing, undoing, and redoing actions using little doers.

__init__(max_size: int = 2000)[source]

Construct a new history object.

Parameters:

max_size – The size of the history, or the size until items begin being deleted from the history.

Methods

__init__([max_size])

Construct a new history object.

can_redo()

Returns False if the future is not empty, otherwise False.

can_undo()

Returns True if the history is not empty, otherwise False.

clear()

Clear the history, wiping out all entries...

do(name, value)

Do an action, adding it to the history, clearing the future.

redo()

Redo the most recent change in history, using one of the registered little redoers.

register_confirmer(name, func)

Register a confirmer, which confirms if an action should actually be done before doing it.

register_redoer(name, func)

Register a little doer, which redoes an action of a specific type.

register_undoer(name, func)

Register a little doer, which undoes an action of a specific type.

set_change_handler(func)

Set the function to be called whenever this history object is updated.

undo()

Undo the most recent change in history, using one of the registered little undoers.

class Element(name: str, value: Any)[source]

Bases: object

A history ‘element’. Used internally.

can_redo() bool[source]

Returns False if the future is not empty, otherwise False.

can_undo() bool[source]

Returns True if the history is not empty, otherwise False.

clear()[source]

Clear the history, wiping out all entries…

do(name: str, value: Any)[source]

Do an action, adding it to the history, clearing the future.

Parameters:
  • name – The name of this action, or classifier of it.

  • value – The state before this action was done, can be anything….

redo()[source]

Redo the most recent change in history, using one of the registered little redoers.

register_confirmer(name: str, func: Callable[[bool], bool])[source]

Register a confirmer, which confirms if an action should actually be done before doing it.

Parameters:
  • name – The type of action this confirmer confirms.

  • func – A callable which accepts a boolean which is true if performing an undo and false if performing a redo. The callable should return a boolean, True if user confirmed the action or false if the user canceled the action.

register_redoer(name: str, func: Callable[[Any], Any | None])[source]

Register a little doer, which redoes an action of a specific type.

Parameters:
  • name – The type of action this little doer redoes.

  • func – A callable which accepts the stored state to change to and also returns the state prior to applying the change. Data type will depend on what was passed to the do method of the history object. Returning None adds no entry to the history.

register_undoer(name: str, func: Callable[[Any], Any | None])[source]

Register a little doer, which undoes an action of a specific type.

Parameters:
  • name – The type of action this little doer undoes.

  • func – A callable which accepts the stored state to change to and also returns the state prior to applying the change. Data type will depend on what was passed to the do method of the history object. Returning None adds no entry to the future.

set_change_handler(func: Callable[[History], None] | None)[source]

Set the function to be called whenever this history object is updated. Can be used to update ui widgets and etc.

undo()[source]

Undo the most recent change in history, using one of the registered little undoers.