from PySide.QtCore import Qt from pytd.util.fsutils import iterPaths from pytd.util.sysutils import qtGuiApp from pytd.gui.dialogs import QuickTreeDialog #srcPaths = ["A/B/C", "A/C/D", "A/C/D/E", "A/C/D/F", "A/B/D/F", "A/A/D/F", "A/C/D/G"] app = qtGuiApp() if not app: app = QtGui.QApplication(sys.argv) dlg = QuickTreeDialog() treeWdg = dlg.treeWidget treeWdg.setSortingEnabled(True) dlg.show() def iterTreeData(): for p in iterPaths("C:/Users/styx/Google Drive", intermediateDirs=True, relative=False): data = {"path":p} if osp.isfile(p): roleData = {Qt.BackgroundRole:(0, QtGui.QBrush(Qt.green))} data["roles"] = roleData yield data treeData = tuple(iterTreeData()) treeWdg.createTree(treeData, rootPath="C:/Users/styx/Google Drive")
def launch(rootDirList, update=False, dryRun=True, project="", dialogParent=None): global TREE_ITEM_DCT TREE_ITEM_DCT = {} app = qtGuiApp() if not app: app = QtGui.QApplication(sys.argv) proj = initProject(project) dlg = QuickTreeDialog(dialogParent) treeWdg = dlg.treeWidget treeWdg.setHeaderLabels(("Entity Name", "Infos")) missingPathItems = listMissingPathItems(rootDirList, update=update) badEntityList = [] treeDataList = [] for damEntity, sMissingPaths in missingPathItems: if isinstance(damEntity, basestring): p = pathJoin("Errors", damEntity) badEntityList.append({"path":p, "texts":[damEntity, sMissingPaths], "flags":Qt.ItemIsEnabled, "roles":{Qt.ForegroundRole:(1, QtGui.QBrush(Qt.red))} }) continue drcLib = proj.getLibrary("public", damEntity.libraryName) sLibPath = drcLib.absPath() sEntityTitle = damEntity.sgEntityType + 's' sEntityPath = damEntity.getPath("public") sEntiTreePath = re.sub("^" + sLibPath, sEntityTitle, sEntityPath) roleData = {Qt.UserRole:(0, damEntity)} treeDataList.append({"path":sEntiTreePath, "flags":None, "roles":roleData}) sTreePathList = tuple(re.sub("^" + sLibPath, sEntityTitle, p) for p in sMissingPaths) tree = OrderedTree.fromPaths(sTreePathList) for sTreePath in tree.iterPaths(rootPath=sEntiTreePath): treeDataList.append({"path":sTreePath, "flags":Qt.NoItemFlags}) treeWdg.createTree(badEntityList) treeWdg.defaultFlags |= Qt.ItemIsTristate treeWdg.defaultRoles = {Qt.CheckStateRole:(0, Qt.Unchecked)} treeWdg.createTree(treeDataList) topItemCount = treeWdg.topLevelItemCount() if topItemCount == 1: curItem = treeWdg.topLevelItem(0) treeWdg.setRootIndex(treeWdg.indexFromItem(curItem)) while curItem.childCount() == 1: curItem = curItem.child(0) curItem.setExpanded(True) else: for i in xrange(topItemCount): treeWdg.topLevelItem(i).setExpanded(True) dlg.show() while True: bOk = dlg.exec_() if not bOk: return bApply = False flags = (QTreeWidgetItemIterator.Checked | QTreeWidgetItemIterator.Enabled) treeIter = QTreeWidgetItemIterator(treeWdg, flags) damEntities = tuple(it.value().data(0, Qt.UserRole) for it in treeIter) damAssets = tuple(e for e in damEntities if isinstance(e, DamAsset)) damShots = tuple(e for e in damEntities if isinstance(e, DamShot)) if damAssets or damShots: sMsg = "Create directories and files for:\n" if damAssets: sMsg += "\n - {} Assets".format(len(damAssets)) if damShots: sMsg += "\n - {} Shots".format(len(damShots)) sConfirm = confirmDialog(title="WARNING !", message=sMsg, button=("Yes", "No"), defaultButton="No", cancelButton="No", dismissString="No", icon="warning", ) if sConfirm == "Yes": bApply = True break if bApply: entityDirList = len(damEntities) * [None] for i, damEntity in enumerate(damEntities): if not damEntity: continue damEntity.createDirsAndFiles(dryRun=dryRun, checkDb=False) entityDirList[i] = damEntity.getResource("public", "entity_dir") for drcDir in entityDirList: if drcDir: drcDir.setSyncRules(drcDir.syncRules)
def launch_old(entityType="", dryRun=True, project="", dialogParent=None): global TREE_ITEM_DCT TREE_ITEM_DCT = {} app = qtGuiApp() if not app: app = QtGui.QApplication(sys.argv) sProject = os.environ["DAVOS_INIT_PROJECT"] if not project else project proj = DamProject(sProject) print sProject.center(80, "-") dlg = QuickTreeDialog(dialogParent) treeWdg = dlg.treeWidget treeWdg.setHeaderLabels(("Entity Name", "Infos")) dlg.show() missingPathItems = listMissingPathItems(proj, entityType) badEntityItems = [] for damEntity, sMissingPaths in missingPathItems: if isinstance(damEntity, basestring): badEntityItems.append((damEntity, sMissingPaths)) continue drcLib = proj.getLibrary("public", damEntity.libraryName) sLibPath = drcLib.absPath() sEntityTitle = damEntity.sgEntityType + 's' sEntityPath = damEntity.getPath("public") sEntityPath = re.sub("^" + sLibPath, sEntityTitle, sEntityPath) sEntityPathDirs = pathSplitDirs(sEntityPath) for sAbsPath in sMissingPaths: sTreePath = re.sub("^" + sLibPath, sEntityTitle, sAbsPath) sParentPath, sFilename = osp.split(pathNorm(sTreePath)) parentItem = TREE_ITEM_DCT.get(sParentPath) if not parentItem: sDirList = pathSplitDirs(sParentPath) curParentItem = treeWdg for i, sDirName in enumerate(sDirList): if i == 0: sItemPath = sDirName else: sItemPath = pathJoin(*sDirList[:i + 1]) item = TREE_ITEM_DCT.get(sItemPath) if not item: flags = None if sItemPath.startswith(sEntityPath): if len(pathSplitDirs(sItemPath)) > len(sEntityPathDirs): flags = Qt.NoItemFlags userData = None if sItemPath == sEntityPath: userData = damEntity item = loadTreeItem(curParentItem, sItemPath, [sDirName], flags=flags, userData=userData) curParentItem = item parentItem = curParentItem flags = None if sTreePath.startswith(sEntityPath): if len(pathSplitDirs(sTreePath)) > len(sEntityPathDirs): flags = Qt.NoItemFlags userData = None if sTreePath == sEntityPath: userData = damEntity loadTreeItem(parentItem, sTreePath, [sFilename], flags=flags, userData=userData) if badEntityItems: errorsItem = loadTreeItem(None, "Errors", ["ERRORS"]) treeWdg.insertTopLevelItem(0, errorsItem) for sEntityName, sError in badEntityItems: loadTreeItem(errorsItem, sEntityName, [sEntityName, sError], checkable=False) for i in xrange(treeWdg.topLevelItemCount()): treeWdg.topLevelItem(i).setExpanded(True) while True: bOk = dlg.exec_() if not bOk: return bApply = False flags = (QTreeWidgetItemIterator.Checked | QTreeWidgetItemIterator.Enabled) treeIter = QTreeWidgetItemIterator(treeWdg, flags) damEntities = tuple(it.value().data(0, Qt.UserRole) for it in treeIter) damAssets = tuple(e for e in damEntities if isinstance(e, DamAsset)) damShots = tuple(e for e in damEntities if isinstance(e, DamShot)) if damAssets or damShots: sMsg = "Create directories and files for:\n" if damAssets: sMsg += "\n - {} Assets".format(len(damAssets)) if damShots: sMsg += "\n - {} Shots".format(len(damShots)) sConfirm = confirmDialog(title="WARNING !", message=sMsg, button=("Yes", "No"), defaultButton="No", cancelButton="No", dismissString="No", icon="warning", ) if sConfirm == "Yes": bApply = True break if bApply: for damEntity in damEntities: if not damEntity: continue damEntity.createDirsAndFiles(dryRun=dryRun)