예제 #1
0
 def refTest(ref=('StringPin', "", {
     "inputWidgetVariant": "ObjectPathWIdget"
 })):
     """Path test"""
     entity = PathsRegistry().getEntity(ref)
     try:
         entity.call()
     except:
         pass
예제 #2
0
    def computeHull(self):

        loopEndNodePath = self.getPinSG("Paired block").getData()
        loopEndNode = PathsRegistry().getEntity(loopEndNodePath)

        if loopEndNode is None:
            self.poly = QtGui.QPainterPath()
            return
        if self.isUnderCollapsedComment():
            p = [self.getTopMostOwningCollapsedComment()]
        else:
            p = [self]
        if loopEndNode.__class__.__name__ == "loopEnd" and loopEndNode.getWrapper(
        ) is not None:
            uiLoopEnd = loopEndNode.getWrapper()
            if loopEndNode.isUnderActiveGraph():
                if uiLoopEnd.isUnderCollapsedComment():
                    p.append(uiLoopEnd.getTopMostOwningCollapsedComment())
                else:
                    p.append(uiLoopEnd)

        else:
            self.poly = QtGui.QPainterPath()
            return

        p += self.getBetwenLoopNodes(self)

        path = []
        self.left = 0
        self.top = 0
        self.right = 0
        self.down = 0
        for i in p:
            relPos = i.scenePos()
            self.left = min(self.left, relPos.x())
            self.top = max(self.top, relPos.y())
            self.right = max(self.right, relPos.x())
            self.down = min(self.down, relPos.y())
            relSize = QtCore.QPointF(i.getNodeWidth(), i.geometry().height())
            path.append((relPos.x() - 5, relPos.y() - 5))
            path.append((relPos.x() + relSize.x() + 5, relPos.y() - 5))
            path.append(
                (relPos.x() + relSize.x() + 5, relPos.y() + relSize.y() + 5))
            path.append((relPos.x() - 5, relPos.y() + relSize.y() + 5))

        if len(path) >= 3:
            self.convex_hull = convex_hull(path)
            path = []
            for i in self.convex_hull:
                path.append(QtCore.QPointF(i[0], i[1]))
            self.poly = ConnectionPainter.roundCornersPath(path, 6, True)
예제 #3
0
    def loadFromData(self, data, clearHistory=False):

        # check first if all packages we are trying to load are legal
        missedPackages = set()
        if not validateGraphDataPackages(data, missedPackages):
            msg = "This graph can not be loaded. Following packages not found:\n\n"
            index = 1
            for missedPackageName in missedPackages:
                msg += "{0}. {1}\n".format(index, missedPackageName)
                index += 1
            QMessageBox.critical(self, "Missing dependencies", msg)
            return

        if clearHistory:
            EditorHistory().clear()
            historyTools = self.getRegisteredTools(
                classNameFilters=["HistoryTool"])
            for historyTools in historyTools:
                historyTools.onClear()

        self.newFile(keepRoot=False)
        # load raw data
        self.graphManager.get().deserialize(data)
        self.fileBeenLoaded.emit()
        self.graphManager.get().selectGraphByName(data["activeGraph"])
        self.updateLabel()
        PathsRegistry().rebuild()
예제 #4
0
    def compute(self, *args, **kwargs):
        endNodePath = self.loopEndNode.getData()
        loopEndNode = PathsRegistry().getEntity(endNodePath)
        if loopEndNode is not None:
            if loopEndNode.loopBeginNode.getData() != self.path():
                self.setError("Invalid pair")
                return
            if self.graph() is not loopEndNode.graph():
                err = "block ends in different graphs"
                self.setError(err)
                loopEndNode.setError(err)
                return
        else:
            self.setError("Pair {} not found".format(endNodePath))
            return

        self.onNext(*args, **kwargs)
