def test_children(self): num = 9 p = nodes.Node('parent') ns = [] for i in range(num): n = nodes.Node('node'+str(i), parent=p) ns.append(n) self.assertEqual(p.childCount(), num) children = p.children() self.assertEquals(children, ns)
def test_insertChild(self): n1 = nodes.Node('node1') n2 = nodes.Node('node2') r = n1.insertChild(0, n2) self.assertTrue(r) self.assertEqual(n1.childCount(), 1) self.assertEquals(n1.child(0), n2) r = n1.insertChild(2, n2) self.assertFalse(r)
def test_allTags(self): # Tests parentTags, childrenTags, allTags and allTagsStr. n0 = nodes.Node('parent') n1 = nodes.Node('node1', parent=n0) n2 = nodes.Node('node2', parent=n1) n3 = nodes.Node('node3', parent=n2) n4 = nodes.Node('node4', parent=n3) n5 = nodes.Node('node5', parent=n4) n11 = nodes.Node('node11', parent=n0) n12 = nodes.Node('node12', parent=n11) n13 = nodes.Node('node13', parent=n12) tags0 = ['parent', 'node1', 'node2', 'node3', 'node4', 'node5', 'node11', 'node12', 'node13'] tags1 = ['node1', 'parent', 'node2', 'node3', 'node4', 'node5'] tags2 = ['node2', 'node1', 'parent', 'node3', 'node4', 'node5'] tags3 = ['node3', 'node2', 'node1', 'parent', 'node4', 'node5'] tags4 = ['node4', 'node3', 'node2', 'node1', 'parent', 'node5'] tags5 = ['node5', 'node4', 'node3', 'node2', 'node1', 'parent'] tags11 = ['node11', 'parent', 'node12', 'node13'] self.assertEqual(n0.allTags(), tags0) self.assertEqual(n1.allTags(), tags1) self.assertEqual(n2.allTags(), tags2) self.assertEqual(n3.allTags(), tags3) self.assertEqual(n4.allTags(), tags4) self.assertEqual(n5.allTags(), tags5) self.assertEqual(n11.allTags(), tags11) value = 'parent|node1|node2|node3|node4|node5|node11|node12|node13' self.assertEqual(n0.allTagsStr(), value)
def test_removeChild(self): n1 = nodes.Node('node1') n2 = nodes.Node('node2', parent=n1) self.assertEqual(n1.childCount(), 1) r = n1.removeChild(99) self.assertFalse(r) r = n1.removeChild(0) self.assertTrue(r) self.assertEqual(n1.childCount(), 0)
def test_child(self): num = 9 p = nodes.Node('parent') ns = [] for i in range(num): n = nodes.Node('node'+str(i), parent=p) ns.append(n) self.assertEqual(p.childCount(), num) for i in range(p.childCount()): c = p.child(i) n = ns[i] self.assertEquals(n, c)
def test_setEnabled(self): newEnabled = False n = nodes.Node('name') self.assertTrue(isinstance(n.enabled(), bool)) n.setEnabled(newEnabled) self.assertEqual(n.enabled(), newEnabled) self.assertTrue(isinstance(n.enabled(), bool))
def test_setNeverHasChildren(self): newNeverHasChildren = True n = nodes.Node('name') self.assertTrue(isinstance(n.neverHasChildren(), bool)) n.setNeverHasChildren(newNeverHasChildren) self.assertEqual(n.neverHasChildren(), newNeverHasChildren) self.assertTrue(isinstance(n.neverHasChildren(), bool))
def test_setCheckable(self): newCheckable = True n = nodes.Node('name') self.assertTrue(isinstance(n.checkable(), bool)) n.setCheckable(newCheckable) self.assertEqual(n.checkable(), newCheckable) self.assertTrue(isinstance(n.checkable(), bool))
def test_setSelectable(self): newSelectable = False n = nodes.Node('name') self.assertTrue(isinstance(n.selectable(), bool)) n.setSelectable(newSelectable) self.assertEqual(n.selectable(), newSelectable) self.assertTrue(isinstance(n.selectable(), bool))
def test_row(self): p = nodes.Node('parent') n1 = nodes.Node('node1', parent=p) n2 = nodes.Node('node2', parent=p) n3 = nodes.Node('node3', parent=p) n4 = nodes.Node('node4', parent=p) self.assertEqual(p.childCount(), 4) row1 = n1.row() row2 = n2.row() row3 = n3.row() row4 = n4.row() self.assertEqual(row1, 0) self.assertEqual(row2, 1) self.assertEqual(row3, 2) self.assertEqual(row4, 3) self.assertEqual(p.row(), 0)
def test_setData(self): data = {'key': 'value'} newData = {'new key': 'new value'} n = nodes.Node('name', data=data) self.assertEqual(n.data(), data) self.assertTrue(isinstance(n.data(), dict)) n.setData(newData) self.assertEqual(n.data(), newData) self.assertTrue(isinstance(n.data(), dict))
def test_setStatusTip(self): statusTip = 'my statusTip' newStatusTip = 'the new statusTip' n = nodes.Node('name', statusTip=statusTip) self.assertEqual(n.statusTip(), statusTip) self.assertTrue(isinstance(n.statusTip(), str)) n.setStatusTip(newStatusTip) self.assertEqual(n.statusTip(), newStatusTip) self.assertTrue(isinstance(n.statusTip(), str))
def test_setTooltip(self): toolTip = 'my tooltip' newToolTip = 'the new tooltip' n = nodes.Node('name', toolTip=toolTip) self.assertEqual(n.toolTip(), toolTip) self.assertTrue(isinstance(n.toolTip(), str)) n.setToolTip(newToolTip) self.assertEqual(n.toolTip(), newToolTip) self.assertTrue(isinstance(n.toolTip(), str))
def test_setName(self): name = 'myNode' newName = 'newNodeName' n = nodes.Node(name) self.assertEqual(n.name(), name) self.assertTrue(isinstance(n.name(), str)) n.setName(newName) self.assertEqual(n.name(), newName) self.assertTrue(isinstance(n.name(), str))
def getFileNodes(self): path = self.getDataValue('path') # Example data rootNode = nodes.Node('root', data=path) # Matchmove data = {'department': 'matchmove'} matchmoveDept = DeptNode('matchmove', parent=rootNode, data=data) data['task'] = 'camera' camTask = TaskNode('camera', parent=matchmoveDept, data=data) data['name'] = 'bg01' camBg1Name = FileNameNode('bg01', parent=camTask, data=data) data['name'] = 'bg02' camBg2Name = FileNameNode('bg02', parent=camTask, data=data) data['name'] = 'bg03' camBg3Name = FileNameNode('bg03', parent=camTask, data=data) data['name'] = 'bg04' camBg4Name = FileNameNode('bg04', parent=camTask, data=data) data['name'] = 'bg05' camBg5Name = FileNameNode('bg05', parent=camTask, data=data) data['task'] = 'matchmove' mmTask = TaskNode('matchmove', parent=matchmoveDept, data=data) data['name'] = 'john' matchmoveName = FileNameNode('john', parent=mmTask, data=data) # Layout data = {'department': 'layout'} layoutDept = DeptNode('layout', parent=rootNode, data=data) data['task'] = 'layout' layoutTask = TaskNode('layout', parent=layoutDept, data=data) data['name'] = 'camera' cameraName = FileNameNode('camera', parent=layoutTask, data=data) data['name'] = 'environment' envName = FileNameNode('environment', parent=layoutTask, data=data) data['name'] = 'layout' layoutName = FileNameNode('layout', parent=layoutTask, data=data) # Animation data = {'department': 'animation'} animDept = DeptNode('animation', parent=rootNode, data=data) data.update(task='anim') animTask = TaskNode('anim', parent=animDept, data=data) data.update(name='animation') animationName = FileNameNode('animation', parent=animTask, data=data) # Lighting data = {'department': 'light'} lightDept = DeptNode('light', parent=rootNode, data=data) data.update(task='light') lightTask = TaskNode('light', parent=lightDept, data=data) data.update(name='light') lightName = FileNameNode('light', parent=lightTask, data=data) # Effects data = {'department': 'effects'} effectsDept = DeptNode('effects', parent=rootNode) data = {'department': 'effects', 'task': 'destruction'} destTask = TaskNode('destruction', parent=effectsDept, data=data) data.update(name='fx') fxName = FileNameNode('fx', parent=destTask, data=data) data = {'department': 'effects', 'task': 'water'} waterTask = TaskNode('water', parent=effectsDept, data=data) data.update(name='fx') fxName = FileNameNode('fx', parent=waterTask, data=data) data = {'department': 'effects', 'task': 'fire'} fireTask = TaskNode('fire', parent=effectsDept, data=data) data.update(name='fx') fxName = FileNameNode('fx', parent=fireTask, data=data) # Model data = {'department': 'model'} modelDept = DeptNode('model', parent=rootNode, data=data) data.update(task='model') modelTask = TaskNode('model', parent=modelDept, data=data) data.update(task='sculpt') sculptTask = TaskNode('sculpt', parent=modelDept, data=data) data.update(task='proxy') proxyTask = TaskNode('proxy', parent=modelDept, data=data) data.update(name='model') modelName = FileNameNode('model', parent=modelTask, data=data) data.update(name='sculpt') sculptName = FileNameNode('sculpt', parent=sculptTask, data=data) data.update(name='model') proxyName = FileNameNode('model', parent=proxyTask, data=data) # Rig data = {'department': 'rig'} rigDept = DeptNode('rig', parent=rootNode, data=data) data.update(task='rig') rigTask = TaskNode('rig', parent=rigDept, data=data) data.update(name='john') johnName = FileNameNode('john', parent=rigTask, data=data) # Lookdev data = {'department': 'lookdev'} lookdevDept = DeptNode('lookdev', parent=rootNode, data=data) data.update(task='texture') textureTask = TaskNode('texture', parent=lookdevDept, data=data) data.update(task='shader') shaderTask = TaskNode('shader', parent=lookdevDept, data=data) data.update(name='texture') textureName = FileNameNode('texture', parent=textureTask, data=data) data.update(name='shader') shaderName = FileNameNode('shader', parent=shaderTask, data=data) # Pipeline data = {'department': 'pipeline'} pipelineDept = DeptNode('pipeline', parent=rootNode, data=data) data.update(task='pipeline') pipelineTask = TaskNode('pipeline', parent=pipelineDept, data=data) data.update(name='pipeline') pipelineName = FileNameNode('pipeline', parent=pipelineTask, data=data) return rootNode
def __init__(self, parent, withFileFormatFilter=True, fileFormatFilterTagName=None, fileFormatFilterNodeType=None, pathFormat=None): super(VersionSelector, self).__init__() self.setupUi(self) self.parent = parent self.font = uiUtils.getFont('monospace') self._data = {} self._path = '' self.__internalRemap = {} self._pathFormat = pathFormat if pathFormat is None: self._pathFormat = '/projects/{project}/{sequence}/{shot}/{department}/{task}/{name}_{major}.{minor}.{ext}' # File Format Filter self.fileFormatModel = None self._fileFormatFilterTagName = None self._fileFormatFilterNodeType = None if withFileFormatFilter is True: filterData = self.__getFileFormatNames() self.fileFormatModel = QtCore.QStringListModel(filterData) self.fileFormatComboBox.setModel(self.fileFormatModel) if fileFormatFilterTagName is not None: if isinstance(fileFormatFilterTagName, str): self._fileFormatFilterTagName = fileFormatFilterTagName else: raise ValueError if fileFormatFilterNodeType is not None: if isinstance(fileFormatFilterNodeType, str): self._fileFormatFilterNodeType = fileFormatFilterNodeType else: raise ValueError else: self.fileFormatLabel.hide() self.fileFormatComboBox.hide() rootNode = nodes.Node('root', data=self._path) self.versionModel = VersionModel(rootNode, font=self.font) self.versionFilterModel = qtLearn.uiModels.SortFilterProxyModel() self.versionFilterModel.setSourceModel(self.versionModel) self.versionFilterModel.setDynamicSortFilter(True) self.versionFilterModel.setFilterCaseSensitivity( QtCore.Qt.CaseInsensitive) self.versionFilterModel.setFilterTagName(self._fileFormatFilterTagName) self.versionFilterModel.setFilterTagNodeType( self._fileFormatFilterNodeType) self.treeView.setModel(self.versionFilterModel) self.treeView.setSortingEnabled(True) self.treeView.sortByColumn(0, QtCore.Qt.DescendingOrder) self.treeView.expandAll() self.selectionModel = self.treeView.selectionModel() self.selectionModel.currentChanged.connect(self.slotCurrentChanged) self.fileFormatComboBox.currentIndexChanged.connect( self.slotFileFormatFilterChanged)
def getVersionNodes(self): # TODO: Use 'path' to look up versions rather than hard-coding test data. tags = self.data() pth = paths.Path(tags, format=self._pathFormat) path = pth.getPath() # print('VersionSelector getVersionNodes path:', path) rootNode = self.__internalRemap.get(path) if rootNode is not None: return rootNode exts = ['mb', 'ma'] versions_1 = [ ('v001.001', 'john', 'description', random.choice(exts)), ('v002.001', 'davidc', 'description', random.choice(exts)), ('v002.002', 'davidc', 'description', random.choice(exts)), ('v002.003', 'davidc', 'description', random.choice(exts)), ('v002.004', 'john', 'description', random.choice(exts)), ('v003.001', 'bob', 'description', random.choice(exts)), ] versions_2 = [ ('v001.001', 'davidc', 'description', random.choice(exts)), ] versions_3 = [ ('v001.001', 'davidc', 'description', random.choice(exts)), ('v002.001', 'davidc', 'description', random.choice(exts)), ('v003.001', 'davidc', 'description', random.choice(exts)), ('v004.001', 'davidc', 'description', random.choice(exts)), ('v005.001', 'davidc', 'description', random.choice(exts)), ('v006.001', 'davidc', 'description', random.choice(exts)), ('v007.001', 'davidc', 'description', random.choice(exts)), ('v008.001', 'davidc', 'description', random.choice(exts)), ('v009.001', 'davidc', 'description', random.choice(exts)), ('v010.001', 'davidc', 'description', random.choice(exts)), ('v011.001', 'davidc', 'description', random.choice(exts)), ('v012.001', 'john', 'description', random.choice(exts)), ] versions_4 = [ ('v001.001', 'bob', 'description', random.choice(exts)), ('v001.002', 'bob', 'description', random.choice(exts)), ('v001.003', 'bob', 'description', random.choice(exts)), ('v001.004', 'bob', 'description', random.choice(exts)), ('v001.005', 'bob', 'description', random.choice(exts)), ('v001.006', 'bob', 'description', random.choice(exts)), ('v001.007', 'bob', 'description', random.choice(exts)), ('v001.008', 'bob', 'description', random.choice(exts)), ('v001.009', 'bob', 'description', random.choice(exts)), ('v001.010', 'bob', 'description', random.choice(exts)), ('v002.001', 'davidc', 'description', random.choice(exts)), ('v002.002', 'davidc', 'description', random.choice(exts)), ('v002.003', 'davidc', 'description', random.choice(exts)), ('v002.004', 'davidc', 'description', random.choice(exts)), ('v002.005', 'davidc', 'description', random.choice(exts)), ('v002.006', 'davidc', 'description', random.choice(exts)), ('v002.007', 'davidc', 'description', random.choice(exts)), ('v002.008', 'davidc', 'description', random.choice(exts)), ('v002.009', 'davidc', 'description', random.choice(exts)), ('v002.010', 'davidc', 'description', random.choice(exts)), ('v002.011', 'davidc', 'description', random.choice(exts)), ('v002.012', 'davidc', 'description', random.choice(exts)), ] versions = [versions_1, versions_2, versions_3, versions_4] versions = random.choice(versions) major_versions = {} minor_versions = {} rootNode = nodes.Node('ROOT') for version in versions: ver = version[0] split = str(ver).split('.') major_ver = split[0] minor_ver = split[1] user = version[1] desc = version[2] file_ext = version[3] data = { 'major': major_ver, 'minor': minor_ver, 'version': ver, 'user': user, 'description': desc, 'ext': file_ext, } # Create Major Version if major_ver in major_versions: majorNode = major_versions[major_ver] else: majorNode = MajorVersionNode(major_ver, parent=rootNode, data=data) # Create Minor Version if ver in minor_versions: minorNode = minor_versions[major_ver] else: minorNode = MinorVersionNode(minor_ver, user, desc, parent=majorNode, data=data) major_versions[major_ver] = majorNode minor_versions[ver] = minorNode self.__internalRemap[path] = rootNode return rootNode
def test_init(self): name = 'myNode' n = nodes.Node(name) self.assertEqual(n.name(), name) data = {'cool': 'stuff'} n = nodes.Node(name, data=data) self.assertEqual(n.data(), data) n = nodes.Node(name, data=None) self.assertEqual(n.data(), {}) tooltip = 'tooltip' n = nodes.Node(name, data=data, toolTip=tooltip) self.assertEqual(n.toolTip(), tooltip) statusTip = 'status line text' n = nodes.Node(name, data=data, toolTip=tooltip, statusTip=statusTip) self.assertEqual(n.statusTip(), statusTip) parent = nodes.Node('root') n1 = nodes.Node(name+'1', parent=parent) n2 = nodes.Node(name+'2', parent=parent) n3 = nodes.Node(name+'3', parent=parent) self.assertEquals(n1.parent(), parent) self.assertEquals(n2.parent(), parent) self.assertEquals(n3.parent(), parent) self.assertEqual(parent.childCount(), 3) n1 = nodes.Node(name, enabled=True) n2 = nodes.Node(name, enabled=False) n3 = nodes.Node(name) self.assertEqual(n1.enabled(), True) self.assertEqual(n2.enabled(), False) self.assertEqual(n3.enabled(), True) n1 = nodes.Node(name, editable=True) n2 = nodes.Node(name, editable=False) n3 = nodes.Node(name) self.assertEqual(n1.editable(), True) self.assertEqual(n2.editable(), False) self.assertEqual(n3.editable(), False) n1 = nodes.Node(name, selectable=True) n2 = nodes.Node(name, selectable=False) n3 = nodes.Node(name) self.assertEqual(n1.selectable(), True) self.assertEqual(n2.selectable(), False) self.assertEqual(n3.selectable(), True) n1 = nodes.Node(name, checkable=True) n2 = nodes.Node(name, checkable=False) n3 = nodes.Node(name) self.assertEqual(n1.checkable(), True) self.assertEqual(n2.checkable(), False) self.assertEqual(n3.checkable(), False) n1 = nodes.Node(name, neverHasChildren=True) n2 = nodes.Node(name, neverHasChildren=False) n3 = nodes.Node(name) self.assertEqual(n1.neverHasChildren(), True) self.assertEqual(n2.neverHasChildren(), False) self.assertEqual(n3.neverHasChildren(), False)