7 from GraphViewer import GraphViewer
14 class DataLinkItem(Item.Item):
15 def __init__(self,pin,pout):
18 self.label= pout.getNode().getName()+":"+pout.getName()+"->"+pin.getNode().getName()+":"+pin.getName()
20 def getIconName(self):
23 class StreamLinkItem(Item.Item):
24 def __init__(self,pin,pout):
27 self.label= pout.getNode().getName()+":"+pout.getName()+"->"+pin.getNode().getName()+":"+pin.getName()
29 def getIconName(self):
30 return "streamlink.png"
32 class ControlLinkItem(Item.Item):
33 def __init__(self,nodeup,nodedown):
34 self.nodedown=nodedown
36 self.label= nodeup.getName()+"->"+nodedown.getName()
38 def getIconName(self):
39 return "controllink.png"
41 class ControlLinksItem(Item.Item):
42 """Item pour les liens controle d'un noeud compose"""
43 def __init__(self,item):
45 self.label="Control Links"
46 def getIconName(self):
48 def isExpandable(self):
50 def getChildren(self):
52 for n in self.item.node.edGetDirectDescendants():
53 for p in n.getOutNodes():
54 sublist.append(ControlLinkItem(n,p))
57 class DataLinksItem(Item.Item):
58 """Item pour les liens data d'un noeud compose"""
59 def __init__(self,item):
61 self.label="Data Links"
63 def getIconName(self):
66 def isExpandable(self):
69 def getChildren(self):
71 for pout,pin in self.item.node.getSetOfInternalLinks():
72 if pout.getNode().getFather() != self.item.node and pin.getNode().getFather() != self.item.node:
74 if isinstance(pin,pilot_InputDataStreamPort):
75 sublist.append(StreamLinkItem(pin,pout))
77 sublist.append(DataLinkItem(pin,pout))
78 #for pout,pin in self.item.node.getSetOfLinksLeavingCurrentScope():
79 # sublist.append(DataLinkItem(pin,pout))
80 #for pin,pout in self.item.node.getSetOfLinksComingInCurrentScope():
81 # sublist.append(DataLinkItem(pin,pout))
84 class MyCanvas(QCanvas):
85 def customEvent(self,event):
87 object.customEvent(event)
90 class ItemComposedNode(Item.Item):
91 """Item pour les noeuds composes"""
93 def __init__(self,node):
94 #node is an instance of YACS::ENGINE::ComposedNode
96 self.label=node.getName()
98 def isExpandable(self):
101 def getChildren(self):
102 #liste des noeuds fils
103 liste=self.node.edGetDirectDescendants()
104 #On les adapte en item avant de les retourner
108 sublist.append(adapt.adapt(n,Item.Item))
111 #traceback.print_exc()
113 sublist.append(DataLinksItem(self))
114 sublist.append(ControlLinksItem(self))
117 def getIconName(self):
120 def panel(self,parent):
121 """Retourne un tab widget pour browser/editer la proc"""
122 tabWidget = QTabWidget( parent )
123 for name,method in self.panels:
124 tabWidget.addTab( method(self,tabWidget), name )
129 ItemComposedNode.n=ItemComposedNode.n+1
130 n1=r.createScriptNode("","unknown_%d" % ItemComposedNode.n)
131 node=CItems.Cell(n1,self.canvas)
133 self.citems[n1.ptr()]=node
136 def panel1(self,parent):
138 #Canvas size : 10000x10000
139 self.canvas=MyCanvas(10000,10000)
140 self.editor=GraphViewer(self,self.canvas,qvbox,"example",0)
142 #permet de retrouver un item node dans le canvas a partir
143 #d'un proxy swig quelconque (astuce)
144 #Pour retrouver un item node faire : citems[node.ptr()]
147 #permet de retrouver un item port dans le canvas a partir
148 #d'un proxy swig quelconque (astuce)
149 #Pour retrouver un item port faire : pitems[port.ptr()]
154 lnode=self.node.edGetDirectDescendants()
156 c=CItems.Cell(n,self.canvas)
160 for k,n in citems.items():
162 pitems[p.port.ptr()]=p
164 pitems[p.port.ptr()]=p
166 for pout,pin in self.node.getSetOfInternalLinks():
167 if pout.getNode().getFather() != self.node and pin.getNode().getFather() != self.node:
169 po=pitems.get(pout.ptr())
170 pi=pitems.get(pin.ptr())
172 CItems.LinkItem(po,pi,self.canvas)
175 itemup=citems[n.ptr()]
176 for ndown in n.getOutNodes():
177 itemdown=citems[ndown.ptr()]
178 CItems.ControlLinkItem(itemup.outgate,itemdown.ingate,self.canvas)
184 panels=[("Panel1",panel1)]
186 def layout(self,rankdir):
187 """Compute graph layout with graphviz package"""
188 G=pygraphviz.AGraph(strict=False,directed=True)
189 G.graph_attr["rankdir"]=rankdir
190 for k,n in self.citems.items():
191 #k est l'adresse du node (YACS)
192 #n est l'item dans le canvas
195 for pout,pin in self.node.getSetOfInternalLinks():
196 if pout.getNode().ptr() not in self.citems :
198 if pin.getNode().ptr() not in self.citems:
200 G.add_edge(pout.getNode().ptr(),pin.getNode().ptr())
202 for k,n in self.citems.items():
203 for ndown in n.node.getOutNodes():
204 G.add_edge(n.node.ptr(),ndown.ptr())
206 #By default graphviz uses 96.0 pixel per inch (dpi=96.0)
208 item=self.citems[int(n)]
209 h=item.height()/96. #height in inch
210 w=item.width()/96. #width in inch
211 n.attr['height']=str(h)
212 n.attr['width']=str(w)
213 n.attr['fixedsize']="true"
214 n.attr['shape']="box"
215 #n.attr['label']=item.node.getName()
217 G.layout(prog='dot') # use dot
218 #G.write("layout.dot")
219 #G.draw("layout.png")
221 #from pygraphviz import graphviz as gv
222 #bbox= gv.agget(G.handle,"bb")#bounding box to resize
223 #x1,y1,x2,y2=eval(bbox)
224 #self.canvas.resize(w,h)
227 pos=n.attr['pos'] #position is given in points (72 points par inch, so 1 point = 96./72=1.34)
231 item=self.citems[int(n)]
232 # x0=item.x()+item.width()/2.
233 # y0=item.y()+item.height()/2.
242 class ItemProc(ItemComposedNode):
243 """Item pour la procedure"""
245 class ItemPort(Item.Item):
246 """Item pour les ports """
248 def __init__(self,port):
250 self.label=port.getName()
252 def getIconName(self):
255 def panel(self,parent):
256 """Retourne un tab widget pour browser/editer l'item"""
257 tabWidget = QTabWidget( parent )
258 for name,method in self.panels:
259 tabWidget.addTab( method(self,tabWidget), name )
262 class ItemInPort(ItemPort):
263 def getIconName(self):
266 def panel1(self,parent):
268 qvbox.layout().setAlignment(Qt.AlignTop|Qt.AlignLeft)
269 qvbox.setSpacing( 5 )
271 label=QLabel("Name: ",row0)
272 lined0 = QLineEdit(self.port.getName(),row0)
273 label=QLabel("Type: ",row0)
274 QLineEdit(self.port.edGetType().name(),row0)
276 label=QLabel("Value: ",qvbox)
277 #self.value=QLabel("Empty",qvbox)
278 self.value=QTextEdit(qvbox)
279 self.value.setText("Empty")
280 if not self.port.isEmpty():
281 self.value.setText(self.port.dump())
284 but2=QPushButton( "Refresh", row3 )
285 qvbox.connect( but2, SIGNAL("clicked()"), self.handleRefresh )
289 def handleRefresh(self):
290 if not self.port.isEmpty():
291 self.value.setText(self.port.dump())
293 panels=[("Panel1",panel1)]
295 class ItemOutPort(ItemPort):
296 def getIconName(self):
299 def panel1(self,parent):
301 qvbox.layout().setAlignment(Qt.AlignTop|Qt.AlignLeft)
302 qvbox.setSpacing( 5 )
305 QLabel("Name: ",row0)
306 QLineEdit(self.port.getName(),row0)
307 QLabel("Type: ",row0)
308 QLineEdit(self.port.edGetType().name(),row0)
310 QLabel("Value: ",qvbox)
311 self.value=QTextEdit(qvbox)
312 self.value.setText("Empty")
314 self.value.setText(self.port.dump())
316 traceback.print_exc()
319 but2=QPushButton( "Refresh", row3 )
320 qvbox.connect( but2, SIGNAL("clicked()"), self.handleRefresh )
324 def handleRefresh(self):
326 self.value.setText(self.port.dump())
328 traceback.print_exc()
330 panels=[("Panel1",panel1)]
333 class ItemInStream(ItemPort):
334 def getIconName(self):
335 return "instream.png"
336 class ItemOutStream(ItemPort):
337 def getIconName(self):
338 return "outstream.png"
340 class ItemNode(Item.Item):
341 """Item pour les noeuds elementaires
344 #attr donnant la liste des panels du noeud (nom,method)
346 def __init__(self,node):
348 self.label=node.getName()
350 def isExpandable(self):
353 def getChildren(self):
355 for n in self.node.getSetOfInputPort():
356 sublist.append(adapt.adapt(n,Item.Item))
357 for n in self.node.getSetOfOutputPort():
358 sublist.append(adapt.adapt(n,Item.Item))
359 for n in self.node.getSetOfInputDataStreamPort():
360 sublist.append(adapt.adapt(n,Item.Item))
361 for n in self.node.getSetOfOutputDataStreamPort():
362 sublist.append(adapt.adapt(n,Item.Item))
365 def panel(self,parent):
366 """Retourne un tab widget pour browser/editer l'item"""
367 tabWidget = QTabWidget( parent )
368 for name,method in self.panels:
369 tabWidget.addTab( method(self,tabWidget), name )
372 class ItemScriptNode(ItemNode):
374 def panel1(self,parent):
376 qvbox.setSpacing( 5 )
379 label=QLabel("Name: ",row0)
380 lined0 = QLineEdit(self.node.getName(),row0)
382 label=QLabel("Script: ",qvbox)
383 mle=Editor.Editor(qvbox,"multiLineEdit" )
384 mle.setText(self.node.getScript())
387 but1=QPushButton( "Save", row2 )
388 but2=QPushButton( "Cancel", row2 )
389 qvbox.connect( but1, SIGNAL("clicked()"), self.handleSave )
390 qvbox.connect( but2, SIGNAL("clicked()"), self.handleCancel )
394 panels=[("Panel1",panel1)]
396 def getIconName(self):
399 def handleSave(self):
400 self.node.setScript(str(self.mle.text()))
401 def handleCancel(self):
402 self.lined0.setText(self.node.getName())
403 self.mle.setText(self.node.getScript())
405 class ItemFuncNode(ItemNode):
406 def panel1(self,parent):
407 """Retourne un widget pour browser/editer l'item"""
409 qvbox.setSpacing( 5 )
412 label=QLabel("Name: ",row0)
413 self.lined0 = QLineEdit(self.node.getName(),row0)
416 label=QLabel("Fname: ",row1)
417 self.lined1 = QLineEdit(self.node.getFname(),row1)
419 label=QLabel("Function: ",qvbox)
420 self.mle=Editor.Editor(qvbox,"multiLineEdit" )
421 self.mle.setText(self.node.getScript())
424 but1=QPushButton( "Save", row2 )
425 but2=QPushButton( "Cancel", row2 )
426 qvbox.connect( but1, SIGNAL("clicked()"), self.handleSave )
427 qvbox.connect( but2, SIGNAL("clicked()"), self.handleCancel )
431 panels=[("Panel1",panel1)]
433 def getIconName(self):
435 def FuncChanged(self, newText ):
436 self.myFunc=str(newText)
438 def handleSave(self):
439 self.node.setFname(str(self.lined1.text()))
440 self.node.setScript(str(self.mle.text()))
441 def handleCancel(self):
442 self.lined0.setText(self.node.getName())
443 self.lined1.setText(self.node.getFname())
444 self.mle.setText(self.node.getScript())
446 class ItemService(ItemNode):
447 def panel1(self,parent):
448 """Retourne un widget pour browser/editer l'item"""
449 self.myName=self.node.getName()
452 qvbox.layout().setAlignment(Qt.AlignTop|Qt.AlignLeft)
453 qvbox.setSpacing( 5 )
456 label=QLabel("Name: ",row0)
457 self.lined0 = QLineEdit(self.node.getName(),row0)
458 qvbox.connect( self.lined0, SIGNAL("textChanged(const QString &)"), self.NameChanged )
459 qvbox.connect( self.lined0, SIGNAL("returnPressed()"), self.NameReturn )
460 QToolTip.add( self.lined0, "Node name" )
463 label1=QLabel("Ref: ",row1)
464 self.lined1 = QLineEdit(row1)
465 if self.node.getComponent():
466 self.lined1.setText(self.node.getComponent().getName())
468 self.lined1.setText("NO_COMPONENT_NAME")
471 label2=QLabel("Method: ",row2)
472 self.lined2 = QLineEdit(row2)
473 self.lined2.setText(self.node.getMethod())
476 but1=QPushButton( "Save", row3 )
477 but2=QPushButton( "Cancel", row3 )
478 qvbox.connect( but1, SIGNAL("clicked()"), self.handleSave )
479 qvbox.connect( but2, SIGNAL("clicked()"), self.handleCancel )
483 panels=[("Panel1",panel1)]
485 def NameChanged(self, newText ):
486 self.myName=str(newText)
488 def NameReturn(self):
491 def getIconName(self):
492 return "green-square"
494 def handleSave(self):
495 self.node.setRef(str(self.lined1.text()))
496 self.node.setMethod(str(self.lined2.text()))
497 def handleCancel(self):
498 self.lined0.setText(self.node.getName())
499 self.lined1.setText(self.node.getComponent().getName())
500 self.lined2.setText(self.node.getMethod())
502 def adapt_Proc_to_Item(obj, protocol, alternate):
505 def adapt_Node_to_Item(obj, protocol, alternate):
508 def adapt_ComposedNode_to_Item(obj, protocol, alternate):
509 return ItemComposedNode(obj)
511 def adapt_InlineFuncNode_to_Item(obj, protocol, alternate):
512 return ItemFuncNode(obj)
514 def adapt_InlineScriptNode_to_Item(obj, protocol, alternate):
515 return ItemScriptNode(obj)
517 def adapt_ServiceNode_to_Item(obj, protocol, alternate):
518 return ItemService(obj)
520 def adapt_Port_to_Item(obj, protocol, alternate):
523 def adapt_InPort_to_Item(obj, protocol, alternate):
524 return ItemInPort(obj)
526 def adapt_OutPort_to_Item(obj, protocol, alternate):
527 return ItemOutPort(obj)
529 def adapt_InStream_to_Item(obj, protocol, alternate):
530 return ItemInStream(obj)
532 def adapt_OutStream_to_Item(obj, protocol, alternate):
533 return ItemOutStream(obj)
535 if hasattr(pilot,"ProcPtr"):
536 adapt.registerAdapterFactory(pilot.ProcPtr, Item.Item, adapt_Proc_to_Item)
537 adapt.registerAdapterFactory(pilot.BlocPtr, Item.Item, adapt_ComposedNode_to_Item)
538 adapt.registerAdapterFactory(pilot.ForLoopPtr, Item.Item, adapt_ComposedNode_to_Item)
539 adapt.registerAdapterFactory(pilot.WhileLoopPtr, Item.Item, adapt_ComposedNode_to_Item)
540 adapt.registerAdapterFactory(pilot.ForEachLoopPtr, Item.Item, adapt_ComposedNode_to_Item)
541 adapt.registerAdapterFactory(pilot.SwitchPtr, Item.Item, adapt_ComposedNode_to_Item)
542 adapt.registerAdapterFactory(pilot.ComposedNodePtr, Item.Item, adapt_ComposedNode_to_Item)
544 adapt.registerAdapterFactory(pilot.ServiceNodePtr, Item.Item, adapt_ServiceNode_to_Item)
545 #adapt.registerAdapterFactory(pilot.ServiceNodeNodePtr, Item.Item, adapt_Node_to_Item)
546 adapt.registerAdapterFactory(pilot.InlineNodePtr, Item.Item, adapt_InlineScriptNode_to_Item)
547 adapt.registerAdapterFactory(pilot.InlineFuncNodePtr, Item.Item, adapt_InlineFuncNode_to_Item)
548 adapt.registerAdapterFactory(pilot.NodePtr, Item.Item, adapt_Node_to_Item)
550 adapt.registerAdapterFactory(pilot.OutputPortPtr, Item.Item, adapt_OutPort_to_Item)
551 adapt.registerAdapterFactory(pilot.InputPortPtr, Item.Item, adapt_InPort_to_Item)
552 adapt.registerAdapterFactory(pilot.OutputDataStreamPortPtr, Item.Item, adapt_OutStream_to_Item)
553 adapt.registerAdapterFactory(pilot.InputDataStreamPortPtr, Item.Item, adapt_InStream_to_Item)
555 pilot_InputDataStreamPort=pilot.InputDataStreamPortPtr
558 adapt.registerAdapterFactory(pilot.Proc, Item.Item, adapt_Proc_to_Item)
559 adapt.registerAdapterFactory(pilot.Bloc, Item.Item, adapt_ComposedNode_to_Item)
560 adapt.registerAdapterFactory(pilot.ForLoop, Item.Item, adapt_ComposedNode_to_Item)
561 adapt.registerAdapterFactory(pilot.WhileLoop, Item.Item, adapt_ComposedNode_to_Item)
562 adapt.registerAdapterFactory(pilot.ForEachLoop, Item.Item, adapt_ComposedNode_to_Item)
563 adapt.registerAdapterFactory(pilot.Switch, Item.Item, adapt_ComposedNode_to_Item)
564 adapt.registerAdapterFactory(pilot.ComposedNode, Item.Item, adapt_ComposedNode_to_Item)
566 adapt.registerAdapterFactory(pilot.ServiceNode, Item.Item, adapt_ServiceNode_to_Item)
567 #adapt.registerAdapterFactory(pilot.ServiceNodeNode, Item.Item, adapt_Node_to_Item)
568 adapt.registerAdapterFactory(pilot.InlineNode, Item.Item, adapt_InlineScriptNode_to_Item)
569 adapt.registerAdapterFactory(pilot.InlineFuncNode, Item.Item, adapt_InlineFuncNode_to_Item)
570 adapt.registerAdapterFactory(pilot.Node, Item.Item, adapt_Node_to_Item)
572 adapt.registerAdapterFactory(pilot.OutputPort, Item.Item, adapt_OutPort_to_Item)
573 adapt.registerAdapterFactory(pilot.InputPort, Item.Item, adapt_InPort_to_Item)
574 adapt.registerAdapterFactory(pilot.OutputDataStreamPort, Item.Item, adapt_OutStream_to_Item)
575 adapt.registerAdapterFactory(pilot.InputDataStreamPort, Item.Item, adapt_InStream_to_Item)
577 pilot_InputDataStreamPort=pilot.InputDataStreamPort