Skip to content

Commit

Permalink
Disable keybinds when model controls are open
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiebke committed May 14, 2024
1 parent ff9f83e commit 087d2eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 12 additions & 1 deletion callbacks/control_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
Input("keybind-event-listener", "event"),
State({"type": "annotation-class-store", "index": ALL}, "data"),
State("generate-annotation-class-modal", "opened"),
State("current-class-selection", "data"),
State("control-accordion", "value"),
State({"type": "edit-annotation-class-modal", "index": ALL}, "opened"),
State("current-class-selection", "data"),
prevent_initial_call=True,
)
def update_current_class_selection(
Expand All @@ -57,6 +58,7 @@ def update_current_class_selection(
all_annotation_classes,
generate_modal_opened,
previous_current_selection,
control_accordion_state,
edit_modal_opened,
):
"""
Expand All @@ -69,6 +71,11 @@ def update_current_class_selection(
# user is going to type in the class creation/edit modals and we don't want to trigger this callback using keys
if generate_modal_opened or any(edit_modal_opened):
raise PreventUpdate
if (
control_accordion_state is not None
and "run-model" in control_accordion_state
):
raise PreventUpdate
pressed_key = (
keybind_event_listener.get("key", None) if keybind_event_listener else None
)
Expand Down Expand Up @@ -162,6 +169,7 @@ def update_selected_class_style(selected_class, all_annotation_classes):
State("annotation-store", "data"),
State("generate-annotation-class-modal", "opened"),
State({"type": "edit-annotation-class-modal", "index": ALL}, "opened"),
State("control-accordion", "value"),
State("image-viewer", "figure"),
prevent_initial_call=True,
)
Expand All @@ -174,6 +182,7 @@ def annotation_mode(
annotation_store,
generate_modal_opened,
edit_modal_opened,
control_accordion_state,
fig,
):
"""
Expand All @@ -183,6 +192,8 @@ def annotation_mode(
if generate_modal_opened or any(edit_modal_opened):
# user is going to type on this page (on a modal) and we don't want to trigger this callback using keys
raise PreventUpdate
if control_accordion_state is not None and "run-model" in control_accordion_state:
raise PreventUpdate

trigger = ctx.triggered_id
pressed_key = (
Expand Down
5 changes: 4 additions & 1 deletion callbacks/image_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def render_image(
State("image-selection-slider", "max"),
State("generate-annotation-class-modal", "opened"),
State({"type": "edit-annotation-class-modal", "index": ALL}, "opened"),
State("control-accordion", "value"),
prevent_initial_call=True,
)
def keybind_image_slider(
Expand All @@ -250,11 +251,13 @@ def keybind_image_slider(
max_slice,
generate_modal_opened,
edit_modal_opened,
control_accordion_state,
):
"""Allows user to use left/right arrow keys to navigate through images"""
if generate_modal_opened or any(edit_modal_opened):
raise PreventUpdate

if control_accordion_state is not None and "run-model" in control_accordion_state:
raise PreventUpdate
pressed_key = (
keybind_event_listener.get("key", None) if keybind_event_listener else None
)
Expand Down

0 comments on commit 087d2eb

Please sign in to comment.