Skip to content

Commit

Permalink
Tweak Prim Spec editor UX, reorder some attributes for variants to be…
Browse files Browse the repository at this point in the history
… closer together, tweak variant spec colors + add tooltips and matching colors to spec filter widget
  • Loading branch information
BigRoy committed Dec 1, 2023
1 parent eae504d commit 7e2fb08
Showing 1 changed file with 73 additions and 29 deletions.
102 changes: 73 additions & 29 deletions usd_qtpy/prim_spec_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ class StageSdfModel(TreeModel):
"Layer": QtGui.QColor("#008EC5"),
"PseudoRootSpec": QtGui.QColor("#A2D2EF"),
"PrimSpec": QtGui.QColor("#A2D2EF"),
"VariantSetSpec": QtGui.QColor("#A2D2EF"),
"RelationshipSpec": QtGui.QColor("#FCD057"),
"AttributeSpec": QtGui.QColor("#FFC8DD"),
"reference": QtGui.QColor("#C8DDDD"),
"payload": QtGui.QColor("#DDC8DD"),
"variantSetName": QtGui.QColor("#DDDDC8"),
"VariantSetSpec": QtGui.QColor("#AAE48B"),
"VariantSpec": QtGui.QColor("#D6E8CC"),
"variantSetName": QtGui.QColor("#D6E8CC"),
"variantSelections": QtGui.QColor("#D6E8CC"),
}

def __init__(self, stage=None, parent=None):
Expand Down Expand Up @@ -145,6 +147,10 @@ def _traverse(path):
"type": spec.__class__.__name__
})

element_string = spec.path.elementString
if element_string and spec.name != element_string:
spec_item["name"] = element_string

if hasattr(spec, "GetTypeName"):
spec_type_name = spec.GetTypeName()
icon = self._icon_provider.get_icon_from_type_name(
Expand All @@ -169,23 +175,16 @@ def _traverse(path):
type_name = spec.typeName
spec_item["typeName"] = type_name

for attr in [
"variantSelections",
"relocates",
# Variant sets is redundant because these basically
# refer to VariantSetSpecs which will actually be
# traversed path in the layer anyway
# TODO: Remove this commented key?
# "variantSets"
]:
def _add_map_item(attr):
"""Add MapProxyItem for list attribute on Spec"""
proxy = getattr(spec, attr)

# `prim_spec.variantSelections.keys()` can fail
# todo: figure out why this workaround is needed
try:
keys = list(proxy.keys())
except RuntimeError:
continue
return

for key in keys:
proxy_item = MapProxyItem(
Expand All @@ -194,17 +193,15 @@ def _traverse(path):
data={
"name": key,
"default": proxy.get(key), # value
"type": attr
"type": attr,
"typeName": attr,
}
)
spec_item.add_child(proxy_item)

for key in [
"variantSetName",
"reference",
"payload"
]:
list_changes = getattr(spec, key + "List")
def _add_list_item(attr):
"""Add ListProxyItem for list attribute on Spec"""
list_changes = getattr(spec, attr + "List")
for change_type in LIST_ATTRS:
changes_for_type = getattr(list_changes,
change_type)
Expand All @@ -224,14 +221,26 @@ def _traverse(path):
"name": name,
# Strip off "Items"
"default": change_type[:-5],
"type": key,
"typeName": key,
"type": attr,
"typeName": attr,
"parent": changes_for_type
}
)
spec_item.add_child(list_change_item)
if list_changes:
spec_item[key] = str(list_changes)
spec_item[attr] = str(list_changes)

# Add these types intermixed just so we order attributes
# together nicely that are somewhat related, e.g. variant
# information together
for attr, add_fn in [
("reference", _add_list_item),
("payload", _add_list_item),
("relocates", _add_map_item),
("variantSelections", _add_map_item),
("variantSetName", _add_list_item),
]:
add_fn(attr)

elif isinstance(spec, Sdf.AttributeSpec):
value = spec.default
Expand Down Expand Up @@ -330,23 +339,58 @@ def filterAcceptsRow(self, source_row, source_parent):
class FilterListWidget(QtWidgets.QListWidget):
def __init__(self):
super(FilterListWidget, self).__init__()
self.addItems([

# Some labels are indented just to easily visually group some related
# options together
labels = [
"Layer",
# This is hidden since it's usually not filtered to
# "PseudoRootSpec",
"PrimSpec",
" reference",
" payload",
" variantSetName",
" relocates",
"AttributeSpec",
"RelationshipSpec",
"VariantSetSpec",
" VariantSpec",
" variantSetName",
" variantSelections",
]
tooltips = {
"Layer": "A single <b>Layer</b> in the stage.",
"PrimSpec": "A <b>Prim</b> description",
"AttributeSpec": "A property that holds typed data.",
"reference": "Represents a reference.",
"payload": (
"Represents a payload.<br>"
"Payloads are similar to prim references with the major "
"difference that payloads are explicitly loaded by the user."
),
"RelationshipSpec": (
"A property that contains a reference to "
"one or more prim specs."
),
"VariantSetSpec": "A variant set.",
"VariantSpec": "A single variant opinion for a variant set.",
"variantSetName": "Defines available variant set name on a prim.",
"variantSelections": (
"Defines the selected variant for a variant set."
)
}

for label in labels:
type_name = label.lstrip(" ")
item = QtWidgets.QListWidgetItem(label, self)

# Set color
item.setData(QtCore.Qt.ForegroundRole,
StageSdfModel.Colors.get(type_name))

tooltip = tooltips.get(type_name)
if tooltip:
item.setData(QtCore.Qt.ToolTipRole, tooltip)

# TODO: Still to be implemented in the StageSdfModel
# "variantSelections",
# "variantSets",
# "relocates"
])
self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)


Expand Down

0 comments on commit 7e2fb08

Please sign in to comment.