Esempio n. 1
0
    def versionUpOutputFilenames(self, dagNodesToVersionUp):
        """
        Increment the filename version of all output filenames in a given
        list of dag nodes.
        """
        preSnap = self.dag.snapshot(
            nodeMetaDict=self.graphicsScene.nodeMetaDict(),
            connectionMetaDict=self.graphicsScene.connectionMetaDict())

        nodesAffected = list()
        for dagNode in self.selectedDagNodes():
            for output in dagNode.outputs():
                for soName in output.subOutputNames():
                    if not output.value[soName]:
                        continue
                    currentValue = output.value[soName]
                    updatedValue = depends_util.nextFilenameVersion(
                        currentValue)
                    dagNode.setOutputValue(output.name, soName, updatedValue)
                    self.dag.setNodeStale(dagNode, False)
                    nodesAffected = nodesAffected + self.dagNodeOutputChanged(
                        dagNode, dagNode.outputNamed(output.name))

        currentSnap = self.dag.snapshot(
            nodeMetaDict=self.graphicsScene.nodeMetaDict(),
            connectionMetaDict=self.graphicsScene.connectionMetaDict())
        self.undoStack.push(
            depends_undo_commands.DagAndSceneUndoCommand(
                preSnap, currentSnap, self.dag, self.graphicsScene))

        # Updates the drawNodes for each of the affected dagNodes
        self.propWidget.refresh()
        self.graphicsScene.refreshDrawNodes(nodesAffected)
Esempio n. 2
0
    def deleteNodes(self, dagNodesToDelete):
        """
        Delete an existing dag node and its edges, and make sure the QGraphicsScene cleans up as well.
        """
        nodesAffected = list()
        preSnap = self.dag.snapshot(
            nodeMetaDict=self.graphicsScene.nodeMetaDict(),
            connectionMetaDict=self.graphicsScene.connectionMetaDict())

        # Clean up the graphics scene
        # TODO: Should be a signal that tells the scene what to do
        for dagNode in dagNodesToDelete:
            drawNode = self.graphicsScene.drawNode(dagNode)
            drawEdges = drawNode.drawEdges()
            for edge in drawEdges:
                edge.sourceDrawNode().removeDrawEdge(edge)
                edge.destDrawNode().removeDrawEdge(edge)
                self.graphicsScene.removeItem(edge)
            self.graphicsScene.removeItem(drawNode)

        # Remove the nodes from the dag
        for delNode in dagNodesToDelete:
            nodesAffected = nodesAffected + self.dagNodeDisconnected(delNode)
            nodesAffected.remove(delNode)
            self.dag.removeNode(delNode)

        currentSnap = self.dag.snapshot(
            nodeMetaDict=self.graphicsScene.nodeMetaDict(),
            connectionMetaDict=self.graphicsScene.connectionMetaDict())
        self.undoStack.push(
            depends_undo_commands.DagAndSceneUndoCommand(
                preSnap, currentSnap, self.dag, self.graphicsScene))

        # Updates the drawNodes for each of the affected dagNodes
        self.graphicsScene.refreshDrawNodes(nodesAffected)
Esempio n. 3
0
    def createNode(self, nodeType, nodeLocation):
        """
        Create a new dag node with a safe name, add it to the dag, and register it with the QGraphicsScene.
        """
        preSnap = self.dag.snapshot(
            nodeMetaDict=self.graphicsScene.nodeMetaDict(),
            connectionMetaDict=self.graphicsScene.connectionMetaDict())

        newDagNode = nodeType()
        nodeName = depends_node.cleanNodeName(newDagNode.typeStr())
        nodeName = self.dag.safeNodeName(nodeName)
        newDagNode.setName(nodeName)
        self.dag.addNode(newDagNode)
        self.graphicsScene.addExistingDagNode(newDagNode, nodeLocation)

        currentSnap = self.dag.snapshot(
            nodeMetaDict=self.graphicsScene.nodeMetaDict(),
            connectionMetaDict=self.graphicsScene.connectionMetaDict())
        self.undoStack.push(
            depends_undo_commands.DagAndSceneUndoCommand(
                preSnap, currentSnap, self.dag, self.graphicsScene))

        self.clearSelection()
        drawNode = self.graphicsScene.drawNode(newDagNode)
        self.selectNode(drawNode)
