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, DropdownMultiValueUiBlock, DropdownUiBlock, MarkdownUiBlock, SearchInputMultiValueUiBlock, SearchInputUiBlock, SectionUiBlock, SelectorInputMultiValueUiBlock, 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.
- 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, Union[str, List[str]]] ¶
Read Inputs to dict.
Return a dictionary of {block_id: block_value} for all blocks on the canvas with input values. Includes blocks with a value that can be a str or multivalued. Excludes TableUiBlock. Blocks that only have read attributes are omitted.
- List of included blocks:
DropdownMultiValueUiBlock DropdownUiBlock SearchInputMultiValueUiBlock SearchInputUiBlock SelectorInputMultiValueUiBlock SelectorInputUiBlock TextInputUiBlock
Raise DuplicateBlockIdError if multiple blocks with the same id are found.
- inputs_to_dict_multi_value() Dict[str, List[str]] ¶
Read Inputs to dict, but only for multi-valued blocks.
Return a dictionary of {block_id: block_value} for all blocks on the canvas with multivalued input values. Blocks that only have read attributes are omitted. Excludes TableUiBlock.
- List of included blocks:
DropdownMultiValueUiBlock SearchInputMultiValueUiBlock SelectorInputMultiValueUiBlock
Raise DuplicateBlockIdError if multiple blocks with the same id are found.
- inputs_to_dict_single_value() Dict[str, str] ¶
Read Inputs to dict, but only for single-valued blocks.
Return a dictionary of {block_id: block_value} for all blocks on the canvas with single input values. Blocks that only have read attributes are omitted. Excludes TableUiBlock.
- List of included blocks:
DropdownUiBlock SearchInputUiBlock SelectorInputUiBlock TextInputUiBlock
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.
- with_disabled() CanvasBuilder ¶
Return a new CanvasBuilder with the underlying canvas disabled.
This does not call the API, it only assigns state in the CanvasBuilder.
- with_enabled() CanvasBuilder ¶
Return a new CanvasBuilder with the underlying canvas enabled.
This does not call the API, it only assigns state in the CanvasBuilder.