From 087d2eb53c522bfbd8486ca2bbdf9378efa45cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiebke=20K=C3=B6pp?= Date: Tue, 14 May 2024 11:30:32 -0700 Subject: [PATCH] Disable keybinds when model controls are open --- callbacks/control_bar.py | 13 ++++++++++++- callbacks/image_viewer.py | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/callbacks/control_bar.py b/callbacks/control_bar.py index 3c6a91d..a7028ab 100644 --- a/callbacks/control_bar.py +++ b/callbacks/control_bar.py @@ -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( @@ -57,6 +58,7 @@ def update_current_class_selection( all_annotation_classes, generate_modal_opened, previous_current_selection, + control_accordion_state, edit_modal_opened, ): """ @@ -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 ) @@ -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, ) @@ -174,6 +182,7 @@ def annotation_mode( annotation_store, generate_modal_opened, edit_modal_opened, + control_accordion_state, fig, ): """ @@ -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 = ( diff --git a/callbacks/image_viewer.py b/callbacks/image_viewer.py index 468526d..7815dc8 100644 --- a/callbacks/image_viewer.py +++ b/callbacks/image_viewer.py @@ -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( @@ -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 )