def paintEvent(self, event):
        painter = QtGui.QPainter()
        painter.begin(self)

        keyColor = QtGui.QColor.fromRgb(
            *findPinClassByType(self.parent().dataType).color())

        structure = self.parent()._rawVariable.structure
        if structure == StructureType.Single:
            painter.setRenderHint(QtGui.QPainter.Antialiasing)
            pen = QtGui.QPen()
            pen.setColor(QtGui.QColor(0, 0, 0, 0))
            painter.setPen(pen)
            rect = event.rect()
            rect.setHeight(10)
            rect.setWidth(15)
            rect.moveTop(3)
            painter.setBrush(keyColor)
            painter.drawRoundedRect(rect, 5, 5)

        if structure == StructureType.Array:
            gridSize = 3
            size = self.height()
            cellW = size / gridSize
            cellH = size / gridSize

            painter.setBrush(QtGui.QBrush(keyColor))
            painter.setPen(QtGui.QPen(QtCore.Qt.black, 0.2))
            for row in range(gridSize):
                for column in range(gridSize):
                    x = row * cellW
                    y = column * cellH
                    painter.drawRect(x, y, cellW, cellH)

        if structure == StructureType.Dict:
            dictObject = self.parent()._rawVariable.value

            keyColor = QtGui.QColor.fromRgb(
                *findPinClassByType(dictObject.keyType).color())
            valueColor = QtGui.QColor.fromRgb(
                *findPinClassByType(dictObject.valueType).color())

            gridSize = 3
            size = self.height()
            cellW = size / gridSize
            cellH = size / gridSize

            painter.setBrush(QtGui.QBrush(keyColor))
            painter.setPen(QtGui.QPen(QtCore.Qt.black, 0.2))
            for row in range(gridSize):
                painter.setBrush(keyColor)
                painter.drawRect(0, row * cellH, cellW, cellH)
                painter.setBrush(valueColor)
                painter.drawRect(cellW, row * cellH, cellW * 2, cellH)

        painter.end()
Exemple #2
0
    def setType(self, dataType):
        if not self.changeTypeOnConnection:
            return False

        if self.activeDataType != self.__class__.__name__ and self.singleInit:
            # Marked as single init. Type already been set. Skip
            return False

        otherClass = findPinClassByType(dataType)
        self.super = otherClass
        self.activeDataType = dataType
        if not self.isArray():
            self._data = getPinDefaultValueByType(self.activeDataType)
        else:
            self._data = []
        self.setDefaultValue(self._data)

        self.color = otherClass.color
        self.dirty = True
        self.jsonEncoderClass = otherClass.jsonEncoderClass
        self.jsonDecoderClass = otherClass.jsonDecoderClass
        self.supportedDataTypes = otherClass.supportedDataTypes
        self._supportedDataTypes = otherClass.supportedDataTypes()

        self.typeChanged.send(self.activeDataType)
        self._free = self.activeDataType == self.__class__.__name__

        return True
Exemple #3
0
 def setDataType(self, dataType, _bJustSpawned=False):
     self._rawVariable.dataType = dataType
     self.widget.color = findPinClassByType(self.dataType).color()
     self.widget.update()
     if _bJustSpawned:
         return
     self.variablesWidget.onUpdatePropertyView(self)
Exemple #4
0
    def __init__(self, rawVariable, variablesWidget, parent=None):
        super(UIVariable, self).__init__(parent)
        self._rawVariable = rawVariable
        self.variablesWidget = variablesWidget
        # ui
        self.horizontalLayout = QHBoxLayout(self)
        self.horizontalLayout.setSpacing(1)
        self.horizontalLayout.setContentsMargins(1, 1, 1, 1)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.widget = TypeWidget(findPinClassByType(self._rawVariable.dataType).color(), self)
        self.widget.setObjectName("widget")
        self.horizontalLayout.addWidget(self.widget)
        self.labelName = QLabel(self)
        self.labelName.setStyleSheet("background:transparent")
        self.labelName.setObjectName("labelName")
        self.horizontalLayout.addWidget(self.labelName)
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        # find refs
        self.pbFindRefs = QPushButton("")
        self.pbFindRefs.setIcon(QtGui.QIcon(":/searching-magnifying-glass.png"))
        self.pbFindRefs.setObjectName("pbFindRefs")
        self.horizontalLayout.addWidget(self.pbFindRefs)
        self.pbFindRefs.clicked.connect(self.onFindRefsClicked)
        #  kill variable
        self.pbKill = QPushButton("")
        self.pbKill.setIcon(QtGui.QIcon(":/delete_icon.png"))
        self.pbKill.setObjectName("pbKill")
        self.horizontalLayout.addWidget(self.pbKill)
        self.pbKill.clicked.connect(self.onKillClicked)

        QtCore.QMetaObject.connectSlotsByName(self)
        self.setName(self._rawVariable.name)
        self._rawVariable.setWrapper(self)