Esempio n. 4
0
    def mouseMoveEvent(self, event):
        """
        Node head dragging.
        """
        if self.dragging:
            self.mouseMoved = True
            self.floatingDestinationPoint = event.scenePos()
            if self.destDrawNode():
                # Disconnect an edge from a node
                preSnap = self.scene().dag.snapshot(nodeMetaDict=self.scene().nodeMetaDict(),
                                                    connectionMetaDict=self.scene().connectionMetaDict())

                self.destDrawNode().removeDrawEdge(self)
                self.scene().nodesDisconnected.emit(self.sourceDrawNode().dagNode, self.destDrawNode().dagNode)
                self.setDestDrawNode(None)

                currentSnap = self.scene().dag.snapshot(nodeMetaDict=self.scene().nodeMetaDict(),
                                                        connectionMetaDict=self.scene().connectionMetaDict())
                self.scene().undoStack().push(
                    depends_undo_commands.DagAndSceneUndoCommand(preSnap, currentSnap, self.scene().dag, self.scene()))
            # nodes = [n for n in self.scene().items(self.floatingDestinationPoint) if type(n) in [DrawNodeInputNub, DrawNodeOutputNub]]
            # if nodes:
            # print nodes
            self.adjust()
            # TODO: Hoover-color nodes as potential targets
        QtGui.QGraphicsItem.mouseMoveEvent(self, event)
Esempio n. 5
0
    def shakeNodes(self, dagNodesToShake):
        """
        Pull a node out of the dependency chain without deleting it and without 
        losing downstream information.
        """
        nodesAffected = list()
        preSnap = self.dag.snapshot(
            nodeMetaDict=self.graphicsScene.nodeMetaDict(),
            connectionMetaDict=self.graphicsScene.connectionMetaDict())

        for dagNode in dagNodesToShake:
            inNodes = self.dag.nodeConnectionsIn(dagNode)
            outNodes = self.dag.nodeConnectionsOut(dagNode)
            drawNode = self.graphicsScene.drawNode(dagNode)

            # Connect all previous dag nodes to all next nodes & add the draw edges
            for inputDagNode in inNodes:
                inputDrawNode = self.graphicsScene.drawNode(inputDagNode)
                for outputDagNode in outNodes:
                    outputDrawNode = self.graphicsScene.drawNode(outputDagNode)
                    self.dag.connectNodes(inputDagNode, outputDagNode)
                    newDrawEdge = self.graphicsScene.addExistingConnection(
                        inputDagNode, outputDagNode)
                    newDrawEdge.horizontalConnectionOffset = self.graphicsScene.drawEdge(
                        drawNode, outputDrawNode).horizontalConnectionOffset
                    newDrawEdge.adjust()

            # Disconnect this dag node from everything
            for inputDagNode in inNodes:
                self.dag.disconnectNodes(inputDagNode, dagNode)
            for outputDagNode in outNodes:
                nodesAffected = nodesAffected + self.dagNodeDisconnected(
                    dagNode)
                self.dag.disconnectNodes(dagNode, outputDagNode)

            # Remove all draw edges
            for edge in drawNode.drawEdges():
                edge.sourceDrawNode().removeDrawEdge(edge)
                edge.destDrawNode().removeDrawEdge(edge)
                self.graphicsScene.removeItem(edge)

            # Nullify all our inputs
            for input in dagNode.inputs():
                dagNode.setInputValue(input.name, "")

        currentSnap = self.dag.snapshot(
            nodeMetaDict=self.graphicsScene.nodeMetaDict(),
            connectionMetaDict=self.graphicsScene.connectionMetaDict())
        self.undoStack.push(
            depends_undo_commands.DagAndSceneUndoCommand(
                preSnap, currentSnap, self.dag, self.graphicsScene))

        # A few refreshes
        self.propWidget.refresh()
        self.graphicsScene.refreshDrawNodes(nodesAffected)
