Skip to content

comments

ReviewMenu

Bases: MinorMode

Review menu for viewing and annotating frames with status and comments.

Creates a dockable widget for RV adding review specific functionality like status management, commenting, and frame annotations. It attaches to the AYON menu and provides controls for navigating through annotated frames and managing review metadata.

The widget displays: - Shot name and status - Review comment field - Annotation navigation controls - Image export functionality

It stores review status and comments as metadata on the source node using the AYON attribute prefix. The widget is designed to be used in conjunction with the AYON pipeline.

Source code in client/ayon_openrv/startup/pkgs_source/comments/comments.py
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
class ReviewMenu(MinorMode):
    """Review menu for viewing and annotating frames with status and comments.

    Creates a dockable widget for RV adding review specific functionality like
    status management, commenting, and frame annotations. It attaches to
    the AYON menu and provides controls for navigating through annotated
    frames and managing review metadata.

    The widget displays:
    - Shot name and status
    - Review comment field
    - Annotation navigation controls
    - Image export functionality

    It stores review status and comments as metadata on the source node using
    the AYON attribute prefix. The widget is designed to be used in
    conjunction with the AYON pipeline.
    """

    def __init__(self) -> None:
        MinorMode.__init__(self)
        self.log = logging.getLogger("ReviewMenu")
        self.log.setLevel(logging.INFO)

        bindings = [
            (
                "frame-changed",
                self.on_frame_changed,
                "Update UI on frame change",
            ),
            (
                "source-group-complete",
                self.update_ui_attribs,
                "Update UI on new source",
            ),
            (
                "graph-node-inputs-changed",
                self.graph_change,
                "Update UI on graph node inputs changed",
            )
        ]

        self.init(
            "py-ReviewMenu-mode",
            bindings,
            None,
            [
                (
                    "AYON",
                    [
                        ("_", None),  # separator
                        ("Review", self.runme, None, self._is_active),
                    ],
                )
            ],
            # initialization order
            sortKey="source_setup",
            ordering=20,
        )

        # spacers
        self.verticalSpacer = QtWidgets.QSpacerItem(
            20, 40,
            QtWidgets.QSizePolicy.Minimum,
            QtWidgets.QSizePolicy.Expanding
        )
        self.verticalSpacerMin = QtWidgets.QSpacerItem(
            2, 2,
            QtWidgets.QSizePolicy.Minimum,
            QtWidgets.QSizePolicy.Minimum
        )
        self.horizontalSpacer = QtWidgets.QSpacerItem(
            40, 10,
            QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Minimum
        )
        self.customDockWidget = QtWidgets.QWidget()

        # data
        self.current_loaded_viewnode = None
        self.review_main_layout = QtWidgets.QVBoxLayout()
        self.rev_head_label = QtWidgets.QLabel("Shot Review")
        self.set_item_font(self.rev_head_label, size=16)
        self.rev_head_name = QtWidgets.QLabel("Shot Name")
        self.current_loaded_shot = QtWidgets.QLabel("")
        self.current_shot_status = QtWidgets.QComboBox()
        self.current_shot_status.addItems([
            "In Review", "Ready For Review", "Reviewed", "Approved", "Deliver"
        ])
        self.current_shot_comment = QtWidgets.QPlainTextEdit()
        self.current_shot_comment.setStyleSheet(
            "color: white; background-color: black"
        )

        self.review_main_layout_head = QtWidgets.QVBoxLayout()
        self.review_main_layout_head.addWidget(self.rev_head_label)
        self.review_main_layout_head.addWidget(self.rev_head_name)
        self.review_main_layout_head.addWidget(self.current_loaded_shot)
        self.review_main_layout_head.addWidget(self.current_shot_status)
        self.review_main_layout_head.addWidget(self.current_shot_comment)

        self.get_view_image = QtWidgets.QPushButton("Export frame as image")
        self.review_main_layout_head.addWidget(self.get_view_image)

        self.remove_cmnt_status_btn = QtWidgets.QPushButton("Remove comment and status")  # noqa
        self.review_main_layout_head.addWidget(self.remove_cmnt_status_btn)

        self.rvWindow = None
        self.dockWidget = None

        # annotations controls
        self.notes_layout = QtWidgets.QVBoxLayout()
        self.notes_layout_label = QtWidgets.QLabel("Annotations")
        self.btn_note_prev = QtWidgets.QPushButton("Previous Annotation")
        self.btn_note_next = QtWidgets.QPushButton("Next Annotation")
        self.notes_layout.addWidget(self.notes_layout_label)
        self.notes_layout.addWidget(self.btn_note_prev)
        self.notes_layout.addWidget(self.btn_note_next)

        self.review_main_layout.addLayout(self.review_main_layout_head)
        self.review_main_layout.addLayout(self.notes_layout)
        self.review_main_layout.addStretch(1)
        self.customDockWidget.setLayout(self.review_main_layout)

        # signals
        self.current_shot_status.currentTextChanged.connect(self.setup_combo_status)  # noqa
        self.current_shot_comment.textChanged.connect(self.comment_update)
        self.get_view_image.clicked.connect(self.get_gui_image)
        self.remove_cmnt_status_btn.clicked.connect(self.clean_cmnt_status)
        self.btn_note_prev.clicked.connect(self.annotate_prev)
        self.btn_note_next.clicked.connect(self.annotate_next)

    def runme(self, arg1=None, arg2=None):
        self.rvWindow = rv.qtutils.sessionWindow()
        if self.dockWidget is None:
            # Create DockWidget and add the Custom Widget on first run
            self.dockWidget = QtWidgets.QDockWidget("AYON Review",
                                                    self.rvWindow)
            self.dockWidget.setWidget(self.customDockWidget)

            # Dock widget to the RV MainWindow
            self.rvWindow.addDockWidget(QtCore.Qt.RightDockWidgetArea,
                                        self.dockWidget)

            self.on_frame_changed(None)
        else:
            # Toggle visibility state
            self.dockWidget.toggleViewAction().trigger()
            self.on_frame_changed(None)

    def _is_active(self):
        if self.dockWidget is not None and self.dockWidget.isVisible():
            return rv.commands.CheckedMenuState
        else:
            return rv.commands.UncheckedMenuState

    def set_item_font(self, item, size=14, bold=True):
        font = QtGui.QFont()
        if bold:
            font.setFamily("Arial Bold")
        else:
            font.setFamily("Arial")
        font.setPointSize(size)
        font.setBold(True)
        item.setFont(font)

    def on_frame_changed(self, event=None):
        """Handler for when the active clip/source changes"""
        if event is not None:
            # If the event is not None, it means the frame has changed
            self.log.debug(f"on_frame_changed: event={event.name()} | {event.contents()}")

        # Get the new active source/clip
        self.get_view_source()

        # Update the UI to reflect the new clip
        self.update_ui_attribs(event)

    def graph_change(self, event=None):
        self.log.debug("graph_change")
        # Get the new active source/clip
        self.get_view_source()

        # Update the UI to reflect the new clip
        self.update_ui_attribs(event)

    def get_view_source(self):
        try:
            sources = rv.commands.sourcesAtFrame(rv.commands.frame())
            self.current_loaded_viewnode = (
                sources[0] if sources and len(sources) > 0 else None)
            self.log.debug(f"get_view_source: {self.current_loaded_viewnode}")
        except Exception as e:
            self.log.error(f"Error getting sources: {e}")
            self.current_loaded_viewnode = None

    def update_ui_attribs(self, event=None):
        node = self.current_loaded_viewnode
        self.log.debug(f"update_ui_attribs: {node}")
        # Use namespace as loaded shot label
        namespace = ""
        if node is not None:
            property_name = f"{node}.{AYON_ATTR_PREFIX}namespace"
            self.log.debug(f"property_name: {property_name}")
            if rv.commands.propertyExists(property_name):
                namespace = rv.commands.getStringProperty(property_name)[0]

        self.current_loaded_shot.setText(namespace)

        self.setup_properties()
        self.get_comment()

    def setup_combo_status(self):
        # setup properties
        node = self.current_loaded_viewnode
        self.log.debug(f"setup_combo_status: {node}")
        if node is None:
            return

        att_prop = f"{node}.{AYON_ATTR_PREFIX}task_status"
        status = self.current_shot_status.currentText()

         # Check if property exists, create it if it doesn't
        if not rv.commands.propertyExists(att_prop):
            rv.commands.newProperty(att_prop, rv.commands.StringType, 1)

        rv.commands.setStringProperty(att_prop, [str(status)], True)
        self.current_shot_comment.setFocus()

        self.current_shot_status.setCurrentText(status)

    def setup_properties(self):
        # setup properties
        node = self.current_loaded_viewnode
        self.log.debug(f"setup_properties: {node}")
        if node is None:
            self.current_shot_status.setCurrentIndex(0)
            return

        att_prop = f"{node}.{AYON_ATTR_PREFIX}task_status"
        if not rv.commands.propertyExists(att_prop):
            status = "In Review"
            rv.commands.newProperty(att_prop, rv.commands.StringType, 1)
            rv.commands.setStringProperty(att_prop, [str(status)], True)
            self.current_shot_status.setCurrentIndex(0)
        else:
            status = rv.commands.getStringProperty(att_prop)[0]
            self.current_shot_status.setCurrentText(status)

    def comment_update(self):
        node = self.current_loaded_viewnode
        self.log.debug(f"comment_update: {node}")
        if node is None:
            return

        comment = self.current_shot_comment.toPlainText()
        att_prop = f"{node}.{AYON_ATTR_PREFIX}task_comment"
        rv.commands.newProperty(att_prop, rv.commands.StringType, 1)
        rv.commands.setStringProperty(att_prop, [str(comment)], True)

    def get_comment(self):
        node = self.current_loaded_viewnode
        self.log.debug(f"get_comment: {node}")
        if node is None:
            self.current_shot_comment.setPlainText("")
            return

        att_prop = f"{node}.{AYON_ATTR_PREFIX}task_comment"
        if not rv.commands.propertyExists(att_prop):
            rv.commands.newProperty(att_prop, rv.commands.StringType, 1)
            rv.commands.setStringProperty(att_prop, [""], True)
        else:
            status = rv.commands.getStringProperty(att_prop)[0]
            self.current_shot_comment.setPlainText(status)

    def clean_cmnt_status(self):
        node = self.current_loaded_viewnode
        self.log.debug(f"clean_cmnt_status: {node}")

        for prop in [
            f"{node}.{AYON_ATTR_PREFIX}task_comment",
            f"{node}.{AYON_ATTR_PREFIX}task_status",
        ]:
            self.log.debug(f"prop: {prop}")
            if not rv.commands.propertyExists(prop):
                rv.commands.newProperty(prop, rv.commands.StringType, 1)
            rv.commands.setStringProperty(prop, [""], True)

        self.current_shot_status.setCurrentText("In Review")
        self.current_shot_comment.setPlainText("")

    def get_gui_image(self, filename=None):
        current_attributes = OrderedDict(rv.commands.getCurrentAttributes())
        frame_number = rv.commands.frame()
        current_frame = current_attributes.get("SourceFrame", frame_number)
        current_file_path = Path(current_attributes.get("File", "Image.png"))

        current_frame_name = current_file_path.stem
        if current_frame not in current_frame_name:
            current_frame_name = f"{current_frame_name}.{current_frame}"

        if not filename:
            # Allow user to pick filename
            filename, _ = QtWidgets.QFileDialog.getSaveFileName(
                self.customDockWidget,
                "Save image",
                f"annotate_{current_frame_name}.png",
                "Images (*.png *.jpg *.jpeg *.exr)"
            )
            if not filename:
                # User cancelled
                return

        rv.commands.exportCurrentFrame(filename)
        print("Current frame exported to: {}".format(filename))

    def annotate_next(self):
        """Set frame to next annotated frame"""
        all_notes = self.get_annotated_for_view()
        if not all_notes:
            return
        nxt = get_cycle_frame(frame=rv.commands.frame(),
                              frames_lookup=all_notes,
                              direction="next")

        rv.commands.setFrame(int(nxt))
        rv.commands.redraw()

    def annotate_prev(self):
        """Set frame to previous annotated frame"""
        all_notes = self.get_annotated_for_view()
        if not all_notes:
            return
        previous = get_cycle_frame(frame=rv.commands.frame(),
                                   frames_lookup=all_notes,
                                   direction="prev")
        rv.commands.setFrame(int(previous))
        rv.commands.redraw()

    def get_annotated_for_view(self):
        """Return the frame numbers for all annotated frames"""
        annotated_frames = rv.extra_commands.findAnnotatedFrames()
        return annotated_frames

    def get_task_status(self):
        import ftrack_api
        session = ftrack_api.Session(auto_connect_event_hub=False)
        self.log.debug("Ftrack user: \"{0}\"".format(session.api_user))

