def __init__(self, startHook, endHook = None): QtGui.QGraphicsItem.__init__(self, None, startHook.scene()) self._rect = QtCore.QRectF(0, 0, 0, 0) self._startHook = weakref.ref(startHook) self._endHook = None self._color = startHook.colorRef() self._pen = QtGui.QPen(self._color) self._pen.setWidth(1) self._isTempConnection = False self._path = QtGui.QPainterPath() startHook.addConnection(self) if endHook: self._endHook = weakref.ref(endHook) endHook.addConnection(self) else: # creating a dummy endHook for temporary connection dragging self._endHook = weakref.ref(ConnectionHook(startHook.parentAttributeUi(), parentItem = self)) self._endHook().boundingRect().setSize(QtCore.QSizeF(2.0, 2.0)) self._isTempConnection = True self.updateStartPos() self.setZValue(-1.0)
def __init__(self, coralAttribute, parentNodeUi): QtGui.QGraphicsWidget.__init__(self, parentNodeUi) self._coralAttribute = weakref.ref(coralAttribute) self._coralAttributeId = coralAttribute.id() self._parentNodeUi = weakref.ref(parentNodeUi) self._spacerConstant = 5.0 self._label = QtGui.QGraphicsSimpleTextItem(self) self._inputHook = None self._outputHook = None self._proxy = None self._attributeSpecializedObserver = Observer() self._disconnectedInputObserver = Observer() self._nameChangedObserver = Observer() self._labelSuffix = "" self._labelText = "" if coralAttribute.isInput(): self._inputHook = ConnectionHook(self, isInput=True) else: self._outputHook = ConnectionHook(self, isOutput=True) self._label.setBrush(parentNodeUi.labelsColor()) self._labelText = coralAttribute.name().split(":")[-1] self._label.setText(self._labelText) self.setHooksColor( self.hooksColor(self._coralAttribute().allowedSpecialization())) coralApp.addDisconnectedInputObserver(self._disconnectedInputObserver, coralAttribute, self._disconnected) coralApp.addAttributeSpecializedObserver( self._attributeSpecializedObserver, coralAttribute, self.specialized) coralApp.addNameChangedObserver(self._nameChangedObserver, coralAttribute, self._coralAttributeNameChanged) if coralAttribute.name().startswith("_"): self.setVisible(False) if parentNodeUi.attributesProxyEnabled(): self._enableProxy() self.specialized()
def __init__(self, attributeUi): QtGui.QGraphicsWidget.__init__(self) self._parentNodeUi = weakref.ref(attributeUi.parentNodeUi()) self._attributeUi = weakref.ref(attributeUi) self._shapePen = self._parentNodeUi().shapePen() self._inputHook = None self._outputHook = None self._label = QtGui.QGraphicsSimpleTextItem(self) self._spacerConstant = 5.0 self._currentMagnifyFactor = 0.0 self._zValue = self.zValue() hookColor = QtGui.QColor(100, 100, 100) if attributeUi.outputHook(): hookColor = attributeUi.outputHook().color() elif attributeUi.inputHook(): hookColor = attributeUi.inputHook().color() if attributeUi.inputHook(): self._outputHook = ConnectionHook(attributeUi, parentItem=self, isOutput=True) self._outputHook.setColor(hookColor) self._outputHook.setFlags( QtGui.QGraphicsItem.ItemSendsScenePositionChanges) else: self._inputHook = ConnectionHook(attributeUi, parentItem=self, isInput=True) self._inputHook.setColor(hookColor) self._inputHook.setFlags( QtGui.QGraphicsItem.ItemSendsScenePositionChanges) self.setFlag(QtGui.QGraphicsItem.ItemIsMovable) self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable) self._label.setBrush(attributeUi.labelColor()) self._label.setText(attributeUi.coralAttribute().name()) self._shapePen.setStyle(QtCore.Qt.NoPen) self.setAcceptHoverEvents(True) self.updateLayout()