Пример #1
0
    def test_create_step(self):
        blueprintModel = pulse.views.BlueprintUIModel.getDefaultModel()
        bp = blueprintModel.blueprint

        result = cmds.pulseCreateStep("", 0, "{'name':'StepA'}")
        self.assertEqual(result, ['StepA'])

        result = cmds.pulseCreateStep("", 0, "{'name':'StepB'}")
        self.assertEqual(result, ['StepB'])

        result = cmds.pulseCreateStep("", 0, "")
        self.assertEqual(result, ['New Step'])

        self.assertTrue(bp.rootStep.numChildren() == 3)
        cmds.undo()
        self.assertTrue(bp.rootStep.numChildren() == 2)

        cmds.pulseDeleteStep('StepA')
        self.assertTrue(bp.rootStep.numChildren() == 1)
        cmds.undo()
        self.assertTrue(bp.rootStep.numChildren() == 2)

        cmds.pulseMoveStep('StepB', 'StepA/StepBX')
        stepB = bp.getStepByPath('StepA/StepBX')
        self.assertIsNotNone(stepB)

        cmds.undo()
        stepA = bp.getStepByPath('StepA')
        stepB = bp.getStepByPath('StepB')
        self.assertIsNotNone(stepB)
        self.assertTrue(stepA.numChildren() == 0)

        cmds.pulseMoveStep('StepB', 'StepBY')
        stepB = bp.getStepByPath('StepBY')
        self.assertIsNotNone(stepB)

        cmds.undo()
        cmds.redo()
        stepB = bp.getStepByPath('StepBY')
        self.assertIsNotNone(stepB)

        cmds.pulseMoveStep('StepBY', 'StepA/StepBY')
        cmds.pulseRenameStep('StepA/StepBY', 'StepBZ')
        stepB = bp.getStepByPath('StepA/StepBZ')
        self.assertIsNotNone(stepB)
Пример #2
0
 def getOrCreatePairedStep(self, sourceStep):
     """
     Return the BuildStep that is paired with a step,
     creating a new BuildStep if necessary.
     """
     destStepPath = self.getMirroredStepPath(sourceStep)
     if destStepPath:
         destStep = self.blueprintModel.getStep(destStepPath)
         if not destStep:
             childIndex = sourceStep.indexInParent() + 1
             newStepData = sourceStep.serialize()
             newStepData['name'] = self.getMirroredStepName(sourceStep.name)
             dataStr = serializeAttrValue(newStepData)
             cmds.pulseCreateStep(sourceStep.getParentPath(), childIndex,
                                  dataStr)
             return self.blueprintModel.getStep(destStepPath)
         else:
             return destStep
Пример #3
0
    def dropMimeData(self, data, action, row, column, parentIndex):
        if not self.canDropMimeData(data, action, row, column, parentIndex):
            return False

        if action == QtCore.Qt.IgnoreAction:
            return True

        step_data = self.getStepDataListFromMimeData(data)
        if step_data is None:
            # TODO: log error here, even though we shouldn't in canDropMimeData
            return False

        print('dropData', step_data, data, action, row, column, parentIndex)

        beginRow = 0
        parentPath = None

        if parentIndex.isValid():
            parentStep = self.stepForIndex(parentIndex)
            if parentStep:
                if parentStep.canHaveChildren:
                    # drop into step group
                    beginRow = parentStep.numChildren()
                    parentPath = parentStep.getFullPath()
                else:
                    # drop next to step
                    beginRow = parentIndex.row()
                    parentPath = os.path.dirname(parentStep.getFullPath())

        if not parentPath:
            parentPath = ''
            beginRow = self.rowCount(QtCore.QModelIndex())
        if row != -1:
            beginRow = row

        cmds.undoInfo(openChunk=True, chunkName='Drag Pulse Actions')
        self.isMoveActionOpen = True
        cmds.evalDeferred(self._deferredMoveUndoClose)

        count = len(step_data)
        for i in range(count):
            step_data_str = serializeAttrValue(step_data[i])
            newStepPath = cmds.pulseCreateStep(parentPath, beginRow + i,
                                               step_data_str)
            if newStepPath:
                newStepPath = newStepPath[0]

            if action == QtCore.Qt.MoveAction:
                # hacky, but because steps are removed after the new ones are created,
                # we need to rename the steps back to their original names in case they
                # were auto-renamed to avoid conflicts
                targetName = step_data[i].get('name', '')
                self.dragRenameQueue.append((newStepPath, targetName))

        # always return false, since we don't need the item view to handle removing moved items
        return True