annotate_next()

Set frame to next annotated frame

Source code in client/ayon_openrv/startup/pkgs_source/comments/comments.py
375
376
377
378
379
380
381
382
383
384
385
def annotate_next(self):
    """Set frame to next annotated frame"""
    all_notes = self.get_annotated_for_view()
    if not all_notes:
        return
    nxt = get_cycle_frame(frame=rv.commands.frame(),
                          frames_lookup=all_notes,
                          direction="next")

    rv.commands.setFrame(int(nxt))
    rv.commands.redraw()

annotate_prev()

Set frame to previous annotated frame

Source code in client/ayon_openrv/startup/pkgs_source/comments/comments.py
387
388
389
390
391
392
393
394
395
396
def annotate_prev(self):
    """Set frame to previous annotated frame"""
    all_notes = self.get_annotated_for_view()
    if not all_notes:
        return
    previous = get_cycle_frame(frame=rv.commands.frame(),
                               frames_lookup=all_notes,
                               direction="prev")
    rv.commands.setFrame(int(previous))
    rv.commands.redraw()

get_annotated_for_view()

Return the frame numbers for all annotated frames

Source code in client/ayon_openrv/startup/pkgs_source/comments/comments.py
398
399
400
401
def get_annotated_for_view(self):
    """Return the frame numbers for all annotated frames"""
    annotated_frames = rv.extra_commands.findAnnotatedFrames()
    return annotated_frames

