def loadList(self): brush_notExists = QBrush(QColor(255, 150, 120)) brush_unUsed = QBrush(QColor(120, 180, 255)) brush_unUsed_and_notExists = QBrush(QColor(225, 120, 225)) brush_notExists_file = QBrush(QColor(255, 100, 100)) brush_unUsed_file = QBrush(QColor(100, 150, 255)) extensionList = [ dict1['extension'] for dict1 in self.dict_extensionList ] extensionList_with_dot = ['.' + str1 for str1 in extensionList] def cmdByExtension(first, second): firstSplit = os.path.splitext(first) secondSplit = os.path.splitext(second) if len(firstSplit) < 2 or len(secondSplit) < 2: return cmp(first, second) if not firstSplit[-1] or not secondSplit[-1]: return cmp(first, second) if firstSplit[-1][0] != '.' or secondSplit[-1][0] != '.': return cmp(first, second) if not firstSplit[-1].lower() in extensionList_with_dot: return cmp(first, second) if not secondSplit[-1].lower() in extensionList_with_dot: return cmp(first, second) if firstSplit[-1].lower() > secondSplit[-1].lower(): return 1 elif firstSplit[-1].lower() < secondSplit[-1].lower(): return -1 return cmp(first, second) from maya import cmds basePath = os.path.dirname(cmds.file(q=1, sceneName=1)) self.lineEdit.setText(basePath) self.w_tree.clear() dict_attrs = {} for w_typeAttr in self.w_typeAttrList.w_typeAttrs: if not w_typeAttr.checkBox.isChecked(): continue targetAttrs = pymel.core.ls('*.%s' % w_typeAttr.attr_name) for targetAttr in targetAttrs: dirName = os.path.dirname( os.path.normpath(targetAttr.get().strip().lower())) if not dict_attrs.has_key(dirName): dict_attrs[dirName] = [targetAttr] else: dict_attrs[dirName].append(targetAttr) showUnusedDir = self.checkBox.isChecked() for dirName in dict_attrs: filesInDir = [] for root, dirs, names in os.walk(dirName): for name in names: targetPath = os.path.normpath(root + '/' + name).strip().lower() try: ext = os.path.splitext(targetPath)[-1] except: continue if not ext[1:].lower() in extensionList: continue filesInDir.append(targetPath) break attrList = dict_attrs[dirName] itemBase = QTreeWidgetItem(self.w_tree) itemBase.setText(0, os.path.normpath(dirName).strip().lower()) notExistsList = [] unusedList = [] attrs_from_paths = {} for attr in attrList: path = os.path.normpath(attr.get().strip().lower()) if attrs_from_paths.has_key(path): attrs_from_paths[path].append(attr) else: attrs_from_paths[path] = [attr] keys_attrs_from_paths = attrs_from_paths.keys() keys_attrs_from_paths.sort(cmdByExtension) for path in keys_attrs_from_paths: item = QTreeWidgetItem(itemBase) item.setText(0, path) attrs = attrs_from_paths[path] attrName = attrs[0].name() if len(attrs) > 1: attrName += '...' item.setText(1, attrName) item.attrs = attrs if not os.path.exists(path): item.setForeground(0, brush_notExists_file) notExistsList.append(path) if path in filesInDir: filesInDir.remove(path) if showUnusedDir: for fileInDir in filesInDir: item = QTreeWidgetItem(itemBase) path = os.path.normpath(fileInDir).strip().lower() item.setText(0, path) item.setForeground(0, brush_unUsed_file) item.attrs = None unusedList.append(path) if unusedList and notExistsList: itemBase.setForeground(0, brush_unUsed_and_notExists) elif unusedList: itemBase.setForeground(0, brush_unUsed) elif notExistsList: itemBase.setForeground(0, brush_notExists) self.w_tree.resizeColumnToContents(0) self.w_tree.setColumnWidth(0, self.w_tree.columnWidth(0) + 10)