Пример #4
0
    def dropMimeData(self, data, action, row, column, parentIndex):
        if not self.canDropMimeData(data, action, row, column, parentIndex):
            return False

        if action == QtCore.Qt.IgnoreAction:
            return True

        try:
            stepDataList = meta.decodeMetaData(str(data.data('text/plain')))
        except Exception as e:
            LOG.error(e)
            return False

        print('dropData', stepDataList, data, action, row, column, parentIndex)

        beginRow = 0
        parentPath = None

        if parentIndex.isValid():
            parentStep = self.stepForIndex(parentIndex)
            if parentStep:
                if parentStep.canHaveChildren:
                    # drop into step group
                    beginRow = parentStep.numChildren()
                    parentPath = parentStep.getFullPath()
                else:
                    # drop next to step
                    beginRow = parentIndex.row()
                    parentPath = os.path.dirname(parentStep.getFullPath())

        if not parentPath:
            parentPath = ''
            beginRow = self.rowCount(QtCore.QModelIndex())
        if row != -1:
            beginRow = row

        cmds.undoInfo(openChunk=True, chunkName='Drag Pulse Actions')
        self.isMoveActionOpen = True
        cmds.evalDeferred(self._deferredMoveUndoClose)

        # create dropped steps
        count = len(stepDataList)
        for i in range(count):
            stepDataStr = serializeAttrValue(stepDataList[i])
            newStepPath = cmds.pulseCreateStep(
                parentPath, beginRow + i, stepDataStr)
            if newStepPath:
                newStepPath = newStepPath[0]

                if action == QtCore.Qt.MoveAction:
                    # create queue of renames to perform after source
                    # steps have been removed
                    targetName = stepDataList[i].get('name', '')
                    self.dragRenameQueue.append((newStepPath, targetName))

        return True
Пример #5
0
    def createStepsForSelection(self, stepData=None):
        """
        Create new BuildSteps in the hierarchy at the
        current selection and return the new step paths.

        Args:
            stepData (str): A string representation of serialized
                BuildStep data used to create the new steps
        """
        if self.blueprintModel.isReadOnly():
            LOG.warning('cannot create steps, blueprint is read only')
            return

        LOG.debug('creating new steps at selection: %s', stepData)

        selIndexes = self.selectionModel.selectedIndexes()
        if not selIndexes:
            selIndexes = [QtCore.QModelIndex()]

        model = self.selectionModel.model()

        def getParentAndInsertIndex(index):
            step = model.stepForIndex(index)
            LOG.debug('step: %s', step)
            if step.canHaveChildren:
                LOG.debug('inserting at num children: %d', step.numChildren())
                return step, step.numChildren()
            else:
                LOG.debug('inserting at selected + 1: %d', index.row() + 1)
                return step.parent, index.row() + 1

        newPaths = []
        for index in selIndexes:
            parentStep, insertIndex = getParentAndInsertIndex(index)
            parentPath = parentStep.getFullPath() if parentStep else None
            if not parentPath:
                parentPath = ''
            if not stepData:
                stepData = ''
            newStepPath = cmds.pulseCreateStep(parentPath, insertIndex,
                                               stepData)
            if newStepPath:
                # TODO: remove this if/when plugin command only returns single string
                newStepPath = newStepPath[0]
                newPaths.append(newStepPath)
            # if self.model.insertRows(insertIndex, 1, parentIndex):
            #     newIndex = self.model.index(insertIndex, 0, parentIndex)
            #     newPaths.append(newIndex)

        return newPaths