예제 #5
0
 def onNext(self, *args, **kwargs):
     currentCondition = self.condition.getData()
     if currentCondition:
         self.loopBody.call(*args, **kwargs)
     if self.lastCondition is True and currentCondition is False:
         endNodePath = self.loopEndNode.getData()
         loopEndNode = PathsRegistry().getEntity(endNodePath)
         loopEndNode.completed.call()
         self.lastCondition = False
         return
     self.lastCondition = currentCondition
 def compute(self, *args, **kwargs):
     self.reset()
     endNodePath = self.loopEndNode.getData()
     loopEndNode = PathsRegistry().getEntity(endNodePath)
     if loopEndNode is not None:
         if loopEndNode.loopBeginNode.getData() != self.path():
             self.setError("Invalid pair")
             return
         if self.graph() is not loopEndNode.graph():
             err = "block ends in different graphs"
             self.setError(err)
             loopEndNode.setError(err)
             return
     else:
         self.setError("{} not found".format(endNodePath))
     if not self._working:
         self.thread = threading.Thread(target=self.onNext,
                                        args=(self, args, kwargs))
         self.thread.start()
         self._working = True
예제 #7
0
    def kill(self, *args, **kwargs):
        from PyFlow.Core.PathsRegistry import PathsRegistry

        if self.uid not in self.graph().getNodes():
            return

        self.killed.send()

        for pin in self.inputs.values():
            pin.kill()
        for pin in self.outputs.values():
            pin.kill()
        self.graph().getNodes().pop(self.uid)

        PathsRegistry().rebuild()
 def compute(self, *args, **kwargs):
     node = PathsRegistry().getEntity(self.loopBeginNode.getData())
     if node is not None:
         if node.graph() == self.graph():
             if node.loopEndNode.getData() != self.path():
                 self.setError("Invalid pair")
                 return
             if node.__class__.__name__ == "forLoopBegin":
                 node.prevIndex = node.currentIndex
                 node.currentIndex += 1
                 if node.currentIndex >= node.lastIndex.getData():
                     self.completed.call()
             else:
                 node.onNext()
         else:
             err = "block ends in different graphs"
             node.setError(err)
             self.setError(err)
     else:
         self.setError("Pair {} not found".format(self.loopBeginNode.getData()))
예제 #9
0
    def addNode(self, node, jsonTemplate=None):
        """Adds node to storage

        :param node: Node to add
        :type node: NodeBase
        :param jsonTemplate: serialized representation of node. This used when graph deserialized to do custom stuff after node will be added.
        :type jsonTemplate: dict
        :rtype: bool
        """
        from PyFlow.Core.PathsRegistry import PathsRegistry

        assert (node is not None), "failed to add node, None is passed"
        if node.uid in self._nodes:
            return False

        # Check if this node is variable get/set.
        # Variables created in child graphs are not visible to parent ones
        # Do not disrupt variable scope.
        if node.__class__.__name__ in ['getVar', 'setVar']:
            var = self.graphManager.findVariableByUid(node.variableUid())
            variableLocation = var.location()
            if len(variableLocation) > len(self.location()):
                return False
            if len(variableLocation) == len(self.location()):
                if Counter(variableLocation) != Counter(self.location()):
                    return False

        node.graph = weakref.ref(self)
        if jsonTemplate is not None:
            jsonTemplate['name'] = self.graphManager.getUniqNodeName(
                jsonTemplate['name'])
        else:
            node.setName(self.graphManager.getUniqNodeName(node.name))

        self._nodes[node.uid] = node
        node.postCreate(jsonTemplate)
        PathsRegistry().rebuild()
        return True
예제 #10
0
 def __init__(self, parent=None, **kwds):
     super(ObjectPathWIdget, self).__init__(parent=parent, **kwds)
     values = []
     self.enumBox = EnumComboBox(PathsRegistry().getAllPaths())
     self.setWidget(self.enumBox)
     self.enumBox.changeCallback.connect(self.dataSetCallback)