Esempio n. 6
0
    def mouseReleaseEvent(self, event):
        """
        Dropping the connection onto a node connects it to the node and emits 
        an appropriate signal.  Dropping the connection into space deletes the
        connection.
        """
        if self.dragging and self.mouseMoved:
            self.dragging = False

            # A little weird - seems to be necessary when passing mouse control from the nub to here
            self.ungrabMouse()

            # Hits?
            nodes = [
                n for n in self.scene().items(self.floatingDestinationPoint)
                if type(n) == DrawNode
            ]
            if nodes:
                topHitNode = nodes[0]
                duplicatingConnection = self.sourceDrawNode(
                ).dagNode in self.scene().dag.nodeConnectionsIn(
                    topHitNode.dagNode)
                if topHitNode is not self.sourceDrawNode(
                ) and not duplicatingConnection:
                    # Connect an edge to a node
                    preSnap = self.scene().dag.snapshot(
                        nodeMetaDict=self.scene().nodeMetaDict(),
                        connectionMetaDict=self.scene().connectionMetaDict())

                    self.setDestDrawNode(topHitNode)
                    self.dest.addDrawEdge(self)
                    self.horizontalConnectionOffset = (
                        event.pos() - self.mapFromItem(self.dest, 0, 0)).x()
                    self.scene().nodesConnected.emit(
                        self.sourceDrawNode().dagNode,
                        self.destDrawNode().dagNode)
                    self.adjust()

                    currentSnap = self.scene().dag.snapshot(
                        nodeMetaDict=self.scene().nodeMetaDict(),
                        connectionMetaDict=self.scene().connectionMetaDict())
                    self.scene().undoStack().push(
                        depends_undo_commands.DagAndSceneUndoCommand(
                            preSnap, currentSnap,
                            self.scene().dag, self.scene()))
                    return QtGui.QGraphicsItem.mouseReleaseEvent(self, event)

            # No hits?  Delete yourself (You have no chance to win!)
            self.sourceDrawNode().removeDrawEdge(self)
            self.scene().removeItem(self)

        self.mouseMoved = False
        QtGui.QGraphicsItem.mouseReleaseEvent(self, event)
Esempio n. 7
0
    def duplicateNodes(self, dagNodesToDupe):
        """
        Create identical copies of the given dag nodes, but drop their 
        incoming and outgoing connections.
        """
        preSnap = self.dag.snapshot(
            nodeMetaDict=self.graphicsScene.nodeMetaDict(),
            connectionMetaDict=self.graphicsScene.connectionMetaDict())

        for dagNode in dagNodesToDupe:
            dupedNode = dagNode.duplicate("_Dupe")
            newLocation = self.graphicsScene.drawNode(
                dagNode).pos() + QtCore.QPointF(20, 20)
            self.dag.addNode(dupedNode)
            self.graphicsScene.addExistingDagNode(dupedNode, newLocation)

        currentSnap = self.dag.snapshot(
            nodeMetaDict=self.graphicsScene.nodeMetaDict(),
            connectionMetaDict=self.graphicsScene.connectionMetaDict())
        self.undoStack.push(
            depends_undo_commands.DagAndSceneUndoCommand(
                preSnap, currentSnap, self.dag, self.graphicsScene))
