From 7e2fb085956d37217ff9cabec6c2d40a03365f0f Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 1 Dec 2023 11:07:07 +0100 Subject: [PATCH] Tweak Prim Spec editor UX, reorder some attributes for variants to be closer together, tweak variant spec colors + add tooltips and matching colors to spec filter widget --- usd_qtpy/prim_spec_editor.py | 102 +++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 29 deletions(-) diff --git a/usd_qtpy/prim_spec_editor.py b/usd_qtpy/prim_spec_editor.py index 12e9375..edd2784 100644 --- a/usd_qtpy/prim_spec_editor.py +++ b/usd_qtpy/prim_spec_editor.py @@ -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): @@ -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( @@ -169,15 +175,8 @@ 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 @@ -185,7 +184,7 @@ def _traverse(path): try: keys = list(proxy.keys()) except RuntimeError: - continue + return for key in keys: proxy_item = MapProxyItem( @@ -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) @@ -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 @@ -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 Layer in the stage.", + "PrimSpec": "A Prim description", + "AttributeSpec": "A property that holds typed data.", + "reference": "Represents a reference.", + "payload": ( + "Represents a payload.
" + "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)