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.
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 the undo/redo stack.
File syncing
DEFAULT_SAVE_FORMAT
The default file format for saving quibs.
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 the value of all file-loading quibs in the project.
Reset the value of all impure quibs in the project.
Reset the value of all random quibs in the project.
Graphics
DEFAULT_GRAPHICS_UPDATE
The default mode of updating graphics for all quibs.
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__.
See also
- property quibs: Set[Quib]
All quibs in the project.
Maintains the set of all quibs in the project.
- Type:
Set of Quib
- 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:
- 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
See also
- 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)See also
- Type:
- 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’.
See also
Sync_quibs
,load_quibs
,Quib.save_format
,Quib.actual_save_format
,Project.save_format
,Quib.load
- 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
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
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.
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.
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.
- 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.