pyquibbler.Project

class pyquibbler.Project(directory: Path | None)

Bases: object

Quibbler project providing save/load and undo/redo functionality.

Keeps a weakref set of all quibs to manage the quibs centrally.

Project

get_or_create([directory])

Returns the current project.

quibs

All quibs in the project.

Undo/Redo

undo()

Undo the last quib assignment.

redo()

Redo the last quib assignment.

can_undo()

Indicates whether an assignment undo exists.

can_redo()

Indicates whether an assignment redo exists.

clear_undo_and_redo_stacks()

Clear the undo/redo stack.

File syncing

DEFAULT_SAVE_FORMAT

save_format

The default file format for saving quibs.

directory

The directory to which quib assignments are saved by default.

load_quibs([response_to_file_not_defined])

Load quib assignments from files.

save_quibs([response_to_file_not_defined])

Save quib assignments to files.

sync_quibs([response_to_file_not_defined])

Sync quib assignments with files.

Reset quibs

reset_file_loading_quibs()

Reset the value of all file-loading quibs in the project.

reset_impure_quibs()

Reset the value of all impure quibs in the project.

reset_random_quibs()

Reset the value of all random quibs in the project.

Graphics

DEFAULT_GRAPHICS_UPDATE

graphics_update

The default mode of updating graphics for all quibs.

refresh_graphics()

Redraw all graphics quibs whose graphics_update='central'.

classmethod get_or_create(directory: Path | str | None = None)

Returns the current project.

Parameters:

directory (Path, str or None, default None) – The project directory, to which quibs are saved. If None, the project directory is set based on the directory of __main__.

property quibs: Set[Quib]

All quibs in the project.

Maintains the set of all quibs in the project.

Type:

Set of Quib

register_quib(quib: Quib)

Register a quib to the project.

reset_random_quibs()

Reset the value of all random quibs in the project.

Invalidates the cache of all random quibs in the project. Any downstream graphics will refresh with new randomization.

reset_file_loading_quibs()

Reset the value of all file-loading quibs in the project.

Invalidates the cache of all file-loading quibs in the project. Request for the value of these quibs will cause re-loading of their files. Any downstream graphics will automatically update.

reset_impure_quibs()

Reset the value of all impure quibs in the project.

Invalidates the cache of all impure quibs, including random or file-loading quibs, in the project. Request for the value of these quibs will cause re-evaluation of their function. Any downstream graphics will automatically update.

refresh_graphics()

Redraw all graphics quibs whose graphics_update=’central’.

property graphics_update: GraphicsUpdateType

The default mode of updating graphics for all quibs.

Quibs whose own graphics_update is None adhere to the default graphics_update of the Project.

Can be set to GraphicsUpdateType or str:

'drag': Update continuously as upstream quibs are being dragged, or upon programmatic assignments to upstream quibs (default for graphics quibs).

'drop': Update only at the end of dragging of upstream quibs (at mouse ‘drop’), or upon programmatic assignments to upstream quibs.

'central': Do not automatically update graphics upon upstream changes. Only update upon explicit request for the quibs get_value(), or upon the central redraw command: refresh_graphics().

'never': Do not automatically update graphics upon upstream changes. Only update upon explicit request for the quibs get_value() (default for non-graphics quibs).

Type:

GraphicsUpdateType

property directory: PathWithHyperLink | None

The directory to which quib assignments are saved by default.

Can be set as a str, Path.

Quibs whose own save_directory is None adhere to the directory of the project.

Quibs with a relative path as their save_directory, save to Project.directory / Quib.save_directory

Type:

PathWithHyperLink or None

property save_format: SaveFormat

The default file format for saving quibs.

Quibs whose own save_format is None yield to this default save_format of the Project.

Can be set as SaveFormat or as str:

'off': do not save

'txt': save quib assignments as text if possible (.txt)

'bin': save quib assignments as a binary file (.quib)

Type:

SaveFormat

save_quibs(response_to_file_not_defined=ResponseToFileNotDefined.WARN_IF_DATA)

Save quib assignments to files.

Saves the assignments of all quibs which have overrides, have an assigned_name and their actual_save_format is not ‘off’.

load_quibs(response_to_file_not_defined=ResponseToFileNotDefined.WARN_IF_DATA)

Load quib assignments from files.

Loads assignments from files for all quibs which have an assigned_name and their actual_save_format is not ‘off’.

sync_quibs(response_to_file_not_defined=ResponseToFileNotDefined.WARN_IF_DATA)

Sync quib assignments with files.

Syncs quib assignments with files for all quibs which have an assigned_name and their actual_save_format is not ‘off’.

can_undo() bool

Indicates whether an assignment undo exists.

Return type:

bool

See also

can_redo, undo, redo

Examples

>>> a = iquib([1, 2, 3])
>>> qb.can_undo()
False
>>> a[1] = 10
>>> qb.can_redo()
True
>>> qb.undo()
>>> qb.can_undo()
False
can_redo() bool

Indicates whether an assignment redo exists.

Return type:

bool

See also

can_undo, undo, redo

Examples

>>> a = iquib([1, 2, 3])
>>> a[1] = 10
>>> qb.undo()
>>> qb.can_redo()
True
>>> qb.redo()
>>> qb.can_redo()
False
undo()

Undo the last quib assignment.

See also

redo, can_undo

Examples

>>> a = iquib([1, 2, 3])
>>> a[1] = 10
>>> a.get_value()
[1, 10, 3]
>>> qb.undo()
>>> a.get_value()
[1, 2, 3]
redo()

Redo the last quib assignment.

See also

undo, can_redo

Examples

>>> a = iquib([1, 2, 3])
>>> a[1] = 10
>>> a.get_value()
[1, 10, 3]
>>> qb.undo()
>>> a.get_value()
[1, 2, 3]
>>> qb.redo()
>>> a.get_value()
[1, 10, 3]
clear_undo_and_redo_stacks()

Clear the undo/redo stack.

See also

undo, redo, can_undo, can_redo

squash_pending_group_into_last_undo()

Combine the pending group into the last undo group while removing Add-Remove action pairs acting on the same assignment.