|
11 | 11 | # and the serialization code, which is in `viewer_event_from_json`. |
12 | 12 |
|
13 | 13 |
|
14 | | -# Base class for all viewer events |
15 | 14 | @dataclass |
16 | 15 | class ViewerEventBase: |
| 16 | + """Base class for all viewer events.""" |
| 17 | + |
17 | 18 | application_id: str |
| 19 | + """The application ID of the recording that triggered the event.""" |
| 20 | + |
18 | 21 | recording_id: str |
| 22 | + """The recording ID of the recording that triggered the event.""" |
| 23 | + |
19 | 24 | segment_id: str | None |
| 25 | + """The segment ID of the recording that triggered the event, if any.""" |
20 | 26 |
|
21 | 27 | @property |
22 | 28 | @deprecated("Use `segment_id` instead.") |
23 | 29 | def partition_id(self) -> str | None: |
24 | 30 | return self.segment_id |
25 | 31 |
|
26 | 32 |
|
27 | | -# Selection item types with proper type discrimination |
28 | 33 | @dataclass |
29 | 34 | class EntitySelectionItem: |
| 35 | + """An entity selection item, representing a selected entity in the viewer.""" |
| 36 | + |
30 | 37 | @property |
31 | 38 | def type(self) -> Literal["entity"]: |
32 | 39 | return "entity" |
33 | 40 |
|
34 | 41 | entity_path: str |
| 42 | + """The entity path of the selected entity.""" |
| 43 | + |
35 | 44 | instance_id: int | None = None |
| 45 | + """The instance ID of the selected entity, if any.""" |
| 46 | + |
36 | 47 | view_name: str | None = None |
| 48 | + """The name of the view containing the selected entity, if any.""" |
| 49 | + |
37 | 50 | position: list[float] | None = None |
| 51 | + """The 3D position of the selection, if any.""" |
38 | 52 |
|
39 | 53 |
|
40 | 54 | @dataclass |
41 | 55 | class ViewSelectionItem: |
| 56 | + """A view selection item, representing a selected view in the viewer.""" |
| 57 | + |
42 | 58 | @property |
43 | 59 | def type(self) -> Literal["view"]: |
44 | 60 | return "view" |
45 | 61 |
|
46 | 62 | view_id: str |
| 63 | + """The ID of the selected view.""" |
| 64 | + |
47 | 65 | view_name: str |
| 66 | + """The name of the selected view.""" |
48 | 67 |
|
49 | 68 |
|
50 | 69 | @dataclass |
51 | 70 | class ContainerSelectionItem: |
| 71 | + """A container selection item, representing a selected container in the viewer.""" |
| 72 | + |
52 | 73 | @property |
53 | 74 | def type(self) -> Literal["container"]: |
54 | 75 | return "container" |
55 | 76 |
|
56 | 77 | container_id: str |
| 78 | + """The ID of the selected container.""" |
| 79 | + |
57 | 80 | container_name: str |
| 81 | + """The name of the selected container.""" |
58 | 82 |
|
59 | 83 |
|
60 | 84 | SelectionItem = EntitySelectionItem | ViewSelectionItem | ContainerSelectionItem |
| 85 | +"""Union type for all possible selection item types.""" |
61 | 86 |
|
62 | 87 |
|
63 | | -# Concrete event classes |
64 | 88 | @dataclass |
65 | 89 | class PlayEvent(ViewerEventBase): |
| 90 | + """Event triggered when the viewer starts playing.""" |
| 91 | + |
66 | 92 | @property |
67 | 93 | def type(self) -> Literal["play"]: |
68 | 94 | return "play" |
69 | 95 |
|
70 | 96 |
|
71 | 97 | @dataclass |
72 | 98 | class PauseEvent(ViewerEventBase): |
| 99 | + """Event triggered when the viewer pauses playback.""" |
| 100 | + |
73 | 101 | @property |
74 | 102 | def type(self) -> Literal["pause"]: |
75 | 103 | return "pause" |
76 | 104 |
|
77 | 105 |
|
78 | 106 | @dataclass |
79 | 107 | class TimeUpdateEvent(ViewerEventBase): |
| 108 | + """Event triggered when the current time changes in the viewer.""" |
| 109 | + |
80 | 110 | @property |
81 | 111 | def type(self) -> Literal["time_update"]: |
82 | 112 | return "time_update" |
83 | 113 |
|
84 | 114 | time: float |
| 115 | + """The new time value.""" |
85 | 116 |
|
86 | 117 |
|
87 | 118 | @dataclass |
88 | 119 | class TimelineChangeEvent(ViewerEventBase): |
| 120 | + """Event triggered when the active timeline changes in the viewer.""" |
| 121 | + |
89 | 122 | @property |
90 | 123 | def type(self) -> Literal["timeline_change"]: |
91 | 124 | return "timeline_change" |
92 | 125 |
|
93 | 126 | timeline: str |
| 127 | + """The name of the new active timeline.""" |
| 128 | + |
94 | 129 | time: float |
| 130 | + """The current time value on the new timeline.""" |
95 | 131 |
|
96 | 132 |
|
97 | 133 | @dataclass |
98 | 134 | class SelectionChangeEvent(ViewerEventBase): |
| 135 | + """Event triggered when the selection changes in the viewer.""" |
| 136 | + |
99 | 137 | @property |
100 | 138 | def type(self) -> Literal["selection_change"]: |
101 | 139 | return "selection_change" |
102 | 140 |
|
103 | 141 | items: list[SelectionItem] |
| 142 | + """The list of currently selected items.""" |
104 | 143 |
|
105 | 144 |
|
106 | 145 | @dataclass |
107 | 146 | class RecordingOpenEvent(ViewerEventBase): |
| 147 | + """Event triggered when a recording is opened in the viewer.""" |
| 148 | + |
108 | 149 | @property |
109 | 150 | def type(self) -> Literal["recording_open"]: |
110 | 151 | return "recording_open" |
111 | 152 |
|
112 | 153 | source: str |
| 154 | + """The source of the recording (e.g. a URL or file path).""" |
| 155 | + |
113 | 156 | version: str | None |
| 157 | + """The version of the recording, if available.""" |
114 | 158 |
|
115 | 159 |
|
116 | | -# Union type for all possible event types |
117 | 160 | ViewerEvent = PlayEvent | PauseEvent | TimeUpdateEvent | TimelineChangeEvent | SelectionChangeEvent | RecordingOpenEvent |
| 161 | +"""Union type for all possible viewer event types.""" |
118 | 162 |
|
119 | 163 |
|
120 | 164 | def _viewer_event_from_json_str(json_str: str) -> ViewerEvent: |
|
0 commit comments