Skip to content

Commit

Permalink
Bringing back some Version code for unknown reasons, hope to clarify.
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Matto committed Apr 21, 2016
1 parent 29cc3d1 commit 4be347c
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 11 deletions.
39 changes: 39 additions & 0 deletions python/tk_multi_importcut/cut_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,38 @@ def set_name(self, name):
self.name_changed.emit(self, self._name, name)
self._name = name

@property
def version_name(self):
"""
Return the version name for this diff, if any
"""
if self._edit:
return self._edit.get_version_name()
if self._sg_cut_item and self._sg_cut_item["version.Version.code"]:
return self._sg_cut_item["version.Version.code"]
return None

@property
def sg_version(self):
"""
Return the Shotgun version for this diff, if any
"""
if self._edit:
return self._edit.get_sg_version()
if self._sg_cut_item and self._sg_cut_item["version"]:
return self._sg_cut_item["version"]
return None

def set_sg_version(self, sg_version):
"""
Set the Shotgun version associated with this diff
:param sg_version: A SG version, as a dictionary
:raises: ValueError if no EditEvent is associated to this diff
"""
if not self._edit:
raise ValueError("Can't set Shotgun version without an edit entry")
self._edit._sg_version = sg_version

@property
def default_head_in(self):
"""
Expand Down Expand Up @@ -864,4 +896,11 @@ def summary(self):
self.sg_cut_item["cut_item_duration"]
)
version_details = ""
sg_version = self.sg_version
if sg_version:
version_details = "%s, link %s %s" % (
sg_version["code"],
sg_version["entity"]["type"] if sg_version["entity"] else "None",
sg_version["entity.Shot.code"] if sg_version["entity.Shot.code"] else "",
)
return (shot_details, cut_item_details, version_details, str(self._edit))
30 changes: 29 additions & 1 deletion python/tk_multi_importcut/cut_diff_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,32 @@ def _set_ui_values(self):
else:
self.ui.status_label.setText("%s" % reasons)

# self.ui.status_label.setStyleSheet(_DIFF_TYPES_STYLE.get(self._cut_diff.diff_type, ""))

sg_version = self._cut_diff.sg_version
self.ui.version_name_label.setToolTip(None)
if not sg_version:
# No Version
self.ui.version_name_label.setText("<font color=%s>%s</font>" % (
_COLORS["yellow"],
self._cut_diff.version_name or "No Version",
))
elif sg_version.get("entity.Shot.code") != self._cut_diff.name:
# Version linked to another shot
self.ui.version_name_label.setText("<font color=%s>%s</font>" % (
_COLORS["sg_red"],
self._cut_diff.version_name,
))
self.ui.version_name_label.setToolTip(
"Version %s is linked to Shot %s, instead of %s" % (
self._cut_diff.version_name,
sg_version.get("entity.Shot.code"),
self._cut_diff.name,
)
)
else:
self.ui.version_name_label.setText(self._cut_diff.version_name)

value = self._cut_diff.shot_head_in
new_value = self._cut_diff.new_head_in
self.display_values(self.ui.shot_head_in_label, new_value, value)
Expand Down Expand Up @@ -320,7 +346,9 @@ def retrieve_thumbnail(self):
asynchronous thumbnail download if it is the case
"""
thumb_url = None
if self._cut_diff.sg_shot and self._cut_diff.sg_shot.get("image"):
if self._cut_diff.sg_version and self._cut_diff.sg_version.get("image"):
thumb_url = self._cut_diff.sg_version["image"]
elif self._cut_diff.sg_shot and self._cut_diff.sg_shot.get("image"):
thumb_url = self._cut_diff.sg_shot["image"]
if thumb_url:
f, path = tempfile.mkstemp()
Expand Down
55 changes: 47 additions & 8 deletions python/tk_multi_importcut/edl_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,11 +721,11 @@ def sg_cut_item_for_shot(self, sg_cut_items, sg_shot, sg_version=None, edit=None
Best matching cut item is returned, a score is computed for each entry
from :
- Is it linked to the right shot ?
- Is it linked to the right version ?
- Is the cut order the same ?
- Is the tc in the same ?
- Is the tc out the same ?
- Is it linked to the right shot?
- Is it linked to the right version?
- Is the cut order the same?
- Is the tc in the same?
- Is the tc out the same?
:param sg_cut_items: A list of CutItem instances to consider
:param sg_shot: A SG shot dictionary
Expand Down Expand Up @@ -784,9 +784,9 @@ def sg_cut_item_for_shot(self, sg_cut_items, sg_shot, sg_version=None, edit=None
def _get_cut_item_score(self, sg_cut_item, edit):
"""
Return a matching score for the given cut item and edit, based on :
- Is the cut order the same ?
- Is the tc in the same ?
- Is the tc out the same ?
- Is the cut order the same?
- Is the tc in the same?
- Is the tc out the same?
So the best score is 3 if all matches
Expand Down Expand Up @@ -827,6 +827,7 @@ def do_cut_import(self, title, sender, to, description, update_shots):
self._sg_new_cut = self.create_sg_cut(title, description)
self.update_sg_shots(update_shots)
self.progress_changed.emit(1)
# self.update_sg_versions()
self.progress_changed.emit(2)
self.create_sg_cut_items(self._sg_new_cut)
self.progress_changed.emit(3)
Expand Down Expand Up @@ -1105,6 +1106,44 @@ def update_sg_shots(self, update_shots):
else:
cut_diff._sg_shot = sg_shot

def update_sg_versions(self):
"""
Create versions in Shotgun for each shot which needs one
"""
# Temporary helper to create versions in SG for initial
# testing. Should be commented out before going into production
# unless it becomes part of the specs
self._logger.info("Updating versions ...")
sg_batch_data = []
for shot_name, items in self._summary.iteritems():
for cut_diff in items:
edit = cut_diff.edit
if edit and not edit.get_sg_version() and edit.get_version_name():
sg_batch_data.append({
"request_type": "create",
"entity_type": "Version",
"data": {
"project": self._ctx.project,
"code": edit.get_version_name(),
"entity": cut_diff.sg_shot,
"updated_by": self._ctx.user,
"created_by": self._ctx.user,
"entity": cut_diff.sg_shot,
},
"return_fields": [
"entity.Shot.code",
]
})
if sg_batch_data:
res = self._sg.batch(sg_batch_data)
self._logger.info("Created %d new versions." % len(res))
for shot_name, items in self._summary.iteritems():
for cut_diff in items:
edit = cut_diff.edit
if edit and not edit.get_sg_version():
# Creation order should match
cut_diff.set_sg_version(res.pop(0))

def create_sg_cut_items(self, sg_cut):
"""
Create the cut items in Shotgun, linked to the given cut
Expand Down
2 changes: 1 addition & 1 deletion python/tk_multi_importcut/ui/cut_diff_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def setupUi(self, CutDiffCard):
self.version_name_label.setObjectName("version_name_label")
self.gridLayout_2.addWidget(self.version_name_label, 1, 1, 1, 1)
self.version_title_label = QtGui.QLabel(CutDiffCard)
self.version_title_label.setText("")
self.version_title_label.setObjectName("version_title_label")
self.gridLayout_2.addWidget(self.version_title_label, 1, 0, 1, 1)
self.shot_title_label = QtGui.QLabel(CutDiffCard)
Expand Down Expand Up @@ -153,6 +152,7 @@ def setupUi(self, CutDiffCard):

def retranslateUi(self, CutDiffCard):
CutDiffCard.setWindowTitle(QtGui.QApplication.translate("CutDiffCard", "Frame", None, QtGui.QApplication.UnicodeUTF8))
self.version_title_label.setText(QtGui.QApplication.translate("CutDiffCard", "Version", None, QtGui.QApplication.UnicodeUTF8))
self.shot_title_label.setText(QtGui.QApplication.translate("CutDiffCard", "SHOT", None, QtGui.QApplication.UnicodeUTF8))
self.status_label.setText(QtGui.QApplication.translate("CutDiffCard", "New", None, QtGui.QApplication.UnicodeUTF8))
self.tail_title_label.setText(QtGui.QApplication.translate("CutDiffCard", "<b>TAIL</b>", None, QtGui.QApplication.UnicodeUTF8))
Expand Down
2 changes: 1 addition & 1 deletion resources/cut_diff_card.ui
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
<item row="1" column="0">
<widget class="QLabel" name="version_title_label">
<property name="text">
<string/>
<string>Version</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 4be347c

Please sign in to comment.