54
55
56
57
58
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 | class ReviewMenu(MinorMode):
def __init__(self):
MinorMode.__init__(self)
self.init("py-ReviewMenu-mode", None, 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("Get 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.setup_listeners()
else:
# Toggle visibility state
self.dockWidget.toggleViewAction().trigger()
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, noweight=False, bold=True):
font = QtGui.QFont()
if bold:
font.setFamily("Arial Bold")
else:
font.setFamily("Arial")
font.setPointSize(size)
font.setBold(True)
if not noweight:
font.setWeight(75)
item.setFont(font)
def setup_listeners(self):
# Some other supported signals:
# new-source
# graph-state-change,
# after-progressive-loading,
# media-relocated
rv.commands.bind("default", "global", "source-media-set",
self.graph_change, "Doc string")
rv.commands.bind("default", "global", "after-graph-view-change",
self.graph_change, "Doc string")
def graph_change(self, event):
# update the view
self.get_view_source()
def get_view_source(self):
sources = rv.commands.sourcesAtFrame(rv.commands.frame())
self.current_loaded_viewnode = sources[0] if sources else None
self.update_ui_attribs()
def update_ui_attribs(self):
node = self.current_loaded_viewnode
# Use namespace as loaded shot label
namespace = ""
if node is not None:
property_name = "{}.openpype.namespace".format(node)
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
att_prop = node + ".openpype_review.task_status"
status = self.current_shot_status.currentText()
rv.commands.setStringProperty(att_prop, [str(status)], True)
self.current_shot_status.setCurrentText(status)
def setup_properties(self):
# setup properties
node = self.current_loaded_viewnode
if node is None:
self.current_shot_status.setCurrentIndex(0)
return
att_prop = node + ".openpype_review.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
if node is None:
return
comment = self.current_shot_comment.toPlainText()
att_prop = node + ".openpype_review.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
if node is None:
self.current_shot_comment.setPlainText("")
return
att_prop = node + ".openpype_review.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):
attribs = []
node = self.current_loaded_viewnode
att_prop_cmnt = node + ".openpype_review.task_comment"
att_prop_status = node + ".openpype_review.task_status"
attribs.append(att_prop_cmnt)
attribs.append(att_prop_status)
for prop in attribs:
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):
if not filename:
# Allow user to pick filename
filename, _ = QtWidgets.QFileDialog.getSaveFileName(
self.customDockWidget,
"Save image",
"image.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))
|