benchling_sdk.apps.helpers.canvas_helpers module¶
- class CanvasBuilder¶
Bases:
object
Canvas Builder.
This class provides methods to help developers effectively work with Canvas UI Blocks. Working with the underlying API models directly can be clunky, as there is no native way to easily find blocks based on their attributes, and then operate on them. Some blocks, like SectionUiBlock, have nested children blocks, further complicating the unassisted experience.
The goal of CanvasBuilder is to accept an existing Canvas, and easily change its contents (blocks), then send a resulting AppCanvasCreate or AppCanvasUpdate model to the API.
- Some block operations include:
Get by Id
Filtering by predicate
Remove
Replace
Insert After
Insert Before
Append
- Sample usage:
``` canvas: Canvas = benchling.apps.get_canvas_by_id(âcanvas_idâ) builder = CanvasBuilder.from_canvas(canvas).blocks
.filter(lambda block: isinstance(block, TextInputUiBlock)) .remove()
updated_canvas = benchling.apps.update_canvas(âcanvas_idâ, builder.to_update()) ```
- __init__(app_id: str, feature_id: str, resource_id: str, enabled: bool = True, session_id: Optional[str] = None, blocks: Optional[List[Union[ButtonUiBlock, ChipUiBlock, DropdownUiBlock, MarkdownUiBlock, SearchInputUiBlock, SectionUiBlock, SelectorInputUiBlock, TableUiBlock, TextInputUiBlock, benchling_api_client.v2.extensions.UnknownType]]] = None)¶
Init AppCanvas.
Create a CanvasBuilder from scratch. Useful when a source AppCanvas is not already created.
- property blocks: benchling_sdk.apps.helpers.canvas_helpers._CanvasBuilderBlockStream¶
Blocks.
Return a stream of blocks which can be iterated and operated on to mutate the canvas stored by the builder.
- disable() CanvasBuilder ¶
Set the canvas to disabled.
- enable() CanvasBuilder ¶
Set the canvas to enabled.
- classmethod from_canvas(canvas: AppCanvas) CanvasBuilder ¶
From Canvas.
Create a CanvasBuilder from an existing canvas. Preferred when a canvas already exists.
- inputs_to_dict() Dict[str, str] ¶
Read Inputs to dict.
Return a dictionary of {block_id: block_value} for all blocks on the canvas with input values. Blocks that only have read attributes are omitted.
Raise DuplicateBlockIdError if multiple blocks with the same id are found.
- to_create() AppCanvasCreate ¶
Return an AppCanvasCreate API model from the current state of the canvas managed by CanvasBuilder.
- to_update() AppCanvasUpdate ¶
Return an AppCanvasUpdate API model from the current state of the canvas managed by CanvasBuilder.