def __init__(self, scene, lineCalc, lineDecorator, parent, x, y, w, h, name = None): QGraphicsItem.__init__(self, parent) self.lineCalc = lineCalc self.lineDecorator = lineDecorator self.nameTag = TextNode(self.scene, text = name, x = x-105, y= y-3) self.name = name self.parent = parent self.host = None self.scene = scene self.child = [] #in screen coords self.contentPos = QPoint(x,y) #self.scenePos() self.setFlag(QGraphicsItem.ItemIsMovable) self.setAcceptHoverEvents(True) #width and height of content (img, text) without the arrows self.w = w self.h = h #variables for proper dragging and scaling self.resizeMode = False self.moveMode = False self.ignore = False self.lineRect = None self.setAcceptDrops(True)
def __init__(self, scene, lineCalc, lineDecorator, parent, x , y, w , h, name = None): QGraphicsItem.__init__(self, parent) self.Pcount = 0 self.Scount = 0 self.Swidgetcount = 0 self.scene = scene self.lineCalc = lineCalc self.lineDecorator = lineDecorator self.nameTag = TextNode(self.scene, text = name, x= x+10, y= y+5) self.nameTag.changeText(name) self.name = name self.parent = parent self.status = 0 self.temp_stat = 0 self.host = [] self.client = [] self.child = [] self.jack = [] self.drain = [] self.parts = [self.nameTag] #self.Ring, self.level = None self.script = None # self.parameters = None self.output = TypeError self.contentPos = QPoint(x,y) #self.scenePos() self.setFlag(QGraphicsItem.ItemIsMovable) self.setAcceptHoverEvents(True) self.setLevel(-1) #width and height of content (img, text) without the arrows self.x = x self.y = y self.w = w self.h = h #variables for proper dragging and scaling self.resizeMode = False self.moveMode = False self.ignore = False self.lineRect = None
def getTextNode(): returnValue = libpanda._inPWvimKv2y() import TextNode returnObject = TextNode.TextNode(None) returnObject.this = returnValue if returnObject.this == 0: return None returnObject.userManagesMemory = 1 return returnObject.setPointer() return
def getTextDef(self, state): returnValue = libpanda._inPWvimHmBt(self.this, state) import TextNode returnObject = TextNode.TextNode(None) returnObject.this = returnValue if returnObject.this == 0: return None returnObject.userManagesMemory = 1 return returnObject.setPointer()
def downcastToTextNodeFromTextEncoder(this): returnValue = libpanda._inPmUk_sPjp(this.this) import TextNode returnObject = TextNode.TextNode(None) returnObject.this = returnValue if returnObject.this == 0: return None returnObject.userManagesMemory = 1 return returnObject return
class PNode(QGraphicsItem): def __init__(self, scene, lineCalc, lineDecorator, parent, x, y, w, h, name=None): QGraphicsItem.__init__(self, parent) self.lineCalc = lineCalc self.lineDecorator = lineDecorator self.nameTag = TextNode(self.scene, text=name, x=x + 10, y=y - 3) self.name = name self.parent = parent self.host = None self.scene = scene self.child = [] self.level = 0 #in screen coords self.contentPos = QPoint(x, y) #self.scenePos() self.setFlag(QGraphicsItem.ItemIsMovable) self.setAcceptHoverEvents(True) #width and height of content (img, text) without the arrows self.w = w self.h = h #variables for proper dragging and scaling self.resizeMode = False self.moveMode = False self.connectMode = False self.ignore = False self.lineRect = None #bounding rectangle which encapsulates the arrow to parent def getName(self): return self.name def setName(self, name): self.name = name self.nameTag.changeText(name, size=8, bold=False) def setParent(self, parent): self.parent = parent def setHost(self, host): self.host = host if self.nameTag not in self.host.parts: self.scene.addItem(self.nameTag) self.host.parts.append(self.nameTag) def getHost(self): return self.host def setLevel(self, level): self.host.level = level def getLevel(self): return self.host.level def addChild(self, node): # useless in this node, connection is establish from source node. # set connection to source Nodes. # not currently in use, connection should be establish from source. if node not in self.child: self.child.append(node) node.setParent(self) def killConnect(self): # self have connect, remove self from parent(sourceNode).child list # remove self.JackNode from host.JackNode # and removeconnect(setParent as None). self.host.clear() if self.parent is not None and self in self.parent.child: self_JackNode = self.getHost() parent_JackNode = self.parent.getHost() self.parent.child.remove(self) parent_JackNode.removeClient(self_JackNode) self_JackNode.removeHost(parent_JackNode) self.setParent(None) def selfDestory(self): self.killConnect() # self.nameTag.selfDestory() self.host.jack.pop(self.host.jack.index(self)) self.scene.removeItem(self) del self def SetX(self, x): self.prepareGeometryChange() self.contentPos.setX(x) def GetX(self): return self.contentPos.x() def SetY(self, y): self.prepareGeometryChange() self.contentPos.setY(y) def GetY(self): return self.contentPos.y() def GetWidth(self): return self.w def SetWidth(self, w): self.prepareGeometryChange() self.w = w def GetHeight(self): return self.h def SetHeight(self, h): self.prepareGeometryChange() self.h = h def contentSceneRect(self): return QRect(int(self.contentPos.x()), int(self.contentPos.y()), self.w, self.h) def contentSceneRectF(self): return QRectF(self.contentPos, QSize(self.w, self.h)) def contentRect(self): return self.mapToItem(self, self.contentSceneRect()).boundingRect() def boundingRect(self): """important method for proper redrawing and not leaving artefacts""" boundingRect = self.contentSceneRectF() # include also bounding rectangle of arrows if self.lineRect is not None: boundingRect = boundingRect.united(self.lineRect) for w in self.child: if w.lineRect is not None: boundingRect = boundingRect.united(w.lineRect) return boundingRect def mousePressEvent(self, event): # do not react on events on arrows rect = self.contentSceneRect() if not rect.contains(int(event.scenePos().x()), int(event.scenePos().y())): #ungrab mouse event.ignore() self.ignore = True return self.ignore = False if event.button() == Qt.RightButton: self.resizeMode = False if event.button() == Qt.LeftButton: self.moveMode = False def mouseReleaseEvent(self, event): if self.ignore: event.ignore() if event.button() == Qt.RightButton: self.resizeMode = False if event.button() == Qt.LeftButton: self.moveMode = False def mouseMoveEvent(self, event): if self.ignore: event.ignore() # calculate in screen coords (item coords is jerky, even.pos()) if self.resizeMode: self.prepareGeometryChange() p = event.scenePos() - self.contentPos scalex = p.x() / self.w scaley = p.y() / self.h #rescale only the content, not arrow self.w = scalex * self.w self.h = scaley * self.h self.update() if self.moveMode: # move only the content, arrow will be redrawn self.prepareGeometryChange() p = event.scenePos() - self.offset self.contentPos = p self.update() def mouseDoubleClickEvent(self, event): self.killConnect() def drawRect(self, painter, rect): painter.setPen( QPen(Qt.black, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) # painter.drawRect(rect) #draw line and decorators and recalculates bounding box def drawLine(self, painter, sourceRect, destRect): """ method for drawing line and decorators connecting parent and child node, recalculates also the line bounding box, which is used in node bounding box """ self.prepareGeometryChange() painter.setRenderHint(QPainter.Antialiasing) painter.setPen( QPen(Qt.black, 2, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) (sourcePoint, destPoint) = self.lineCalc.calcEndPoints(sourceRect, destRect) #drawing in item coordinates sourcePoint = self.mapToItem(self, sourcePoint) destPoint = self.mapToItem(self, destPoint) self.lineRect = QRectF(sourcePoint, destPoint) line = QLineF(sourcePoint, destPoint) #nothing to draw if line.length() == 0: return painter.drawLine(line) decorators = self.lineDecorator.calcDecorator(line) painter.setBrush(Qt.black) for polygon in decorators: painter.drawPolygon(polygon) self.lineRect.united(polygon.boundingRect())
class SNode(QGraphicsItem): def __init__(self, scene, lineCalc, lineDecorator, parent, x, y, w, h, name = None): QGraphicsItem.__init__(self, parent) self.lineCalc = lineCalc self.lineDecorator = lineDecorator self.nameTag = TextNode(self.scene, text = name, x = x-105, y= y-3) self.name = name self.parent = parent self.host = None self.scene = scene self.child = [] #in screen coords self.contentPos = QPoint(x,y) #self.scenePos() self.setFlag(QGraphicsItem.ItemIsMovable) self.setAcceptHoverEvents(True) #width and height of content (img, text) without the arrows self.w = w self.h = h #variables for proper dragging and scaling self.resizeMode = False self.moveMode = False self.ignore = False self.lineRect = None self.setAcceptDrops(True) #bounding rectangle which encapsulates the arrow to parent def getName(self): return self.name def setName(self, name): self.name = name self.nameTag.changeText(name, size = 8, bold = False, align = 'right') def setParent(self, parent): self.parent = parent def setHost(self, host): self.host = host if self.nameTag not in self.host.parts: self.scene.addItem(self.nameTag) self.host.parts.append(self.nameTag) def getHost(self): return self.host def setLevel(self, level): self.host.level = level def getLevel(self): return self.host.level def addChild(self, node): # kill PNode connections with others, # re-assign parent to self to establish connection. # node.killConnect() node??? node.killConnect() if node not in self.child: addCheck = self.getHost().addClient(node.getHost()) if addCheck: self.child.append(node) node.setParent(self) def killConnect(self): # self have connect, remove self from parent(sourceNode).child list # remove self.JackNode from host.JackNode # and removeconnect(setParent as None). for PlugNode in self.child: print 'a' PlugNode.killConnect() def selfDestory(self): # self.nameTag.selfDestory() self.killConnect() self.host.drain.pop(self.host.drain.index(self)) self.scene.removeItem(self) del self def SetX(self,x): self.prepareGeometryChange() self.contentPos.setX(x) def GetX(self): return self.contentPos.x() def SetY(self,y): self.prepareGeometryChange() self.contentPos.setY(y) def GetY(self): return self.contentPos.y() def GetWidth(self): return self.w def SetWidth(self,w): self.prepareGeometryChange() self.w = w def GetHeight(self): return self.h def SetHeight(self,h): self.prepareGeometryChange() self.h = h def contentSceneRect(self): return QRect(int(self.contentPos.x()), int(self.contentPos.y()), self.w, self.h) def contentSceneRectF(self): return QRectF(self.contentPos, QSize(self.w, self.h)) def contentRect(self): return self.mapToItem(self, self.contentSceneRect()).boundingRect() def boundingRect(self): boundingRect = self.contentSceneRectF() # include also bounding rectangle of arrows if self.lineRect is not None: boundingRect = boundingRect.united(self.lineRect) for w in self.child : if w.lineRect is not None: boundingRect = boundingRect.united(w.lineRect) return boundingRect def mousePressEvent(self, event): # do not react on events on arrows rect = self.contentSceneRect() if not rect.contains(int(event.scenePos().x()), int(event.scenePos().y())): #ungrab mouse event.ignore() self.ignore = True return self.ignore = False if event.button() == Qt.RightButton: self.resizeMode = False if event.button() == Qt.LeftButton: self.moveMode = False self.coursor = [event.scenePos().x(), event.scenePos().y()] self.coursorLine = 0 self.update() def mouseReleaseEvent(self, event): if self.ignore: event.ignore() if event.button() == Qt.RightButton: self.resizeMode = False if event.button() == Qt.LeftButton: self.moveMode = False self.coursorLine = 1 for i in self.scene.items(): if type(i) == PlugNode: [ ix, iy ] = [ event.scenePos().x(), event.scenePos().y() ] [ x,y,h,w ] = [ i.contentPos.x(), i.contentPos.y(), i.h, i.w ] if (x <= ix <= x+w) and (y <= iy <= y+h): if self.getHost() is not i.getHost(): self.addChild(i) self.update() def mouseMoveEvent(self, event): if self.ignore: event.ignore() # calculate in screen coords (item coords is jerky, even.pos()) if self.resizeMode: self.prepareGeometryChange() p = event.scenePos() - self.contentPos scalex = p.x()/self.w scaley = p.y()/self.h #rescale only the content, not arrow self.w = scalex * self.w self.h = scaley * self.h if self.moveMode: # move only the content, arrow will be redrawn self.prepareGeometryChange() p = event.scenePos() - self.offset self.contentPos = p self.coursor = [event.scenePos().x(), event.scenePos().y()] self.coursorLine = 0 self.update() # ---------------------------------- def binomial(self, i, n): """Binomial coefficient""" return math.factorial(n) / float( math.factorial(i) * math.factorial(n - i)) def bernstein(self, t, i, n): """Bernstein polynom""" return self.binomial(i, n) * (t ** i) * ((1 - t) ** (n - i)) def bezier(self, t, points): """Calculate coordinate of a point in the bezier curve""" n = len(points) - 1 x = y = 0 for i, pos in enumerate(points): bern = self.bernstein(t, i, n) x += pos[0] * bern y += pos[1] * bern return x, y def bezier_curve_range(self, n, points): """Range of points in a curve bezier""" for i in xrange(n): t = i / float(n - 1) yield self.bezier(t, points) def drawRect(self, painter, rect): painter.setPen(QPen(Qt.black, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) # painter.drawRect(rect) #draw line and decorators and recalculates bounding box def drawLine(self, painter, sourceRect, destRect): """ method for drawing line and decorators connecting parent and child node, recalculates also the line bounding box, which is used in node bounding box """ self.prepareGeometryChange() painter.setRenderHint(QPainter.Antialiasing) painter.setPen(QPen(Qt.black, 2, Qt.DashLine, Qt.RoundCap, Qt.RoundJoin)) (sourcePoint, destPoint) = self.lineCalc.calcEndPoints(sourceRect, destRect) #drawing in item coordinates sourcePoint = self.mapToItem(self, sourcePoint) destPoint = self.mapToItem(self, destPoint) self.lineRect = QRectF(sourcePoint, destPoint) line = QLineF(sourcePoint, destPoint) #nothing to draw if line.length() == 0: return painter.drawLine(line) # sp = sourcePoint.toTuple() # dp = destPoint.toTuple() # qm = ((sourcePoint + destPoint)/2 +sourcePoint)/2 # qm += QPointF(0.0, 45.0) # qm = qm.toTuple() # tm = ((sourcePoint + destPoint)/2 + destPoint)/2 # tm -= QPointF(0.0, 45.0) # tm = tm.toTuple() # controlPoints = (sp, qm, tm, dp) # for point in self.bezier_curve_range(1000, controlPoints): # painter.drawLine(sp[0], sp[1], point[0], point[1]) # sp = point decorators = self.lineDecorator.calcDecorator(line) painter.setBrush(Qt.black) for polygon in decorators: painter.drawPolygon(polygon) self.lineRect.united(polygon.boundingRect()) return line
class JNode(QGraphicsItem): def __init__(self, scene, lineCalc, lineDecorator, parent, x , y, w , h, name = None): QGraphicsItem.__init__(self, parent) self.Pcount = 0 self.Scount = 0 self.Swidgetcount = 0 self.scene = scene self.lineCalc = lineCalc self.lineDecorator = lineDecorator self.nameTag = TextNode(self.scene, text = name, x= x+10, y= y+5) self.nameTag.changeText(name) self.name = name self.parent = parent self.status = 0 self.temp_stat = 0 self.host = [] self.client = [] self.child = [] self.jack = [] self.drain = [] self.parts = [self.nameTag] #self.Ring, self.level = None self.script = None # self.parameters = None self.output = TypeError self.contentPos = QPoint(x,y) #self.scenePos() self.setFlag(QGraphicsItem.ItemIsMovable) self.setAcceptHoverEvents(True) self.setLevel(-1) #width and height of content (img, text) without the arrows self.x = x self.y = y self.w = w self.h = h #variables for proper dragging and scaling self.resizeMode = False self.moveMode = False self.ignore = False self.lineRect = None #bounding rectangle which encapsulates the arrow to parent def source(self, num): return self.drain[num] def plug(self, num): return self.jack[num] def setName(self, name): self.name = name self.nameTag.changeText(name) def getName(self): return self.name def setLevel(self, level): self.level = level def getLevel(self): return self.level def setStatus(self, status): self.status = status def getStatus(self): return self.status def addChild(self, node): self.child.append(node) def addHost(self, hostJack): if hostJack not in self.host: self.host.append(hostJack) def getHost(self): return self.host def removeHost(self, hostJack): self.setStatus(0) if hostJack in self.host: self.host.remove(hostJack) def setScript(self, script, parameters = []): self.script = script self.parameters = parameters def runScript(self): if self.script != None: self.parameters = [] for plug in self.jack: if plug.parent == None: # not connected,use function defaults self.parameters.append(self.script.func_defaults[self.jack.index(plug)]) elif (plug.parent.getHost().output) is TypeError: self.setStatus(3) raise TypeError else: self.parameters.append(plug.parent.getHost().output) # paremeters = [Jnode.output, ... ] if (self.parameters ) != None: self.output = self.script(*self.parameters) else: self.output = self.script() # if self.output != TypeError: # self.setName(str(self.output)) def clear(self): self.output = TypeError def selfDestory(self): self.clear() self.nameTag.selfDestory() for plug in self.jack: plug.selfDestory() for source in self.drain: source.selfDestory() if self in self.scene.JNodes: self.scene.JNodes.pop(self.scene.JNodes.index(self)) self.scene.removeItem(self) del self def addClient(self, clientJack): if clientJack not in self.client: clientJack.addHost(self) self.client.append(clientJack) # if clientJack.getLevel() <= self.getLevel(): # clientJack.setLevel(clientJack.getLevel() + self.getLevel() + 1) # for c in clientJack.client: # if c not in self.client: # self.client.append(c) # for hostJack in self.host: # hostJack.addClient(c) # c.setLevel(c.getLevel() + self.getLevel() + 1) return True # return False def removeClient(self, clientJack): if clientJack in self.client: self.client.remove(clientJack) # clientJack.setLevel(clientJack.getLevel() - self.getLevel() - 1) # for c in clientJack.client: # if c in self.client: # self.client.remove(c) # c.setLevel(c.getLevel() - self.getLevel() - 1) def addPlug(self, count = 1, name = "None"): if self.Pcount == 0: self.setLevel(0) for i in xrange(count): self.Pcount += 1 plug = PlugNode(self.scene, self.lineCalc, self.lineDecorator, x= self.x +5, y= self.y + 20 + (15) * self.Pcount, name = name) plug.setName(name) plug.setHost(self) self.jack.append(plug) self.scene.addItem(plug) if (self.Pcount - self.Scount > 1) and (self.Pcount > 2) : self.SetHeight(self.GetHeight() + 15) def addSource(self, count = 1, name = "None"): for i in xrange(count): try: self.Swidgetcount += 1 widget = self.f(name) prox = QGraphicsProxyWidget() source = SourceNode(self.scene, self.lineCalc, self.lineDecorator, x= self.x + 85, y= self.y + 12 + (30) * self.Swidgetcount, name = name) source.setName(None) prox.setWidget(widget) self.scene.addItem(prox) widget.setGeometry (self.x + 5, self.y + 4 + (30) * self.Swidgetcount,75,24) prox.contentPos = QPoint(self.x + 5, self.y + 4 + (30) * self.Swidgetcount) self.parts.append(prox) except KeyError: self.Scount += 1 source = SourceNode(self.scene, self.lineCalc, self.lineDecorator, x= self.x + 85, y= self.y+30 + (15) * self.Scount, name = name) source.setName(name) source.setHost(self) self.drain.append(source) self.scene.addItem(source) if ((self.Scount - self.Pcount >= 0 ) and (self.Scount > 1)) or self.Swidgetcount > 1: self.SetHeight(self.GetHeight() + 15 + (self.Swidgetcount-1) * 15) def f(self,x): return { 'QSpin' : QSpinBox(), 'QString': QLineEdit(), }[x] def SetX(self,x): self.prepareGeometryChange() self.contentPos.setX(x) def GetX(self): return self.contentPos.x() def SetY(self,y): self.prepareGeometryChange() self.contentPos.setY(y) def GetY(self): return self.contentPos.y() def GetWidth(self): return self.w def SetWidth(self,w): self.prepareGeometryChange() self.w = w def GetHeight(self): return self.h def SetHeight(self,h): self.prepareGeometryChange() self.h = h def contentSceneRect(self): return QRect(int(self.contentPos.x()), int(self.contentPos.y()), self.w, self.h) def contentSceneRectF(self): return QRectF(self.contentPos, QSize(self.w, self.h)) def contentRect(self): return self.mapToItem(self, self.contentSceneRect()).boundingRect() def boundingRect(self): """important method for proper redrawing and not leaving artefacts""" boundingRect = self.contentSceneRectF() if self.lineRect is not None: boundingRect = boundingRect.united(self.lineRect) for w in self.child : if w.lineRect is not None: boundingRect = boundingRect.united(w.lineRect) return boundingRect def hoverEnterEvent (self, event): event.accept() self.temp_stat = self.status self.status = 1 self.update() def hoverLeaveEvent (self, event): event.accept() self.status = self.temp_stat self.update() def mousePressEvent(self, event): # do not react on events on arrows rect = self.contentSceneRect() if not rect.contains(int(event.scenePos().x()), int(event.scenePos().y())): #ungrab mouse event.ignore() self.ignore = True return self.ignore = False if event.button() == Qt.RightButton: self.menu = QMenu() self.menu.addAction('[x] delete this Node', self.selfDestory) self.menu.addAction('[+] add input', self.addPlug) self.menu.popup(event.screenPos()) # connect(menu, SIGNAL(triggered(QAction *)),object, SLOT(triggered(QAction *))) self.resizeMode = False if event.button() == Qt.LeftButton: self.moveMode = True self.offset = event.scenePos() - self.contentPos for plug in self.jack: plug.moveMode = True plug.offset = event.scenePos() - plug.contentPos for source in self.drain: source.moveMode = True source.offset = event.scenePos() - source.contentPos for part in self.parts: if type(part) is not QGraphicsProxyWidget: part.moveMode = True part.offset = event.scenePos() - part.contentPos else: part.offset = event.scenePos() - part.contentPos def mouseReleaseEvent(self, event): if self.ignore: event.ignore() if event.button() == Qt.RightButton: self.resizeMode = False if event.button() == Qt.LeftButton: self.moveMode = False for plug in self.jack: plug.moveMode = False for source in self.drain: source.moveMode = False for part in self.parts: part.moveMode = False def mouseMoveEvent(self, event): if self.ignore: event.ignore() if self.resizeMode: self.prepareGeometryChange() p = event.scenePos() - self.contentPos scalex = p.x()/self.w scaley = p.y()/self.h #rescale only the content, not arrow self.w = scalex * self.w self.h = scaley * self.h self.update() if self.moveMode: # move only the content, arrow will be redrawn self.prepareGeometryChange() p = event.scenePos() - self.offset self.contentPos = p self.update() for plug in self.jack: plug.prepareGeometryChange() p = event.scenePos() - plug.offset plug.contentPos = p plug.update() for source in self.drain: source.prepareGeometryChange() p = event.scenePos() - source.offset source.contentPos = p source.update() for part in self.parts: if type(part) is not QGraphicsProxyWidget: part.prepareGeometryChange() p = event.scenePos() - part.offset part.contentPos = p part.update() else: part.prepareGeometryChange() p = event.scenePos() - part.offset part.contentPos = p # part.offset = event.scenePos() - part.contentPos part.setPos(event.scenePos().x() -part.offset.x(), event.scenePos().y() -part.offset.y()) part.update() def drawRect(self, painter, rect): painter.setPen(QPen(Qt.black, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) def drawLine(self, painter, sourceRect, destRect): """ method for drawing line and decorators connecting parent and child node, recalculates also the line bounding box, which is used in node bounding box """ self.prepareGeometryChange() painter.setPen(QPen(Qt.black, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) (sourcePoint, destPoint) = self.lineCalc.calcEndPoints(sourceRect, destRect) #drawing in item coordinates sourcePoint = self.mapToItem(self, sourcePoint) destPoint = self.mapToItem(self, destPoint) self.lineRect = QRectF(sourcePoint, destPoint) line = QLineF(sourcePoint, destPoint) #nothing to draw if line.length() == 0: return painter.drawLine(line) decorators = self.lineDecorator.calcDecorator(line) painter.setBrush(Qt.black) for polygon in decorators: painter.drawPolygon(polygon) self.lineRect.united(polygon.boundingRect())