class UIGraphInputs(UINodeBase): pinCreated = QtCore.Signal(object) def __init__(self, raw_node): super(UIGraphInputs, self).__init__(raw_node) actionAddOut = self._menu.addAction("Add pin") actionAddOut.setData(NodeActionButtonInfo(RESOURCES_DIR + "/pin.svg")) actionAddOut.triggered.connect(self.createPinDialog) self.color = Colors.DarkGray self.headColorOverride = Colors.Gray self.image = RESOURCES_DIR + "/gear.svg" def rename(self): name, confirmed = QInputDialog.getText(None, "Rename", "Enter new pin name") if confirmed and name != self.name and name != "": self.displayName = self.canvasRef().getUniqNodeDisplayName(name) self.update() self.setFocus() def createPinDialog(self): self.d = SelectPinDialog() self.d.exec_() dataType = self.d.getResult() if dataType is not None: self.onAddOutPin(None, dataType) self.setFocus() def onAddOutPin(self, name=None, dataType="AnyPin"): rawPin = self._rawNode.addOutPin(name, dataType) uiPin = self._createUIPinWrapper(rawPin) uiPin.labelColor = Colors.AbsoluteBlack self.pinCreated.emit(uiPin) geo = self.geometry() geo.setWidth(50) self.setGeometry(geo) self.updateNodeShape() return uiPin def postCreate(self, jsonTemplate): # this call will create wrappers for raw pins UINodeBase.postCreate(self, jsonTemplate) for uiPin in self.UIPins.values(): uiPin.labelColor = Colors.AbsoluteBlack try: self.displayName = jsonTemplate['name'] except: self.displayName = self.canvasRef().getUniqNodeDisplayName( "Inputs")
class UIGraphInputs(UINodeBase): pinCreated = QtCore.Signal(object) def __init__(self, raw_node): super(UIGraphInputs, self).__init__(raw_node) actionAddOut = self._menu.addAction("Add pin") actionAddOut.setData(NodeActionButtonInfo(RESOURCES_DIR + "/pin.svg")) actionAddOut.triggered.connect(self.createPinDialog) self.color = Colors.DarkGray self.headColorOverride = Colors.Gray self.image = RESOURCES_DIR + "/gear.svg" def setName(self, name): oldName = self.getName() super(UIGraphInputs, self).setName(name) owningCompoundNode = self.canvasRef().graphManager.findNode( self._rawNode.graph().name) if owningCompoundNode: uiCompoundNode = owningCompoundNode.getWrapper() if oldName in uiCompoundNode.groups["input"]: grpItem = uiCompoundNode.groups["input"][oldName] grpItem.name = name if oldName in owningCompoundNode.groups["input"]: for inp in owningCompoundNode.groups["input"][oldName]: inp.grop = name owningCompoundNode.groups["input"][ name] = owningCompoundNode.groups["input"].pop(oldName) def createPinDialog(self): self.d = SelectPinDialog() self.d.exec_() dataType = self.d.getResult() if dataType is not None: self.onAddOutPin(None, dataType) def onAddOutPin(self, name=None, dataType="AnyPin"): rawPin = self._rawNode.addOutPin(name, dataType) uiPin = self._createUIPinWrapper(rawPin) uiPin.labelColor = Colors.AbsoluteBlack self.pinCreated.emit(uiPin) self.updateNodeShape() return uiPin def postCreate(self, jsonTemplate): # this call will create wrappers for raw pins UINodeBase.postCreate(self, jsonTemplate) for uiPin in self.UIPins.values(): uiPin.labelColor = Colors.AbsoluteBlack def createInputWidgets(self, inputsCategory, inGroup=None, pins=True): if self.graph() == GraphManagerSingleton().get().findRootGraph(): self.createOutputWidgets(inputsCategory, inGroup)
class UIGraphOutputs(UINodeBase): pinCreated = QtCore.Signal(object) def __init__(self, raw_node): super(UIGraphOutputs, self).__init__(raw_node) actionRename = self._menu.addAction("Rename") actionRename.triggered.connect(self.rename) actionAddOut = self._menu.addAction("Add pin") actionAddOut.setData(NodeActionButtonInfo(RESOURCES_DIR + "/pin.svg")) actionAddOut.triggered.connect(self.createPinDialog) self.color = Colors.DarkGray self.headColorOverride = Colors.Gray self.image = RESOURCES_DIR + "/gear.svg" def rename(self): name, confirmed = QInputDialog.getText(None, "Rename", "Enter new pin name") if confirmed and name != self.name and name != "": self.update() def createPinDialog(self): self.d = SelectPinDialog() self.d.exec_() dataType = self.d.getResult() if dataType is not None: self.onAddInPin(None, dataType) def onAddInPin(self, name=None, dataType="AnyPin"): rawPin = self._rawNode.addInPin(name, dataType) uiPin = self._createUIPinWrapper(rawPin) uiPin.labelColor = Colors.AbsoluteBlack self.pinCreated.emit(uiPin) self.updateNodeShape() return uiPin def postCreate(self, jsonTemplate): UINodeBase.postCreate(self, jsonTemplate) for uiPin in self.UIPins.values(): uiPin.labelColor = Colors.AbsoluteBlack
class UIAnyPin(UIPinBase): def __init__(self, owningNode, raw_pin): """UI wrapper for :class:`PyFlow.Packages.Base.Pins.AnyPin` :param owningNode: Owning node :type owningNode: :class:`PyFlow.UI.Canvas.NodeBase` :param raw_pin: PinBase reference :type raw_pin: :class:`PyFlow.Packages.Base.Pins.AnyPin` """ super(UIAnyPin, self).__init__(owningNode, raw_pin) self._defaultColor = self._pinColor self._rawPin.typeChanged.connect(self.setType) self._rawPin.dataTypeBeenSet.connect(self.dataTypeBeenSet) self._rawPin.onPinDisconnected.connect(self.disconnect) self.menu.addAction("InitAs").triggered.connect(self.selectInit) self.prevDataType = "AnyPin" self.prevColor = None def dataTypeBeenSet(self, *args, **kwargs): self.prevColor = None self.prevDataType = None self.setDefault(self._rawPin.defColor()) def checkFree(self, checked=[], selfCheck=True): return self._rawPin.checkFree(checked, selfCheck) def disconnect(self, other): self.prevColor = None self.prevDataType = None @property def activeDataType(self): return self._rawPin.activeDataType def setDefault(self, defcolor): if defcolor != self.prevColor: self.prevColor = defcolor self._pinColor = QtGui.QColor(*defcolor) for e in self.connections: e.setColor(QtGui.QColor(*defcolor)) self.OnPinChanged.emit(self) self.update() def selectInit(self): validPins = list(self._rawPin._defaultSupportedDataTypes) if "AnyPin" in validPins: validPins.remove("AnyPin") self.d = SelectPinDialog(validPins=validPins) self.d.exec_() dataType = self.d.getResult() if dataType is not None: self.initType(dataType, True) def initType(self, dataType, init=False): self._rawPin.initType(dataType, init) 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()
class UIAnyPin(UIPinBase): def __init__(self, owningNode, raw_pin): super(UIAnyPin, self).__init__(owningNode, raw_pin) self._defaultColor = self._pinColor self._rawPin.typeChanged.connect(self.setType) self._rawPin.dataTypeBeenSet.connect(self.dataTypeBeenSet) self._rawPin.onPinDisconnected.connect(self.disconnect) self.menu.addAction("InitAs").triggered.connect(self.selectInit) self.prevDataType = "AnyPin" self.prevColor = None def dataTypeBeenSet(self, *args, **kwargs): self.prevColor = None self.prevDataType = None self.setDefault(self._rawPin.defColor()) def checkFree(self, checked=[], selfChek=True): return self._rawPin.checkFree(checked, selfChek) def disconnect(self, other): self.prevColor = None self.prevDataType = None @property def activeDataType(self): return self._rawPin.activeDataType def setDefault(self, defcolor): if defcolor != self.prevColor: self.prevColor = defcolor self._pinColor = QtGui.QColor(*defcolor) for e in self.connections: e.setColor(QtGui.QColor(*defcolor)) self.OnPinChanged.emit(self) self.update() def selectInit(self): validPins = self._rawPin._defaultSupportedDataTypes + ("AnyPin", ) # List can't become array if self._rawPin._currStructure != PinStructure.Single: validPins = tuple([i for i in validPins if i != "ListPin"]) self.d = SelectPinDialog(validPins=validPins) self.d.exec_() dataType = self.d.getResult() if dataType is not None: self.initType(dataType, True) def initType(self, dataType, init=False): self._rawPin.initType(dataType, init) 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() def hoverEnterEvent(self, event): super(UIPinBase, self).hoverEnterEvent(event) self.update() self.hovered = True supportedTypes = self._rawPin.allowedDataTypes( [], self._rawPin._supportedDataTypes) hoverMessage = "Data: {0}\r\nDirty: {1}\r\nAllowed Types: {2}".format( str(self._rawPin.currentData()), self._rawPin.dirty, supportedTypes) self.setToolTip(hoverMessage) event.accept() def paint(self, painter, option, widget): if self.isExec(): PinPainter.asExecPin(self, painter, option, widget) elif self.isArray(): PinPainter.asArrayPin(self, painter, option, widget) elif self.isList(): PinPainter.asListPin(self, painter, option, widget) else: PinPainter.asValuePin(self, painter, option, widget)