|
| 1 | +# Event Editor Module (`ui/localization/event_editor/`) |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This module is responsible for the **Right Panel** of the Localization (Action Spotting) interface. It provides the primary mechanisms for users to: |
| 6 | +1. **Create Events**: "Spot" actions at specific timestamps using dynamic category buttons. |
| 7 | +2. **Manage Schema**: Add, rename, or delete annotation categories (Heads) and labels. |
| 8 | +3. **Edit Events**: View, sort, and modify existing events in a detailed table view. |
| 9 | +4. **Control History**: Access Undo/Redo functionality for the localization task. |
| 10 | + |
| 11 | +## Directory Structure |
| 12 | + |
| 13 | +```text |
| 14 | +ui/localization/event_editor/ |
| 15 | +├── __init__.py # Package entry point; assembles components into LocRightPanel. |
| 16 | +├── spotting_controls.py # Top section: Tabbed interface for action spotting buttons. |
| 17 | +└── annotation_table.py # Bottom section: Data grid showing the list of events. |
| 18 | +
|
| 19 | +``` |
| 20 | + |
| 21 | +## Components Breakdown |
| 22 | + |
| 23 | +### 1. `__init__.py` |
| 24 | + |
| 25 | +**Main Class:** `LocRightPanel` |
| 26 | + |
| 27 | +* **Role**: The main container widget that acts as the "Right Panel" in the Localization layout. |
| 28 | +* **Composition**: |
| 29 | +* **Header**: Contains the "Annotation Controls" label and the **Undo/Redo** buttons. |
| 30 | +* **Top Widget**: `AnnotationManagementWidget` (imported from `spotting_controls.py`). |
| 31 | +* **Bottom Widget**: `AnnotationTableWidget` (imported from `annotation_table.py`). |
| 32 | + |
| 33 | + |
| 34 | +* **Usage**: This class is instantiated by the `UnifiedTaskPanel` (or `MainWindowUI`) to construct the UI. |
| 35 | + |
| 36 | +### 2. `spotting_controls.py` |
| 37 | + |
| 38 | +**Role**: Handles the dynamic creation of buttons based on the JSON schema. It allows users to click a button to record an event at the current video timestamp. |
| 39 | + |
| 40 | +**Key Classes:** |
| 41 | + |
| 42 | +* **`SpottingTabWidget`**: |
| 43 | +* A `QTabWidget` where each tab represents a **Head** (Category, e.g., "Pass", "Shot"). |
| 44 | +* Supports context menus on tabs to **Rename** or **Delete** heads. |
| 45 | +* Contains a special `+` tab to add new heads dynamically. |
| 46 | + |
| 47 | + |
| 48 | +* **`HeadSpottingPage`**: |
| 49 | +* The widget inside each tab. |
| 50 | +* Displays a grid of `LabelButton`s for each label defined in the schema. |
| 51 | +* Includes an "Add new label" button to extend the schema on the fly. |
| 52 | + |
| 53 | + |
| 54 | +* **`LabelButton`**: |
| 55 | +* A custom `QPushButton` that emits signals for Right-Click (Context Menu) and Double-Click events. |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +**Signals:** |
| 60 | + |
| 61 | +* `spottingTriggered(head, label)`: Emitted when a user spots an action. |
| 62 | +* `headAdded`, `headRenamed`, `headDeleted`: Emitted when schema structure changes. |
| 63 | + |
| 64 | +### 3. `annotation_table.py` |
| 65 | + |
| 66 | +**Role**: Displays the list of recorded events for the currently selected video. It supports direct cell editing. |
| 67 | + |
| 68 | +**Key Classes:** |
| 69 | + |
| 70 | +* **`AnnotationTableModel` (`QAbstractTableModel`)**: |
| 71 | +* The underlying data model connecting the UI to the list of events. |
| 72 | +* Columns: **Time** (formatted `MM:SS.mmm`), **Head**, **Label**. |
| 73 | +* Implements `setData` to allow users to double-click a cell and modify the time or label directly. |
| 74 | + |
| 75 | + |
| 76 | +* **`AnnotationTableWidget`**: |
| 77 | +* Wraps the `QTableView`. |
| 78 | +* Handles row selection (syncs with the video player seek). |
| 79 | +* Provides a context menu to **Delete** events. |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +**Signals:** |
| 84 | + |
| 85 | +* `annotationSelected(position_ms)`: Emitted when a row is clicked (tells the player to seek). |
| 86 | +* `annotationModified(old_data, new_data)`: Emitted after a cell edit (tells the Controller to push an Undo command). |
| 87 | +* `annotationDeleted(event_item)`: Emitted via context menu. |
| 88 | + |
| 89 | +## Interaction Flow |
| 90 | + |
| 91 | +1. **Initialization**: The `LocalizationManager` calls `update_schema()` on the `spotting_controls` to build the tabs. |
| 92 | +2. **Spotting**: |
| 93 | +* User clicks a button in `HeadSpottingPage`. |
| 94 | +* Signal bubbles up to `LocRightPanel` -> `LocalizationManager`. |
| 95 | +* Manager grabs current player time and adds an event to the Model. |
| 96 | + |
| 97 | + |
| 98 | +3. **Data Refresh**: |
| 99 | +* The Model updates the `AnnotationTableModel`. |
| 100 | +* The table refreshes to show the new row. |
| 101 | + |
| 102 | + |
| 103 | +4. **Editing**: |
| 104 | +* User edits a timestamp in the table. |
| 105 | +* `AnnotationTableModel` validates the input. |
| 106 | +* If valid, it updates the internal data and signals the Manager to record the change for Undo/Redo. |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | +## Dependencies |
| 111 | + |
| 112 | +* **PyQt6**: `QtWidgets`, `QtCore`, `QtGui`. |
| 113 | +* **Project Utils**: Standard signal/slot mechanisms defined in the Controller layer. |
0 commit comments