on_frame_changed(event=None)

Handler for when the active clip/source changes

Source code in client/ayon_openrv/startup/pkgs_source/comments/comments.py
225
226
227
228
229
230
231
232
233
234
235
def on_frame_changed(self, event=None):
    """Handler for when the active clip/source changes"""
    if event is not None:
        # If the event is not None, it means the frame has changed
        self.log.debug(f"on_frame_changed: event={event.name()} | {event.contents()}")

    # Get the new active source/clip
    self.get_view_source()

    # Update the UI to reflect the new clip
    self.update_ui_attribs(event)

get_cycle_frame(frame=None, frames_lookup=None, direction='next')

Cycle through frames in a lookup list, returning the nearest frame.

This function finds the frame in frames_lookup that is closest to the given frame in the specified direction. If no frame exists in the specified direction, it cycles to the other end of the list.

Note

Returns None if frames_lookup is empty.

Parameters:

Name Type Description Default
frame int

The frame number to start the search from.

None
frames_lookup list[int]

A list of frame numbers to search within.

None
direction str

The direction to search, either "next" or "prev". Defaults to "next".

'next'

Returns:

Type Description

int or None: The nearest frame number in the specified direction, or None if frames_lookup is empty.

Source code in client/ayon_openrv/startup/pkgs_source/comments/comments.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def get_cycle_frame(frame=None, frames_lookup=None, direction="next"):
    """Cycle through frames in a lookup list, returning the nearest frame.

    This function finds the frame in `frames_lookup` that is closest to the
    given `frame` in the specified `direction`. If no frame exists in the
    specified direction, it cycles to the other end of the list.

    Note:
        Returns None if `frames_lookup` is empty.

    Args:
        frame (int): The frame number to start the search from.
        frames_lookup (list[int]): A list of frame numbers to search within.
        direction (str): The direction to search, either "next" or "prev".
            Defaults to "next".

    Returns:
        int or None: The nearest frame number in the specified direction,
            or None if `frames_lookup` is empty.
    """
    if direction not in {"prev", "next"}:
        raise ValueError("Direction must be either 'next' or 'prev'. "
                         "Got: {}".format(direction))

    if not frames_lookup:
        return

    elif len(frames_lookup) == 1:
        return frames_lookup[0]

    # We require the sorting of the lookup frames because we pass e.g. the
    # result of `rv.extra_commands.findAnnotatedFrames()` as lookup frames
    # which according to its documentations states:
    # The array is not sorted and some frames may appear more than once.
    frames_lookup = list(sorted(frames_lookup))
    if direction == "next":
        # Return next nearest number or cycle to the lowest number
        return next((i for i in frames_lookup if i > frame),
                    frames_lookup[0])
    elif direction == "prev":
        # Return previous nearest number or cycle to the highest number
        return next((i for i in reversed(frames_lookup) if i < frame),
                    frames_lookup[-1])