Exemple #5
0
 def changeType(self, dataType):
     self.headColor = self.headColorOverride = QtGui.QColor(
         *findPinClassByType(dataType).color())
     if self.headColor.lightnessF() > 0.75:
         self.labelTextColor = QtCore.Qt.black
     else:
         self.labelTextColor = QtCore.Qt.white
     self.update()
Exemple #6
0
 def setType(self, dataType):
     if dataType != self.prevDataType:
         self.prevDataType = dataType
         colorTuple = findPinClassByType(dataType).color()
         self._pinColor = QtGui.QColor(*colorTuple)
         for e in self.connections:
             e.setColor(self._pinColor)
         self.OnPinChanged.emit(self)
         self.update()
Exemple #7
0
 def serialize(self):
     dt = super(AnyPin, self).serialize()
     constrainedType = self.activeDataType
     if constrainedType != self.__class__.__name__:
         pinClass = findPinClassByType(constrainedType)
         # serialize with active type's encoder
         dt['value'] = json.dumps(self.currentData(),
                                  cls=pinClass.jsonEncoderClass())
         dt['currDataType'] = constrainedType
     return dt
Exemple #8
0
    def value(self, value):
        # type checking if this variable is not of any type
        if not self.dataType == 'AnyPin':
            supportedDataTypes = findPinClassByType(self.dataType).supportedDataTypes()
            if self.dataType not in supportedDataTypes:
                return

        if self._value != value:
            self._value = value
            self.valueChanged.send(value)
Exemple #9
0
 def getClassFromType(self, pinType):
     """        
     Gets the internalDataStructure for a defined pinType
     :param pinType: pinType Name
     :type pinType: string
     """
     pin = findPinClassByType(pinType)
     if pin:
         pinClass = pin.internalDataStructure()
         return pinClass
     return None
Exemple #10
0
 def __init__(self, raw_node):
     super(UIConvertToNode, self).__init__(raw_node)
     self.headColorOverride = Colors.Gray
     self.color = Colors.DarkGray
     self.headColor = self.headColorOverride = QtGui.QColor(
         *findPinClassByType("AnyPin").color())
     if self.headColor.lightnessF() > 0.75:
         self.labelTextColor = QtCore.Qt.black
     else:
         self.labelTextColor = QtCore.Qt.white
     self.prevDataType = "AnyPin"
Exemple #11
0
    def deserialize(graph, jsonData, *args, **kwargs):
        name = jsonData['name']
        dataType = jsonData['dataType']

        if dataType != "AnyPin":
            pinClass = findPinClassByType(dataType)
            value = json.loads(jsonData['value'], cls=pinClass.jsonDecoderClass())
        else:
            value = getPinDefaultValueByType("AnyPin")

        accessLevel = AccessLevel(jsonData['accessLevel'])
        uid = uuid.UUID(jsonData['uuid'])
        return Variable(graph, value, name, dataType, accessLevel, uid)
Exemple #12
0
 def serialize(self):
     """Stores The data to Json
     
     Appends current value and currentDataType to default :py:func:`PyFlow.Core.PinBase.PinBase.serialize` method
     :returns: json data
     :rtype: {dict}
     """
     dt = super(AnyPin, self).serialize()
     constrainedType = self.activeDataType
     if constrainedType != self.__class__.__name__:
         pinClass = findPinClassByType(constrainedType)
         # serialize with active type's encoder
         dt['value'] = json.dumps(self.currentData(), cls=pinClass.jsonEncoderClass())
         dt['currDataType'] = constrainedType
     return dt
Exemple #13
0
    def deserialize(data, graph):
        pinClass = findPinClassByType(data['dataType'])

        varUid = uuid.UUID(data['uuid'])
        var = graph.getApp().variablesWidget.createVariable(
            dataType=data['dataType'], accessLevel=AccessLevel(data['accessLevel']), uid=varUid)
        var.setName(data['name'])
        var.setDataType(data['dataType'])

        if data['dataType'] == 'AnyPin':
            var.value = getPinDefaultValueByType('AnyPin')
        else:
            var.value = json.loads(data['value'], cls=pinClass.jsonDecoderClass())

        return var
