diff --git a/wazp/callbacks/events.py b/wazp/callbacks/events.py index 53fac37..b048884 100644 --- a/wazp/callbacks/events.py +++ b/wazp/callbacks/events.py @@ -1,5 +1,5 @@ import dash -from dash import Input, Output +from dash import Input, Output, State def get_callbacks(app: dash.Dash) -> None: @@ -87,3 +87,111 @@ def update_event_select_options( return options, value else: return dash.no_update, dash.no_update + + @app.callback( + Output("tag-event-button", "disabled"), + Input("event-select", "value"), + ) + def disable_tag_event_button( + event_tag: str, + ) -> bool: + """Disable the tag event button if the event tag is empty + + Parameters + ---------- + event_tag : str + Currently selected event tag + + Returns + ------- + disabled : bool + True if the tag event button should be disabled, False otherwise + """ + if event_tag == "" or event_tag is None: + return True + else: + return False + + @app.callback( + Output("events-storage", "data"), + Input("tag-event-button", "n_clicks"), + [ + State("frame-index-input", "value"), + State("events-video-select", "value"), + State("event-select", "value"), + State("events-storage", "data"), + ], + ) + def update_events_storage( + n_clicks: int, + frame_index: int, + video_name: str, + event_tag: str, + events_storage: dict, + ) -> dict: + """Update the events storage with the currently selected event tag + and frame index, when the tag event button is clicked. + + Parameters + ---------- + n_clicks : int + Number of times the tag event button has been clicked + frame_index : int + Currently selected frame index + video_name : str + Currently selected video name + event_tag : str + Currently selected event tag + events_storage : dict + Dictionary storing event tags for each video. + + Returns + ------- + events_storage : dict + data held in temporary memory storage, + accessible to all tabs in the app + """ + if n_clicks > 0: + if video_name not in events_storage.keys(): + events_storage[video_name] = dict() + events_storage[video_name][event_tag] = frame_index + return events_storage + + @app.callback( + Output("events-table", "data"), + [ + Input("events-video-select", "value"), + Input("events-storage", "data"), + ], + ) + def update_events_table( + video_name: str, + events_storage: dict, + ) -> list[dict]: + """Update the events table based on the stored events. + + Parameters + ---------- + video_name : str + Currently selected video name + events_storage : dict + Dictionary storing event tags for each video. + + Returns + ------- + data : list[dict] + list of dictionaries with the following keys and values: + - 'tag': event tag + - 'frame index': frame index + - 'seconds': frame index converted to seconds, based on the + video FPS + """ + fps = 40 + rows = [] + if video_name in events_storage.keys(): + for event, frame_idx in events_storage[video_name].items(): + sec = frame_idx / fps + rows.append( + {"tag": event, "frame index": frame_idx, "seconds": sec} + ) + return rows diff --git a/wazp/pages/03_events.py b/wazp/pages/03_events.py index 1472fa3..6ec13ac 100644 --- a/wazp/pages/03_events.py +++ b/wazp/pages/03_events.py @@ -12,9 +12,9 @@ ############################### # Get initial video -init_videos = ["No videos found yet"] +init_videos = [""] # Get initial set of event tags to initialize table -init_event_tags = ["start", "end"] +init_event_tags = [""] # Columns for events table init_events_table_columns = ["tag", "frame index", "seconds"]