Skip to content

Commit 0b30159

Browse files
Updated docs
1 parent 1389b7e commit 0b30159

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

examples/chem-sync-local-flask/local_app/benchling_app/canvas_interaction.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,30 @@
2828
class UnsupportedButtonError(Exception):
2929
pass
3030

31+
"""
32+
This file contains examples of how to handle a user clicking a button on a canvas
33+
For examples of initialization, check out canvas_initialize.py
34+
"""
3135

3236
def route_interaction_webhook(app: App, canvas_interaction: CanvasInteractionWebhookV2) -> None:
3337
canvas_id = canvas_interaction.canvas_id
38+
39+
# Access the different actions by checking which button was clicked
3440
if canvas_interaction.button_id == SEARCH_BUTTON_ID:
3541
with app.create_session_context("Search Chemicals", timeout_seconds=20) as session:
3642
session.attach_canvas(canvas_id)
43+
44+
# Use a CanvasBuilder to update an existing canvas
3745
canvas_builder = _canvas_builder_from_canvas_id(app, canvas_id)
3846
canvas_inputs = canvas_builder.inputs_to_dict_single_value()
47+
48+
# Validate and sanitize the user's search input
3949
sanitized_inputs = _validate_and_sanitize_inputs(canvas_inputs)
50+
51+
# Search for the chemical
4052
results = search(sanitized_inputs[SEARCH_TEXT_ID])
53+
54+
# Render the preview canvas
4155
render_preview_canvas(results, canvas_id, canvas_builder, session)
4256
elif canvas_interaction.button_id == CANCEL_BUTTON_ID:
4357
# Set session_id = None to detach and prior state or messages (essentially, reset)
@@ -46,12 +60,17 @@ def route_interaction_webhook(app: App, canvas_interaction: CanvasInteractionWeb
4660
.with_session_id(None)\
4761
.with_blocks(input_blocks())\
4862
.to_update()
63+
64+
# Update the canvas
4965
app.benchling.apps.update_canvas(canvas_id, canvas_update)
5066
elif canvas_interaction.button_id == CREATE_BUTTON_ID:
5167
with app.create_session_context("Create Molecules", timeout_seconds=20) as session:
5268
session.attach_canvas(canvas_id)
69+
70+
# Use a CanvasBuilder to create a new molecule
5371
canvas_builder = _canvas_builder_from_canvas_id(app, canvas_id)
5472
molecule = _create_molecule_from_canvas(app, canvas_builder)
73+
5574
render_completed_canvas(molecule, canvas_id, canvas_builder, session)
5675
else:
5776
# Re-enable the Canvas, or it will stay disabled and the user will be stuck

examples/chem-sync-local-flask/local_app/benchling_app/views/canvas_initialize.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from local_app.benchling_app.views.constants import SEARCH_BUTTON_ID, SEARCH_TEXT_ID
1818

1919
"""
20-
This file contains examples of how to handle different Canvas Webhooks
20+
This file contains examples of how create a canvas at initialization
21+
For examples of updates, check out canvas_interaction.py
2122
2223
Use a CanvasBuilder to create or update a canvas associated with your app
2324
This sdk tool can be used for easy creation and updates

0 commit comments

Comments
 (0)