class ComponentQGraphicsItem(QGraphicsObject): #(QtSvg.QGraphicsSvgItem): def __init__(self, svgfile, component, nodes): #QGraphicsSvgItem.__init__(self,svgfile) QGraphicsObject.__init__(self) self.__svggraphic = QGraphicsSvgItem(svgfile) rect = self.__svggraphic.boundingRect() self.__nodeGraphics = [] self.__component = weakref.ref(component) # this signals the itemChange() method when this item is moved # used for refreshing the spaces between components self.setFlags(QGraphicsItem.ItemSendsGeometryChanges) self.nodedx = [] # stores the node square offsets item = QGraphicsTextItem(component.name, self) rect = item.boundingRect() item.setPos(-0.5 * rect.width(), 40 - 0.5 * rect.height()) self.setAcceptsHoverEvents(True) for n in nodes: self.nodedx.append([n[0], n[1]]) node = n[2].getQGraphicsItem(n[0], n[1], nsize, self) node.setPen(QPen(Qt.black)) node.refresh() self.__nodeGraphics.append(node) self.refresh() self.installEventFilter(self) self.setHandlesChildEvents(True) def boundingRect(self): return self.__svggraphic.boundingRect() def paint(self, arg1, arg2, arg3): self.__svggraphic.rotate(45) self.__svggraphic.paint(arg1, arg2, arg3) @property def component(self): return self.__component() def refresh(self): for n in self.__nodeGraphics: n.refresh() def itemChange(self, change, value): # if the item is moved then update any spaces attached to it if change == QGraphicsItem.ItemPositionHasChanged: nodes = self.component.nodes for n in nodes: conn = n.amIConnected(self.component) if conn[0] and isinstance(conn[1], pykat.components.space): conn[1].getQGraphicsItem().refresh() return QGraphicsSvgItem.itemChange(self, change, value)