Got it, many thanks for it, Justin!
I have another question, the following is the working code:
class MyModel(QtGui.QStandardItemModel):
def __init__(self, parent=None):
super(MyModel, self).__init__(parent)
self.get_contents()
self.assets_column = 0
def get_contents(self):
self.clear()
contents = [
'|Base|character|Mike|body',
'|Base|character|John',
'|Base|camera'
]
base_grp_icon = QtGui.QIcon('/user_data/base_grp_icon.png') # For
|Base
char_grp_icon = .QIcon('/user_data/char_grp_icon.png') # For
|Base|character
char_icon = .QIcon('/user_data/char_icon.png') # For
|Base|character|John
cam_icon = QtGui.QIcon('/user_data/cam_icon.png') # For |Base|camera
for content in contents:
parent = self.invisibleRootItem()
# content here will be `|Base|character|Mike|body` instead of
it iterating each and every item in that path
# node_type = cmds.nodeType(content)
# if node_type == "baseMain":
# icon = base_grp_icon
# if node_type == "charGrp":
# icon = char_grp_icon
# if node_type == "charMain":
# icon = char_icon
# if node_type == "camMain":
# icon = cam_icon
for word in content.split("|")[1:]:
child_items = [parent.child(i) for i in
range(parent.rowCount())]
for item in child_items:
if item.text() == word:
it = item
break
else:
it = QtGui.QStandardItem(word)
parent.setChild(parent.rowCount(), it)
parent = it
If I had wanted to append icons for each row, what is the best way that I
can do?
Those paths that you have seen in the code, are custom node types and if I
do `cmds.nodeType` as seen in that commented code portion, I will only be
able to iterate it based on the items found within the `contents` instead
of every item within...
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/28092299-d377-41ad-ac96-2e1c7f5544bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.