Exemple #14
0
    def setType(self, dataType):
        """Here is where :py:class:`AnyPin` heredates all the properties from other defined dataTypes and act like those
        
        :param dataType: New DataType
        :type dataType: string
        :returns: True if succes setting dataType
        :rtype: {bool}
        """
        if self.activeDataType == dataType:
            return True

        if not self.optionEnabled(PinOptions.ChangeTypeOnConnection):
            return False

        if self.activeDataType != self.__class__.__name__ and self.singleInit:
            # Marked as single init. Type already been set. Skip
            return False

        otherClass = findPinClassByType(dataType)
        if dataType != "AnyPin":
            self.super = otherClass
        else:
            self.super = None

        if self.activeDataType == "AnyPin" and self._lastError2 == None:
            self.prevDataType = "AnyPin"
        else:
            self.prevDataType = None

        self.activeDataType = dataType
        if not self.isArray():
            self.setData(getPinDefaultValueByType(self.activeDataType))
        else:
            self.setData([])
        self.setDefaultValue(self._data)

        self.color = otherClass.color
        self.dirty = True
        self.jsonEncoderClass = otherClass.jsonEncoderClass
        self.jsonDecoderClass = otherClass.jsonDecoderClass
        self.supportedDataTypes = otherClass.supportedDataTypes
        self._supportedDataTypes = otherClass.supportedDataTypes()
        self.typeChanged.send(self.activeDataType)
        self.dataBeenSet.send(self)

        return True
Exemple #15
0
    def deserialize(self, jsonData):
        """Reconstruct Pin from saved jsonData

        :param jsonData: Input Json Saved data
        :type jsonData: dict
        """
        super(AnyPin, self).deserialize(jsonData)
        if "currDataType" in jsonData:
            self.setType(jsonData["currDataType"])

        pinClass = findPinClassByType(self.activeDataType)
        try:
            self.setData(json.loads(jsonData['value'], cls=pinClass.jsonDecoderClass()))
        except:
            self.setData(self.defaultValue())

        self.updateError([])
Exemple #16
0
    def serialize(self):
        pinClass = findPinClassByType(self.dataType)

        template = Variable.jsonTemplate()

        uidString = str(self.uid)

        template['name'] = self.name
        if self.dataType == 'AnyPin':
            template['value'] = None
        else:
            template['value'] = json.dumps(self.value, cls=pinClass.jsonEncoderClass())
        template['dataType'] = self.dataType
        template['accessLevel'] = self.accessLevel.value
        template['package'] = self._packageName
        template['uuid'] = uidString

        return template
Exemple #17
0
    def serialize(self):
        pinClass = findPinClassByType(self._rawVariable.dataType)

        template = UIVariable.jsonTemplate()
        template['name'] = self._rawVariable.name
        template['uuid'] = str(self._rawVariable.uid)

        if self._rawVariable.dataType == "AnyPin":
            # don't save any variables
            # value will be calculated for this type of variables
            template['value'] = None
        else:
            template['value'] = json.dumps(self._rawVariable.value, cls=pinClass.jsonEncoderClass())

        template['type'] = self._rawVariable.dataType
        template['package'] = self._rawVariable.packageName
        template['accessLevel'] = self._rawVariable.accessLevel.value
        return template
Exemple #18
0
    def __init__(self, dataType, parent=None):
        super(_PinWidget, self).__init__(parent)
        self.dataType = dataType
        self.fakeOwningNode = _FakeNode()
        self._rawPin = _FakePin()
        self._pinColor = QtGui.QColor(
            *findPinClassByType(self.dataType).color())
        self.labelColor = QtCore.Qt.white
        self.hovered = False
        self.pinSize = _PIN_SIZE
        self._font = QtGui.QFont("Consolas")
        self._font.setPointSize(14)
        self.direction = PinDirection.Input
        self.name = self.dataType
        self.bLabelHidden = False

        self.setMouseTracking(True)
        self.setSizePolicy(QtWidgets.QSizePolicy.Maximum,
                           QtWidgets.QSizePolicy.Maximum)
Exemple #19
0
    def deserialize(graph, jsonData, *args, **kwargs):
        name = jsonData['name']

        dataType = "BoolPin"
        if jsonData["structure"] == StructureType.Dict.name:
            keyDataType = jsonData['dictKeyType']
            valueDataType = jsonData['dictValueType']

            value = PFDict(keyDataType, valueDataType)
        else:
            dataType = jsonData['dataType']

            if dataType != "AnyPin":
                pinClass = findPinClassByType(dataType)
                value = json.loads(jsonData['value'], cls=pinClass.jsonDecoderClass())
            else:
                value = getPinDefaultValueByType("AnyPin")

        accessLevel = AccessLevel[jsonData['accessLevel']]
        structure = StructureType[jsonData['structure']]
        uid = uuid.UUID(jsonData['uuid'])
        return Variable(graph, value, name, dataType, accessLevel, structure, uid)
Exemple #20
0
 def updatePackageName(self):
     self._packageName = findPinClassByType(self._dataType)._packageName
Exemple #21
0
 def dataType(self, value):
     self._rawVariable.dataType = value
     self.widget.color = findPinClassByType(
         self._rawVariable.dataType).color()
     self.widget.update()
     self.variablesWidget.onUpdatePropertyView(self)
Exemple #22
0
 def compute(self, *args, **kwargs):
     otherClass = findPinClassByType(self.output.dataType)
     self.output.setData(otherClass.processData(self.input.getData()))