Esempio n. 8
0
    def propertyEdited(self, dagNode, propName, newValue, propertyType=None):
        """
        When the user interface edits a property of a node (meaning an attribute,
        input, or output), communicate this information to the in-flight dag
        and nodes, and handle the repercussions.
        """
        somethingChanged = False
        preSnap = self.dag.snapshot(
            nodeMetaDict=self.graphicsScene.nodeMetaDict(),
            connectionMetaDict=self.graphicsScene.connectionMetaDict())

        nodesAffected = list()
        if propName == "Name" and propertyType is depends_node.DagNodeAttribute:
            if newValue != dagNode.name:
                dagNode.setName(newValue)
                nodesAffected = nodesAffected + [dagNode]
                somethingChanged = True
        else:

            if propertyType is depends_node.DagNodeAttribute:
                if newValue != dagNode.attributeValue(propName):
                    dagNode.setAttributeValue(propName, newValue)
                    nodesAffected = nodesAffected + [dagNode]
                    somethingChanged = True

        # Undos aren't registered when the value doesn't actually change
        if somethingChanged:
            currentSnap = self.dag.snapshot(
                nodeMetaDict=self.graphicsScene.nodeMetaDict(),
                connectionMetaDict=self.graphicsScene.connectionMetaDict())
            self.undoStack.push(
                depends_undo_commands.DagAndSceneUndoCommand(
                    preSnap, currentSnap, self.dag, self.graphicsScene,
                    self.propWidget))

        # Updates the drawNodes for each of the affected dagNodes
        self.graphicsScene.refreshDrawNodes(nodesAffected)
Esempio n. 9
0
    def mouseReleaseEvent(self, event):
        """
        Dropping the connection onto a node connects it to the node and emits 
        an appropriate signal.  Dropping the connection into space deletes the
        connection.
        """
        if self.dragging and self.mouseMoved:
            self.dragging = False

            # A little weird - seems to be necessary when passing mouse control from the nub to here
            self.ungrabMouse()

            # Hits?
            nodes = [n for n in self.scene().items(self.floatingDestinationPoint) if
                     type(n) in [DrawNodeInputNub, DrawNodeOutputNub]]
            if nodes:
                topHitNode = nodes[0]

                self.destPort = topHitNode.index

                duplicatingConnection = self.sourceDrawNode().dagNode in self.scene().dag.nodeConnectionsIn(
                    topHitNode.parentItem().dagNode)
                if topHitNode is not self.sourceDrawNode() and not duplicatingConnection:
                    # Connect an edge to a node
                    preSnap = self.scene().dag.snapshot(nodeMetaDict=self.scene().nodeMetaDict(),
                                                        connectionMetaDict=self.scene().connectionMetaDict())

                    self.setDestDrawNode(topHitNode.parentItem())

                    print 'connecting:', self.sourceDrawNode().dagNode, 'port:', self.sourcePort
                    print 'to:', self.destDrawNode().dagNode, 'port:', self.destPort

                    sourcePortType = self.sourceDrawNode().dagNode.outputs()[self.sourcePort].dataType
                    destNodeType = self.destDrawNode().dagNode.inputs()[self.destPort].dataType

                    print sourcePortType, destNodeType

                    if destNodeType != 'any':
                        if sourcePortType != destNodeType:
                            print 'types dont match - bailing'
                            self.sourceDrawNode().removeDrawEdge(self)
                            self.scene().removeItem(self)
                            self.mouseMoved = False
                            QtGui.QGraphicsItem.mouseReleaseEvent(self, event)
                            return

                    self.dest.addDrawEdge(self)
                    self.horizontalConnectionOffset = 0.0
                    self.scene().nodesConnected.emit(self.sourceDrawNode().dagNode, self.destDrawNode().dagNode,
                                                     self.sourcePort, self.destPort)
                    self.adjust()

                    currentSnap = self.scene().dag.snapshot(nodeMetaDict=self.scene().nodeMetaDict(),
                                                            connectionMetaDict=self.scene().connectionMetaDict())
                    self.scene().undoStack().push(
                        depends_undo_commands.DagAndSceneUndoCommand(preSnap, currentSnap, self.scene().dag,
                                                                     self.scene()))
                    return QtGui.QGraphicsItem.mouseReleaseEvent(self, event)

            # No hits?  Delete yourself (You have no chance to win!)
            self.sourceDrawNode().removeDrawEdge(self)
            self.scene().removeItem(self)

        self.mouseMoved = False
        QtGui.QGraphicsItem.mouseReleaseEvent(self, event)