history: base history mechanisms

There should be a single instance of this class; you can create it as a global, some kind of singleton, or pass it around.

Base history mechanism

exception pyqtcmd.history.ConsistencyError[source]

Thrown when something bad happens (trying to undo with an empty past list for instance).

class pyqtcmd.history.History[source]

Maintains lists of past and future commands as they are done and undone. The changed signal is emitted whenever the history state changes. This class also maintains a pointer to a ‘saved’ state and can tell if its current state is the saved one or not (see is_modified()).

can_redo()[source]

Returns True if there is at least one future command

can_undo()[source]

Returns True if there is at least one past command

check()[source]

This just emits the changed signal; use it when you think UICommand states should be updated, when add_check_signal is not enough.

freeze()[source]

This context manager will wrap calls to Command.(undo|redo|do). You can override it to provide some sort of batch updating/signalling in your own project.

is_modified()[source]

Returns True if the history state is different from what it was when save_point() was last called (or when constructed, or reset with is_new=False).

past()[source]

Return a copy of past Command objects. This may be useful in situation where, for instance, a modal dialog has a ‘local’ history, and you want to encapsulate everything that has been done in this dialog in a single CompositeCommand when the dialog is closed, and add it to the ‘main’ history.

redo()[source]

Redo the latest command that was undone. Throws ConsistencyError if there are no command to redo.

redo_label()[source]

The text for the current redo command, or None

reset(is_new=True)[source]

Resets the history state. This is typically called when a new document has been loaded or created. If is_new is False, the saved state is not reset, so is_modified() will still return True. This is intended for session management, when loading a document that hasn’t actually been saved yet.

run(command)[source]

Run a command and put it in the past. In order to keep things consistent, the future list is deleted.

save_point()[source]

Sets the ‘saved’ state as the current one. Call this after saving a document to disk for instance.

undo()[source]

Undo the latest command that was run. Throws ConsistencyError if there are no commands to undo.

undo_label()[source]

The text for the current undo command, or None

class pyqtcmd.history.HistoryVersion[source]

History version. Internal use only.