22 from qtcanvas
import *
27 QToolTip.__init__( self, parent )
30 pos2=self.parentWidget().viewportToContents(pos)
31 point = self.parentWidget().inverseWorldMatrix().map(pos2)
32 ilist = self.parentWidget().
canvas().collisions(point)
33 for each_item
in ilist:
34 if hasattr(each_item,
"tooltip"):
35 each_item.tooltip(self,pos)
37 elif hasattr(each_item,
"getObj"):
38 each_item.getObj().tooltip(self,pos)
43 QCanvasView.__init__(self,c,parent,name,f)
48 self.
selectPen=QPen(QColor(255,255,0),2,Qt.DashLine)
55 point = self.inverseWorldMatrix().map(e.pos())
56 ilist = self.canvas().collisions(point)
57 for each_item
in ilist:
58 if each_item.rtti()==984376:
59 if not each_item.hit(point):
61 if e.button()== Qt.LeftButton:
62 if hasattr(each_item,
"handleDoubleClick"):
63 each_item.handleDoubleClick(point)
64 self.canvas().update()
70 point = self.inverseWorldMatrix().map(e.pos())
71 ilist = self.canvas().collisions(point)
72 for each_item
in ilist:
73 if each_item.rtti()==984376:
74 if not each_item.hit(point):
76 if e.button()== Qt.RightButton:
80 if hasattr(each_item,
"popup"):
81 menu=each_item.popup(self)
83 menu.exec_loop( QCursor.pos() )
84 self.canvas().update()
85 elif hasattr(each_item,
"getObj"):
86 menu=each_item.getObj().
popup(self)
88 menu.exec_loop( QCursor.pos() )
89 self.canvas().update()
91 elif e.button()== Qt.LeftButton:
95 if hasattr(each_item,
"getObj"):
97 self.__connecting.link(each_item.getObj().item)
99 self.canvas().update()
106 self.canvas().update()
108 if e.button()== Qt.RightButton:
111 menu.exec_loop( QCursor.pos() )
112 self.canvas().update()
115 QCanvasView.contentsMousePressEvent(self,e)
126 for citem
in self.canvas().allItems():
127 if hasattr(citem,
"item")
and citem.item
is item:
131 self.canvas().update()
135 obj._origPen = obj.pen()
136 obj._origBrush = obj.brush()
137 obj._origStyle = obj.brush().style()
143 obj.setPen(obj._origPen)
148 caption = QLabel(
"<font color=darkblue><u><b>View Menu</b></u></font>", self )
149 caption.setAlignment( Qt.AlignCenter )
150 menu.insertItem( caption )
151 menu.insertItem(
"add Node", self.
addNode)
161 self.repaintContents(
True)
168 m = self.worldMatrix()
170 self.setWorldMatrix( m )
173 m = self.worldMatrix()
175 self.setWorldMatrix( m )
178 ilist = self.canvas().allItems()
179 for each_item
in ilist:
181 each_item.setCanvas(
None)
183 self.canvas().update()
186 """Method called by an item to notify canvasView a connection has begun"""
187 print "connecting",obj
192 point = self.inverseWorldMatrix().map(e.pos())
193 self.__moving.moveBy(point.x()-self.__moving_start.x(),point.y()-self.__moving_start.y())
195 self.canvas().update()
198 QCanvasView.contentsMouseMoveEvent(self,e)
202 QCanvasRectangle.__init__(self,canvas)
207 self.setSize(self.image.width(), self.image.height())
208 self.pixmap.convertFromImage(self.
image, Qt.OrderedAlphaDither);
216 if not self.image.valid( ix , iy ):
218 self.
pixel = self.image.pixel( ix, iy )
219 return (qAlpha( self.
pixel ) != 0)
222 p.drawPixmap( self.x(), self.y(), self.
pixmap )
226 QCanvasLine.__init__(self,canvas)
227 self.setPen(QPen(Qt.black))
228 self.setBrush(QBrush(Qt.red))
229 fromPort.addOutLink(self)
230 toPort.addInLink(self)
231 self.setPoints(int(fromPort.x()),int(fromPort.y()), int(toPort.x()), int(toPort.y()))
232 self.setZ(min(fromPort.z(),toPort.z())-1)
233 self.setVisible(
True)
234 self.
arrow = QCanvasPolygon(self.canvas())
235 self.arrow.setBrush(QBrush(Qt.black))
240 self.setPoints(x,y,self.endPoint().x(),self.endPoint().y())
244 self.setPoints(self.startPoint().x(), self.startPoint().y(),x,y)
251 x1,y1=self.startPoint().x(),self.startPoint().y()
252 x2,y2=self.endPoint().x(),self.endPoint().y()
253 d=math.hypot(x2-x1,y2-y1)
259 pa.setPoint(0, QPoint(x+10*cosa,y+10*sina))
260 pa.setPoint(1, QPoint(x-5*sina,y+5*cosa))
261 pa.setPoint(2, QPoint(x+5*sina,y-5*cosa))
262 self.arrow.setPoints(pa)
266 caption = QLabel(
"<font color=darkblue><u><b>Node Menu</b></u></font>",menu )
267 caption.setAlignment( Qt.AlignCenter )
268 menu.insertItem( caption )
269 menu.insertItem(
"Delete", self.
delete)
276 r = QRect(pos.x(), pos.y(), pos.x()+10, pos.y()+10)
277 s = QString(
"link: %d,%d" % (r.center().x(), r.center().y()) )
282 QCanvasEllipse.__init__(self,6,6,canvas)
283 self.setPen(QPen(Qt.black))
284 self.setBrush(QBrush(Qt.red))
285 self.setZ(node.z()+1)
289 self.node.moveBy(dx,dy)
292 QCanvasEllipse.moveBy(self,dx,dy)
300 caption = QLabel(
"<font color=darkblue><u><b>Port Menu</b></u></font>",menu )
301 caption.setAlignment( Qt.AlignCenter )
302 menu.insertItem( caption )
303 menu.insertItem(
"Connect", self.
connect)
308 self.context.connecting(self)
314 r = QRect(self.x(), self.y(), self.width(), self.height())
315 s = QString(
"port: %d,%d" % (r.center().x(), r.center().y()) )
320 PortItem.__init__(self,node,canvas)
324 PortItem.myMove(self,dx,dy)
326 link.setToPoint( int(self.x()), int(self.y()) )
330 if isinstance(obj,OutPortItem):
335 self.__inList.append(link)
339 PortItem.__init__(self,node,canvas)
343 PortItem.myMove(self,dx,dy)
345 link.setFromPoint( int(self.x()), int(self.y()) )
349 if isinstance(obj,InPortItem):
354 self.__outList.append(link)
358 QCanvasRectangle.__init__(self,canvas)
366 self.inports.append(p)
369 self.outports.append(p)
372 QCanvasRectangle.moveBy(self,dx,dy)
379 QCanvasRectangle.show(self)
390 caption = QLabel(
"<font color=darkblue><u><b>Node Menu</b></u></font>",menu )
391 caption.setAlignment( Qt.AlignCenter )
392 menu.insertItem( caption )
393 menu.insertItem(
"Browse", self.
browse)
397 r = QRect(self.x(), self.y(), self.width(), self.height())
398 s = QString(
"node: %d,%d" % (r.center().x(), r.center().y()) )
407 if __name__==
'__main__':
408 app=QApplication(sys.argv)
410 QToolBar(box,
"toolbar")
412 canvas.setAdvancePeriod(30)
414 box.setCentralWidget(m)
421 c1.outports[0].link(c2.inports[0])
423 qApp.setMainWidget(box)