class MyModel(QtGui.QStandardItemModel): def __init__(self, parent=None): super(MyModel, self).__init__(parent) self.get_contents()
def get_contents(self): self.clear() contents = [ '|Base|character|Mike|body', '|Base|character|John', '|Base|camera' ]
for content in contents: count = content.count('|') for index in range(count): index = index + 2 split_path = content.split('|')[0:index] self.add_item(split_path)
def add_item(self,name): item1 = QtGui.QStandardItem(name) self.appendRow([item1])|Base
|Base|character
|Base|character|Mike
|Base|character|Mike|body
|Base
|Base|character
|Base|character|John
|Base
|Base|camera|-- Base
|--|-- character
|--|--|-- Mike
|--|--|--|-- body
|--|-- character
|--|--|-- John
|--|-- camera--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c59b034f-9786-4215-a807-4753642bb2d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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# Class variable
MayaPath = QtCore.Qt.UserRole+1
# Save the maya path as a custom data role
it = QtGui.QStandardItem(word)
it.setData(content, self.MayaPath)
# Find items later by the maya path
idxs = self.match(
self.index(0,0),
self.MayaPath,
content,
flags=QtCore.Qt.MatchRecursive,
)
if not idxs:
# not found
it = self.itemFromIndex(idxs[0])
it.setIcon(...)
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/28092299-d377-41ad-ac96-2e1c7f5544bd%40googlegroups.com.
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/a15b269f-180f-485a-88c3-8afd78fabbc3%40googlegroups.com.