22 from qtcanvas
import *
28 dispatcher=pilot.Dispatcher.getDispatcher()
31 """A text in a composite object"""
33 QCanvasText.__init__(self,canvas)
37 """The composite object which contains the text"""
40 """Request the text move by x,y"""
43 self.obj.moveBy(dx,dy)
49 QCanvasText.moveBy(self,dx,dy)
51 """The canvas item has been selected"""
57 """Create a point contained in a composite line (obj)"""
58 QCanvasEllipse.__init__(self,6,6,canvas)
63 self.setPen(QPen(Qt.black))
64 self.setBrush(QBrush(Qt.red))
71 if inline.z() >= self.z():
72 self.setZ(inline.z()+1)
75 if outline.z() >= self.z():
76 self.setZ(outline.z()+1)
79 """Request the point move by x,y"""
84 QCanvasEllipse.moveBy(self,dx,dy)
86 self.outline.setFromPoint( int(self.x()), int(self.y()) )
88 self.inline.setToPoint( int(self.x()), int(self.y()) )
91 """The object which contains the point"""
95 self.obj.deletePoint(self,pos)
101 """To remove from canvas"""
108 """The canvas item has been selected"""
111 """A line between 2 points"""
113 QCanvasLine.__init__(self,canvas)
118 self.setPen(QPen(Qt.black))
119 self.setBrush(QBrush(Qt.red))
120 self.setPoints(int(fromPoint.x()),int(fromPoint.y()), int(toPoint.x()), int(toPoint.y()))
121 self.setZ(min(fromPoint.z(),toPoint.z())-1)
122 self.setVisible(
True)
123 self.
arrow = QCanvasPolygon(self.canvas())
124 self.arrow.setBrush(QBrush(Qt.black))
129 self.setPoints(x,y,self.endPoint().x(),self.endPoint().y())
132 self.setPoints(self.startPoint().x(), self.startPoint().y(),x,y)
135 """Disable line move"""
139 x1,y1=self.startPoint().x(),self.startPoint().y()
140 x2,y2=self.endPoint().x(),self.endPoint().y()
141 d=math.hypot(x2-x1,y2-y1)
148 pa.setPoint(0, QPoint(x+l*cosa,y+l*sina))
149 pa.setPoint(1, QPoint(x-e*sina,y+e*cosa))
150 pa.setPoint(2, QPoint(x+e*sina,y-e*cosa))
151 self.arrow.setPoints(pa)
154 """The object which contains the line"""
158 self.obj.splitline(self,pos)
164 """To remove from canvas"""
169 self.arrow.setCanvas(
None)
173 """The canvas item has been selected"""
181 fromPort.addOutLink(self)
182 toPort.addInLink(self)
185 self.lines.append(
LineItem(self,fromPort, toPort,canvas))
188 """Delete intermediate point"""
189 if point
not in self.
points:
191 self.points.remove(point)
193 outline=point.outline
194 inline.toPoint=outline.toPoint
195 inline.setToPoint(outline.toPoint.x(),outline.toPoint.y())
196 self.lines.remove(outline)
197 if inline.toPoint
in self.
points:
198 inline.toPoint.setInline(inline)
205 for point
in self.
points[:]:
212 """Split line at position x,y"""
215 self.points.append(point)
216 i=self.lines.index(line)
219 if line.toPoint
in self.
points:
221 line.toPoint.setInline(newline)
222 self.lines.insert(i+1,newline)
226 point.setInline(line)
227 point.setOutline(newline)
231 first.setFromPoint(x,y)
242 caption = QLabel(
"<font color=darkblue><u><b>Link Menu</b></u></font>",menu )
243 caption.setAlignment( Qt.AlignCenter )
244 menu.insertItem( caption )
245 menu.insertItem(
"Delete", self.delete)
252 r = QRect(pos.x(), pos.y(), pos.x()+10, pos.y()+10)
253 s = QString(
"link: "+self.fromPort.port.getNode().getName() +
":"+self.fromPort.port.getName()+
"->"+self.toPort.port.getNode().getName()+
":"+self.toPort.port.getName() )
257 """The canvas item has been selected"""
259 class ControlLinkItem(LinkItem):
261 r = QRect(pos.x(), pos.y(), pos.x()+10, pos.y()+10)
262 s = QString(
"link: "+self.fromPort.port.getNode().getName()+
"->"+self.toPort.port.getNode().getName())
268 QCanvasRectangle.__init__(self,canvas)
271 self.setPen(QPen(Qt.black))
272 self.setBrush(QBrush(Qt.red))
273 self.setZ(node.z()+1)
278 self.node.moveBy(dx,dy)
281 QCanvasRectangle.moveBy(self,dx,dy)
289 caption = QLabel(
"<font color=darkblue><u><b>Port Menu</b></u></font>",menu )
290 caption.setAlignment( Qt.AlignCenter )
291 menu.insertItem( caption )
292 menu.insertItem(
"Connect", self.
connect)
296 print "ControlItem.connect",self.
context
298 item=Item.adapt(self.
port)
301 self.context.connecting(item)
311 r = QRect(pos.x(), pos.y(), self.width(), self.height())
312 s = QString(
"gate:")
316 """The canvas item has been selected"""
318 item=Item.adapt(self.
port)
323 ControlItem.__init__(self,node,port,canvas)
327 ControlItem.myMove(self,dx,dy)
329 link.setToPoint( int(self.x()), int(self.y()) )
335 if isinstance(obj,OutControlItem):
340 self.__inList.append(link)
343 r = QRect(pos.x(), pos.y(), self.width(), self.height())
344 s = QString(
"ingate:")
350 ControlItem.__init__(self,node,port,canvas)
354 ControlItem.myMove(self,dx,dy)
356 link.setFromPoint( int(self.x()), int(self.y()) )
362 if isinstance(obj,InControlItem):
367 self.__outList.append(link)
370 r = QRect(pos.x(), pos.y(), self.width(), self.height())
371 s = QString(
"outgate:")
380 QCanvasEllipse.__init__(self,6,6,canvas)
384 self.setPen(QPen(Qt.black))
385 self.setBrush(QBrush(Qt.red))
386 self.setZ(node.z()+1)
390 self.node.moveBy(dx,dy)
393 QCanvasEllipse.moveBy(self,dx,dy)
401 caption = QLabel(
"<font color=darkblue><u><b>Port Menu</b></u></font>",menu )
402 caption.setAlignment( Qt.AlignCenter )
403 menu.insertItem( caption )
404 menu.insertItem(
"Connect", self.
connect)
408 print "PortItem.connect",self.
context
410 item=Item.adapt(self.
port)
412 self.context.connecting(item)
416 print "PortItem.link:",obj
419 r = QRect(pos.x(),pos.y(),self.width(), self.height())
420 t=self.port.edGetType()
421 s = QString(
"port: " + self.port.getName() +
":" + t.name())
425 """The canvas item has been selected"""
427 item=Item.adapt(self.
port)
432 PortItem.__init__(self,node,port,canvas)
436 PortItem.myMove(self,dx,dy)
438 link.setToPoint( int(self.x()), int(self.y()) )
444 if isinstance(obj,OutPortItem):
449 self.__inList.append(link)
453 PortItem.__init__(self,node,port,canvas)
457 PortItem.myMove(self,dx,dy)
459 link.setFromPoint( int(self.x()), int(self.y()) )
465 if isinstance(obj,InPortItem):
470 self.__outList.append(link)
477 InPortItem.__init__(self,node,port,canvas)
478 self.setBrush(QBrush(Qt.green))
482 OutPortItem.__init__(self,node,port,canvas)
483 self.setBrush(QBrush(Qt.green))
489 "magenta":Qt.magenta,
490 "purple":Qt.darkMagenta,
499 QCanvasRectangle.__init__(self,canvas)
500 pypilot.PyObserver.__init__(self)
507 dispatcher.addObserver(self,node,
"status")
509 self.label.setText(self.node.getName())
510 self.label.setFont(QFont(
"Helvetica",8))
511 rect=self.label.boundingRect()
512 self.label.setZ(self.z()+1)
513 self.label.myMove(self.x()+self.width()/2-rect.width()/2,self.y()+self.height()/2-rect.height()/2)
514 color= self.colors.get(node.getColorState(node.getEffectiveState()),Qt.white)
515 self.setBrush(QBrush(color))
519 for inport
in self.node.getSetOfInputPort():
523 self.inports.append(p)
525 for instream
in self.node.getSetOfInputDataStreamPort():
529 self.inports.append(p)
535 for outport
in self.node.getSetOfOutputPort():
539 self.outports.append(p)
541 for outstream
in self.node.getSetOfOutputDataStreamPort():
545 self.outports.append(p)
554 self.inports.append(p)
558 self.outports.append(p)
565 "status":QEvent.User+1,
571 evType=self.events[event]
575 QApplication.postEvent(self.canvas(), ev)
584 if event.yacsEvent==
"status":
586 state=object.getEffectiveState()
587 color=object.getColorState(state)
588 color= self.colors.get(color,Qt.white)
589 self.setBrush(QBrush(color))
591 print "Unknown custom event type:", event.type()
594 QCanvasRectangle.moveBy(self,dx,dy)
595 self.label.myMove(dx,dy)
602 QCanvasRectangle.show(self)
614 caption = QLabel(
"<font color=darkblue><u><b>Node Menu</b></u></font>",menu )
615 caption.setAlignment( Qt.AlignCenter )
616 menu.insertItem( caption )
617 menu.insertItem(
"Browse", self.
browse)
621 r = QRect(pos.x(), pos.y(), self.width(), self.height())
622 s = QString(
"node: " + self.node.getName())
630 """The canvas item has been selected"""
632 item=Item.adapt(self.
node)