def __init__(self, name=None): EObject.__init__(self) self.Name = name self.__attributes = {} self.__connections = {} return
def __init__(self): EObject.__init__(self) self.__type = None self.__attrName = None self.__attrData = None self.__handle = None
def __init__(self, handle): EObject.__init__(self) self.__type = None self.__isConnected = False self.__attrName = None self.__attrData = None self.__handle = handle
def __init__(self): EObject.__init__(self) self.__nodes = {} self.__attributes = {} self.__connections = {} self.__availableNodes = None self.__tAttrId = None self.__pluginManager = EManager()
def __init__(self, head, tail): EObject.__init__(self) self.__headAttr = head self.__tailAttr = tail if head.Type.match(EAttribute.kTypeInput): self.__tailAttr = head self.__headAttr = tail self.__headAttr.Message.connect(self.__messageFilter) self.__tailAttr.Message.connect(self.__messageFilter) self.__tailAttr.Data = self.__headAttr.Data
def __init__(self, head, tail): EObject.__init__(self) self.__headAttr = head self.__tailAttr = tail if head.Type.matches(EAttribute.kTypeInput): self.__tailAttr = head self.__headAttr = tail #self.__headAttr.Message.connect(self.__messageFilter) #self.__tailAttr.Message.connect(self.__messageFilter) self.__tailAttr.Data = self.__headAttr.Handle.getAttributeById(self.__headAttr.Id).Data
def __init__(self, source, destination): EObject.__init__(self) self.__sourceAttr = source self.__destinationAttr = destination if source.Handle.isInput(source.Id): self.__destinationAttr = source self.__sourceAttr = destination self.__sourceAttr.Handle.Message.connect(self.__messageFilter) self.__sourceAttr.Handle.compute() self.__destinationAttr.Handle.setAttribute(self.__destinationAttr, self.__sourceAttr.Data)
def __init__(self, handle): EObject.__init__(self) self.__isConnected = False self.__isArray = False self.__isDirty = False self.__attrType = None self.__attrName = None self.__attrData = None self.__minValue = None self.__maxValue = None self.__attrHandle = handle
def __init__(self): EObject.__init__(self) self.kNodeTypeName = None self.IsStatic = False self.IsContainer = False self.__attributes = {} self.__connections = {} self.__attributeLinks = {} self.__propertyIndexList = {} return
def __init__(self): EObject.__init__(self) self.kNodeTypeName = None self.IsStandAlone = False self.IsContainer = False self.__attributes = {} self.__inputAttributes = [] self.__outputAttributes = [] self.__attributesNetwork = {} self.__connections = {} self.__attributeLinks = {} self.__propertyIndexList = {} return
def __init__(self, head, tail): EObject.__init__(self) self.__head = head self.__tail = tail
class ENodeHandle(EObject): kMessageAttributeMarked = EObject() kMessageAttributeAdded = EObject() kMessageAttributeRemoved = EObject() def __init__(self, name=None): EObject.__init__(self) self.Name = name self.__attributes = {} self.__connections = {} return def __messageFilter(self, message): #print message.sender().Handle.Name, message.sender().Name pass def compute(self, plug, data=None): return None def hasAttribute(self, eAttribute): return def hasAttributeOfType(self, eAttributeType): return def addInputAttribute(self, attrName, attrValue=None): attr = EAttribute().create(EAttribute.kTypeInput, attrName, attrValue) self.addAttribute(attr) return attr def addOutputAttribute(self, attrName, attrValue=None): attr = EAttribute().create(EAttribute.kTypeOutput, attrName, attrValue) self.addAttribute(attr) return attr def addAttribute(self, eAttribute): if not isinstance(eAttribute, EAttribute): raise result = self.getAttributeByName(eAttribute.Name) if len(result): if len(result) > 1 or result[0].Type.match(eAttribute.Type): raise AttributeError("Attribute name is not unique! <%s.%s>" % (self.Name, eAttribute.Name)) self.__attributes[eAttribute.Id] = eAttribute eAttribute.Handle = self eAttribute.Message.connect(self.__messageFilter) self.Message.emit(self.kMessageAttributeAdded.setData(eAttribute)) def delAttribute(self, attributeName): attr = self.getAttributeByName(attributeName) if attr is not None: self.__attributes.pop(attr.Id, None) self.Message.emit(ENodeHandle.kMessageAttributeRemoved) def ls(self, eType=None): if eType is not None: if isinstance(eType, list): return [eAttribute for eAttribute in self.__attributes.itervalues() if eAttribute.Type in eType] return [eAttribute for eAttribute in self.__attributes.itervalues() if eAttribute.Type == eType] return [eAttribute for eAttribute in self.__attributes.itervalues()] def getAttribute(self, eAttribute): if not isinstance(eAttribute, EAttribute): raise AttributeError return self.getAttributeById(eAttribute.Id) def getAttributeById(self, attributeId): if self.__attributes.has_key(attributeId): return self.__attributes[attributeId] return None def getAttributeByName(self, attributeName): result = [] for attr in self.__attributes.itervalues(): if attributeName == attr.Name: result.append(attr) return result def addConnection(self, connection): return def delConnection(self, connection): return def getConnections(self): return self.__connections
class EAttribute(EObject): kTypeInput = EObject() kTypeOutput = EObject() kMessageAttributeSet = EObject() kMessageAttributeGet = EObject() kMessageAttributeRenamed = EObject() def __init__(self): EObject.__init__(self) self.__type = None self.__attrName = None self.__attrData = None self.__handle = None def create(self, attributeType, attributeName, attributeData=None): self.__type = attributeType self.__attrName = attributeName self.__attrData = attributeData return self @property def Type(self): return self.__type @property def Name(self): return self.__attrName @Name.setter def Name(self, name): self.__attrName = name self.Message.emit(self.kMessageAttributeRenamed) @property def Handle(self): return self.__handle @Handle.setter def Handle(self, handle): self.__handle = handle @property def Data(self): self.Message.emit(self.kMessageAttributeGet) return self.__attrData @Data.setter def Data(self, attrData): self.__attrData = attrData self.Message.emit(self.kMessageAttributeSet) def isInput(self): if self.__type == self.kTypeInput: return True return False def isOutput(self): if self.__type == self.kTypeOutput: return True return False @property def isArray(self): return @isArray.setter def isArray(self, state): return def clear(self): self.__attrData = None
class ENode(QGraphicsObject): onMove = pyqtSignal() onPress = pyqtSignal() kGuiAttributeId = EObject() kGuiAttributeType = EObject() kGuiAttributePlug = EObject() kGuiAttributeParent = EObject() kGuiAttributeParentName = EObject() kGuiAttributeLongName = EObject() kGuiAttributeShortName = EObject() def __init__(self, eNodeHandle): QGraphicsObject.__init__(self) self.setFlag(QGraphicsItem.ItemIsMovable, True) self.setAcceptsHoverEvents(True) self.__isDefaultPen = False self.__pen = None self.__pens = { 0: EDraw.EColor.DefaultLeaveHoverPen, 1: EDraw.EColor.DefaultEnterHoverPen } self.setPen(self.__pens[self.__isDefaultPen]) self.Name = eNodeHandle.Name self.__font = QFont('Helvetica', 8, False) self.__nodeHandle = eNodeHandle self.__nodeHandle.Message.connect(self.__messageFilter) self.__attrRect = QRectF(0, 0, 15, 15) self.__titleRect = QRectF(0, 0, 125, 20) self.__textSpace = QRectF( self.__attrRect.width() + self.pen().width(), 0.0, (self.__titleRect.width() - self.__attrRect.width() * 2 - self.pen().width() * 2) / 2, self.__attrRect.height()) self.__attributes = {} self.__out_attr_step = self.__titleRect.height() + self.pen().width() self.__in_attr_step = self.__titleRect.height() + self.pen().width() self.__buildAttributes() self.__height = max([self.__in_attr_step, self.__out_attr_step]) def __messageFilter(self, message): if message.match(self.__nodeHandle.kMessageAttributeAdded): self.__buildAttribute(message.getData()) def __getAttrShortName(self, attributeName): fm = QFontMetrics(self.__font) shortName = '' if fm.width(attributeName) > self.__textSpace.width(): for x in range(len(attributeName) + 1): if fm.width(shortName) > int(self.__textSpace.width()) - 10: return shortName shortName = attributeName[:x] + '...' return attributeName def __getAttributePosition(self, attrType): attr_x_pos = 0 if attrType.match(EAttribute.kTypeOutput): attr_x_pos = self.__titleRect.width() - self.__attrRect.width() rect = self.__attrRect.translated( QPointF(attr_x_pos, self.__out_attr_step)) point = QPointF((rect.topRight() + rect.bottomRight()) / 2) point.setX(point.x() + self.pen().width() * 2) self.__out_attr_step += self.__attrRect.width() + self.pen().width( ) return [rect, point] rect = self.__attrRect.translated( QPointF(attr_x_pos, self.__in_attr_step)) point = QPointF((rect.topLeft() + rect.bottomLeft()) / 2) point.setX(point.x() - self.pen().width() * 2) self.__in_attr_step += self.__attrRect.width() + self.pen().width() return [rect, point] def __buildAttribute(self, attribute): data = self.__getAttributePosition(attribute.Type) self.__attributes[data[0]] = dict({ self.kGuiAttributeId: attribute.Id, self.kGuiAttributeType: attribute.Type, self.kGuiAttributeParent: self, self.kGuiAttributeParentName: self.__nodeHandle.Name, self.kGuiAttributePlug: data[1], self.kGuiAttributeLongName: attribute.Name, self.kGuiAttributeShortName: self.__getAttrShortName(attribute.Name) }) self.__height = max([self.__in_attr_step, self.__out_attr_step]) self.update() self.onMove.emit() def __buildAttributes(self): for eddAttr in self.__nodeHandle.ls(): self.__buildAttribute(eddAttr) def __toggleHighlight(self): if self.__isDefaultPen: self.__isDefaultPen = False self.setPen(self.__pens[self.__isDefaultPen]) #self.setZValue(0.0) return self.__isDefaultPen = True self.setPen(self.__pens[self.__isDefaultPen]) #self.setZValue(-2.0) @property def Id(self): return self.__nodeHandle.Id def pen(self): return self.__pen def setPen(self, pen): if not isinstance(pen, QPen): raise AttributeError self.__pen = pen @property def Handle(self): return self.__nodeHandle def mapFromPoint(self, QPoint): for attrRect, attrValues in self.__attributes.iteritems(): if attrRect.contains(self.mapFromScene(QPoint)): return attrValues[self.kGuiAttributeId] return self.__nodeHandle.Id def mapFromId(self, attrId): for attrValue in self.__attributes.itervalues(): if attrValue[self.kGuiAttributeId] == attrId: return attrValue return None def hoverEnterEvent(self, mouseEvent): QGraphicsObject.hoverEnterEvent(self, mouseEvent) self.__toggleHighlight() def hoverMoveEvent(self, mouseEvent): QGraphicsObject.hoverMoveEvent(self, mouseEvent) def hoverLeaveEvent(self, mouseEvent): QGraphicsObject.hoverLeaveEvent(self, mouseEvent) self.__toggleHighlight() def mousePressEvent(self, mouseEvent): QGraphicsObject.mousePressEvent(self, mouseEvent) #if mouseEvent.button() == Qt.RightButton: #print self.mapFromPoint(mouseEvent.scenePos()) self.onPress.emit() def mouseDoubleClickEvent(self, mouseEvent): QGraphicsObject.mouseDoubleClickEvent(self, mouseEvent) #self.__nodeHandle.compute() def mouseMoveEvent(self, mouseEvent): QGraphicsObject.mouseMoveEvent(self, mouseEvent) self.onMove.emit() def boundingRect(self): extra = self.pen().width() return self.__titleRect.normalized().adjusted( -extra, -extra, extra, (self.__height - self.__titleRect.height()) + extra) def shape(self): return QGraphicsItem.shape(self) def paint(self, painter, option, widget=None): painter.setBrush(Qt.darkGray) painter.setPen(self.pen()) painter.drawRect(self.boundingRect()) painter.setPen(Qt.NoPen) painter.setBrush(QColor(43, 43, 43)) painter.drawRect(self.__titleRect) painter.setPen(Qt.darkGray) painter.drawText(self.__titleRect, Qt.AlignCenter, self.Name) painter.setPen(Qt.NoPen) painter.setBrush(QColor(60, 63, 65)) for rect in self.__attributes.iterkeys(): painter.drawRect(rect) painter.setBrush(Qt.darkGray) for rect in self.__attributes.iterkeys(): painter.drawPolygon( EDraw.Circle(rect.height() / 3, 3).translated(rect.center())) painter.setPen(QPen(QColor(43, 43, 43), 1.0, Qt.SolidLine)) painter.setBrush(Qt.NoBrush) painter.setFont(self.__font) for attrRect, attrValues in self.__attributes.iteritems(): attrNameRect = self.__textSpace.translated(attrRect.topLeft()) align = Qt.AlignLeft if attrRect.topLeft().x() > 0: attrNameRect = self.__textSpace.translated( QPointF((self.__titleRect.width() / 2) - (attrRect.width() + self.pen().width()), attrRect.topLeft().y())) align = Qt.AlignRight painter.drawText(attrNameRect, align, attrValues[self.kGuiAttributeShortName])
class EGraphHandle(EObject): kMessageNodeAdded = EObject() kMessageNodeRemoved = EObject() kMessageNodeUpdate = EObject() kMessageEditBegin = EObject() kMessageEditEnd = EObject() kMessageUnknown = EObject() kMessageInternalError = EObject() kMessageConnectionMade = EObject() kMessageConnectionBroke = EObject() def __init__(self): EObject.__init__(self) self.__nodes = {} self.__attributes = {} self.__connections = {} self.__availableNodes = None self.__tAttrId = None self.__pluginManager = EManager() def __create__(self): return def __messageFilter(self, message): if message.match(ENodeHandle.kMessageAttributeAdded): self.__attributes[message.getData().Id] = message.getData() def getConnectionFromAttributeId(self, attrId): for key, value in self.__connections.iteritems(): if attrId in [value.Head.Id, value.Tail.Id]: return key return None def getHandleFromId(self, id): if not isinstance(id, uuid.UUID): raise AttributeError if self.__attributes.has_key(id): return self.__attributes[id].Handle.Id return None def ls(self): return self.__nodes.values() def lsConnected(self): return self.__connections def select(self, nodeName): for handle in self.__nodes.itervalues(): if nodeName == handle.Name: return handle return None def createNode(self, name=None): if name in self.__pluginManager.lsPlugins(): nodeHandle = self.__pluginManager.loadPlugin(name) else: nodeHandle = ENodeHandle() nodeHandle.Name = name self.addNode(nodeHandle) return nodeHandle def addNode(self, handle): if not isinstance(handle, ENodeHandle): raise AttributeError handle.Message.connect(self.__messageFilter) if not handle.Name: handle.Name = "EUnknown_%s" % str(len(self.__nodes.keys())) self.__nodes[handle.Id] = handle for attribute in handle.ls(): self.__attributes[attribute.Id] = attribute self.Message.emit(self.kMessageNodeAdded.setData(handle)) def delNode(self, handle): self.Message.emit(self.kMessageNodeRemoved.setData(handle)) def updateNode(self, handle): if self.__nodes.has_key(handle.Id): self.__nodes[handle.Id] = handle self.Message.emit(self.kMessageNodeUpdate) def isConnected(self, attribute): if not isinstance(attribute, EAttribute): raise AttributeError return self.__attributes.has_key(attribute.Id) def connectAttributes(self, attributeOne, attributeTwo): if isinstance(attributeOne, EAttribute): attributeOne = attributeOne.Id if isinstance(attributeTwo, EAttribute): attributeTwo = attributeTwo.Id if self.__attributes.has_key( attributeOne) and self.__attributes.has_key(attributeTwo): if self.__attributes[attributeOne].Type.match( self.__attributes[attributeTwo].Type): self.Message.emit(self.kMessageInternalError.setData(None)) return False if self.__attributes[attributeOne].Handle.match( self.__attributes[attributeTwo].Handle): self.Message.emit(self.kMessageInternalError.setData(None)) return False conn1 = self.getConnectionFromAttributeId(attributeOne) conn2 = self.getConnectionFromAttributeId(attributeTwo) if conn1 and conn2 and conn1 == conn2: self.Message.emit(self.kMessageInternalError.setData(None)) return False connection = EConnection(self.__attributes[attributeOne], self.__attributes[attributeTwo]) self.__connections[connection.Id] = connection self.Message.emit( self.kMessageConnectionMade.setData( [attributeOne, attributeTwo, connection.Id])) return True return False def disconnectAttribute(self, attribute): if isinstance(attribute, EAttribute): attribute = attribute.Id if self.__attributes.has_key(attribute): conn = self.getConnectionFromAttributeId(attribute) self.__connections.pop(conn, None) self.Message.emit(self.kMessageConnectionBroke.setData(conn)) return True return False def disconnectAttributes(self, attributeOne, attributeTwo): return def process(self, attrId): if self.__attributes.has_key(attrId) and self.__tAttrId is None: self.__tAttrId = attrId self.Message.emit(self.kMessageEditBegin.setData(None)) return if self.__tAttrId: if self.__attributes.has_key(attrId): self.connectAttributes(self.__tAttrId, attrId) else: self.disconnectAttribute(self.__tAttrId) self.__tAttrId = None self.Message.emit(self.kMessageEditEnd.setData(None))
def __init__(self): EObject.__init__(self) self.__nodes = {} self.__attributes = {} self.__connections = {}
def __init__(self): EObject.__init__(self) self.__scene = None self.__regNodes = {} self.__graphHandle = EGraphHandle()