Salome HOME
0f1b30b588751cfa39017940517383e9fc4fc271
[tools/eficas.git] / InterfaceQT4 / browser.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import string,re
22 import types,sys,os
23 import traceback
24 import typeNode
25 import pdb
26 from PyQt4 import *
27 from PyQt4.QtGui  import *
28 from PyQt4.QtCore import *
29 from Extensions.i18n import tr
30 from gereRegles import GereRegles
31 from monChoixCommande import MonChoixCommande
32
33 class JDCTree( QTreeWidget,GereRegles ):
34     def __init__( self, jdc_item, QWParent):        
35         #if hasattr(QWParent,'widgetTree') : 
36         self.editor        = QWParent
37         self.plie=False
38         if self.editor.widgetTree !=None  :
39            QTreeWidget.__init__(self, self.editor.widgetTree ) 
40            self.editor.verticalLayout_2.addWidget(self)
41            if self.editor.enteteQTree=='complet':
42                  self.headerItem().setText(0,  "Commande   ")
43                  self.headerItem().setText(1, "Concept/Valeur")
44            else :
45                  self.headerItem().setText(0,  "Commande   ")
46            self.setColumnWidth(0,200)
47            self.setExpandsOnDoubleClick(False)
48            self.setSelectionMode(3)
49         else :
50            QTreeWidget.__init__(self, None ) 
51         self.item          = jdc_item
52         self.tree          = self        
53         self.appliEficas   = self.editor.appliEficas
54         self.childrenComplete=[]
55         self.racine=self.item.itemNode(self,self.item)
56  
57         self.itemCourrant=None
58
59         self.connect(self, SIGNAL("itemClicked ( QTreeWidgetItem * ,int) "), self.handleOnItem)
60         self.connect(self, SIGNAL("itemCollapsed ( QTreeWidgetItem *) "), self.handleCollapsedItem)
61         self.connect(self, SIGNAL("itemExpanded ( QTreeWidgetItem *) "), self.handleExpandedItem)
62
63         #PNPNPN verifier dans quel cas on se trouve : affiche l arbre ou la commande
64         self.node_selected=self.racine
65         self.inhibeExpand=True
66         self.expandItem(self.racine)
67         self.inhibeExpand=False
68         #print "self.editor.afficheCommandesPliees", self.editor.afficheCommandesPliees
69         if self.racine.children !=[] :  
70
71             
72            if self.editor.afficheCommandesPliees : self.racine.children[0].plieToutEtReaffiche()
73            else : self.racine.children[0].deplieToutEtReaffiche()
74         
75
76            self.racine.children[0].fenetre.donnePremier()
77         else : self.racine.affichePanneau()
78         #PNPNPN
79         #pdb.set_trace()
80
81     def contextMenuEvent(self,event) :
82         #print "contextMenuEvent"
83         coord=event.globalPos()
84         item= self.currentItem()
85         self.handleContextMenu(item,coord)
86
87     def handleContextMenu(self,item,coord):
88         """
89         Private slot to show the context menu of the listview.
90         
91         @param itm the selected listview item (QListWidgetItem)
92         @param coord the position of the mouse pointer (QPoint)
93         Attention : existeMenu permet de savoir si un menu est associe a cet item
94         """
95         #print "handleContextMenu"
96         if item == None : return
97         if item.existeMenu == 0 : return
98         if item.menu == None:
99            item.createPopUpMenu()
100         if item.menu != None:
101            if item.item.get_nom() == "DISTRIBUTION" and item.item.isvalid() :
102               item.Graphe.setEnabled(1)
103            item.menu.exec_(coord)            
104             
105
106     def handleCollapsedItem(self,item):
107         #print "dans CollapsedItem", self.inhibeExpand  
108         if self.inhibeExpand == True : return
109         # On traite le cas de l item non selectionne
110         itemParent=item
111         while not (hasattr (itemParent,'getPanel')) : 
112            itemParent=itemParent.treeParent 
113         if self.tree.node_selected != itemParent : 
114              item.setExpanded(False)
115              return
116
117         itemParent=item
118         item.setPlie()
119         item.plieToutEtReaffiche()
120         item.select()
121
122     def handleExpandedItem(self,item):
123         #print "handleExpandedItem pour ", item.item.nom, self.inhibeExpand
124         if self.inhibeExpand == True : return
125         itemParent=item
126         while not (hasattr (itemParent,'getPanel')) : 
127            if itemParent.plie==True : itemParent.setDeplie()
128            itemParent=itemParent.treeParent 
129         if self.tree.node_selected != itemParent : 
130              item.setExpanded(True)
131              return
132         item.deplieToutEtReaffiche()
133
134
135     def handleOnItem(self,item,int):
136         #print "je passe dans handleOnItem pour ",self, item.item.nom, item, item.item
137         self.inhibeExpand == True 
138         self.itemCourrant=item
139         itemParent=item
140         while not (hasattr (itemParent,'getPanel')) : 
141            if itemParent.plie==True : itemParent.setDeplie()
142            itemParent=itemParent.treeParent 
143         if itemParent.fenetre != self.editor.fenetreCentraleAffichee : 
144              # il faut afficher le parent
145             if self.editor.afficheCommandesPliees : itemParent.plieToutEtReafficheSaufItem(item)
146             else :                                  itemParent.affichePanneau()
147
148
149         from InterfaceQT4 import composimp
150         if (isinstance(item,composimp.Node)) and item.fenetre : item.fenetre.rendVisible()
151         elif itemParent!=item:
152              #self.tree.handleExpandedItem(item)
153              #item.fenetre.donnePremier()
154              #item.fenetre.rendActif()
155              print 'il faut afficher le 1er'
156         try :
157            fr = item.item.get_fr()
158            if self.editor: self.editor.labelCommentaire.setText(unicode(fr))
159         except:
160             pass
161         item.select()
162         self.inhibeExpand == False 
163         #print "je mets inhibeExpand a false handleOnItem"
164
165
166     def choisitPremier(self,name):
167         self.editor.layoutJDCCHOIX.removeWidget(self.racine.fenetre)
168         self.racine.fenetre.close()
169         new_node=self.racine.append_brother(name,'after')
170  
171 # type de noeud
172 COMMENT     = "COMMENTAIRE"
173 PARAMETERS  = "PARAMETRE"
174  
175 class JDCNode(QTreeWidgetItem,GereRegles):
176     def __init__( self, treeParent, item, itemExpand=False, ancien=False ):
177         #print "creation d'un noeud : ", item, " ",item.nom,"", treeParent, self
178         #self.a=0
179         self.item        = item
180         self.vraiParent  = treeParent
181         self.treeParent  = treeParent
182         self.tree        = self.treeParent.tree
183         self.editor      = self.treeParent.editor
184         self.appliEficas = treeParent.appliEficas
185         self.JESUISOFF=0
186         self.childrenComplete=[]
187                         
188         from InterfaceQT4 import compocomm
189         from InterfaceQT4 import compoparam
190         from InterfaceQT4 import composimp
191         if   (isinstance(self.item,compocomm.COMMTreeItem)) : name=tr("Commentaire")
192         elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=self.appliEficas.trUtf8(str(item.GetLabelText()[0]))
193         else:   name  = self.appliEficas.trUtf8(str(tr( item.nom))+" :")
194         value = self.appliEficas.trUtf8(str( item.GetText() ) )
195  
196
197         mesColonnes=QStringList()
198         if self.editor.enteteQTree=='complet': mesColonnes <<  name << value
199         else : mesColonnes <<  name
200
201         if self.treeParent.plie==True :
202             self.plie        = True
203             self.appartientAUnNoeudPlie=True
204         else :
205             self.plie        = False
206             self.appartientAUnNoeudPlie = False
207
208         if ancien and itemExpand     : self.plie = False
209         if ancien and not itemExpand : self.plie = True 
210         if (isinstance(self.item,composimp.SIMPTreeItem)) : self.plie=False
211
212         from InterfaceQT4 import compobloc
213         from InterfaceQT4 import compomclist
214
215         ajoutAuParentduNoeud=0
216         self.treeParent=treeParent
217         while (isinstance(self.treeParent,compobloc.Node) or ( isinstance(self.treeParent,compomclist.Node) and self.treeParent.item.isMCList())) : 
218               self.treeParent.childrenComplete.append(self)
219               self.treeParent=self.treeParent.vraiParent
220         self.treeParent.childrenComplete.append(self)
221         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
222            QTreeWidgetItem.__init__(self,None,mesColonnes)
223         else :
224            QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
225
226         self.setToolTip(0,QString(self.item.get_fr()))
227         self.setToolTip(1,QString(self.item.get_fr()))
228
229         repIcon=QString(self.appliEficas.repIcon)
230         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
231         self.setIcon(0,monIcone)
232
233         self.children = []
234         self.build_children()
235         self.menu=None
236         self.existeMenu=1
237
238         self.item.connect("valid",self.onValid,())
239         self.item.connect("supp" ,self.onSupp,())
240         self.item.connect("add"  ,self.onAdd,())
241
242         self.state=""
243         self.fenetre=None
244         try :
245           if self.item.getObject().isBLOC() : 
246                 self.setExpanded(True) 
247                 self.plie=False
248         except :
249           pass
250
251
252     def build_children(self,posInsertion=10000):
253         """ Construit la liste des enfants de self """
254         """ Se charge de remettre les noeuds Expanded dans le meme etat """
255         #print "*********** build_children ",self,self.item, self.item.nom
256         
257         self.listeItemExpanded=[]
258         self.listeItemPlie=[]
259
260         for enfant in self.childrenComplete :
261             if enfant.plie : self.listeItemPlie.append(enfant.item)
262             else : self.listeItemExpanded.append(enfant.item)
263
264         for enfant in self.childrenComplete :
265             p=enfant.vraiParent
266             parent=enfant.treeParent
267             parent.removeChild(enfant)
268             enfant.JESUISOFF=1
269          
270         
271         self.children = []
272         self.childrenComplete = []
273         sublist = self.item._GetSubList()
274         ind=0
275         
276         for item in sublist :
277             itemExpand=False
278             ancien=False
279             if item in self.listeItemExpanded : itemExpand=True;  ancien=True
280             if item in self.listeItemPlie     : itemExpand=False; ancien=True
281             nouvelItem=item.itemNode(self,item,itemExpand,ancien)
282             self.children.append(nouvelItem)
283
284         #print "fin *********** build_children ",self,self.item, self.item.nom
285
286         
287     def chercheNoeudCorrespondant(self,objSimp):
288         sublist = self.item._GetSubList()
289         for node in self.childrenComplete:
290             if node.item.object==objSimp : return node
291         return None
292
293
294     def affichePanneau(self) :
295         #print " affichePanneau " , self.item.nom 
296         if self.item.isactif(): 
297            itemParent=self
298            while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent 
299            if itemParent!=self : 
300               itemParent.affichePanneau()
301               return
302            self.fenetre=self.getPanel()
303         else:
304             from monInactifPanel import PanelInactif
305             self.fenetre = PanelInactif(self,self.editor)
306          
307         for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
308             widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
309             self.editor.widgetCentraleLayout.removeItem(widget)
310         # ceinture et bretelle
311         #print 'old fenetre = ',self.editor.fenetreCentraleAffichee
312         if self.editor.fenetreCentraleAffichee != None : 
313             #print "j enleve ", self.editor.fenetreCentraleAffichee, self.editor.fenetreCentraleAffichee.node.item.nom
314             self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
315             self.editor.fenetreCentraleAffichee.close()
316
317         self.editor.widgetCentraleLayout.addWidget(self.fenetre)
318         #print "j ajoute ", self.fenetre, self.fenetre.node.item.nom
319         self.editor.fenetreCentraleAffichee=self.fenetre
320         self.tree.node_selected= self
321
322         if self.editor.first :
323            self.editor.splitter.setSizes((400,1400,400))
324            if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
325         self.tree.inhibeExpand=True
326         self.tree.expandItem(self)
327         self.select()
328         self.tree.inhibeExpand=False
329         #print "fin de affichePanneau", self.item.nom
330         #print "______________________________"
331           
332
333     def createPopUpMenu(self):
334         #implemente dans les noeuds derives si necessaire
335         self.existeMenu = 0
336
337     def commentIt(self):
338         """
339         Cette methode a pour but de commentariser la commande pointee par self
340         """
341         # On traite par une exception le cas ou l'utilisateur final cherche a désactiver
342         # (commentariser) un commentaire.
343         try :
344             pos=self.treeParent.children.index(self)
345             commande_comment = self.item.get_objet_commentarise()
346             # On signale a l editeur du panel (le JDCDisplay) une modification
347             self.editor.init_modif()
348             self.treeParent.build_children()
349             self.treeParent.children[pos].select()
350             self.treeParent.children[pos].affichePanneau()
351         except Exception,e:
352             traceback.print_exc()
353             QMessageBox.critical( self.editor, "TOO BAD",str(e))
354         
355     def unCommentIt(self):
356         """
357         Realise la decommentarisation de self
358         """
359         try :
360             pos=self.treeParent.children.index(self)
361             commande,nom = self.item.uncomment()
362             self.editor.init_modif()
363             self.treeParent.build_children()
364             self.treeParent.children[pos].select()
365             self.treeParent.children[pos].affichePanneau()
366         except Exception,e:
367             QMessageBox.critical( self.editor, "Erreur !",str(e))
368         
369     def addComment( self, after=True ):
370         """
371         Ajoute un commentaire a l'interieur du JDC :
372         """
373         self.editor.init_modif()
374         if after:
375             pos = 'after'
376         else:
377             pos = 'before'
378         return self.append_brother( COMMENT, pos )
379                 
380     def addParameters( self, after=True ):
381         """
382         Ajoute un parametre a l'interieur du JDC :
383         """
384         self.editor.init_modif()
385         if after: pos = 'after'
386         else: pos = 'before'
387         child=self.append_brother( PARAMETERS, pos )
388         return  child
389     
390     
391     def select( self ):
392         """
393         Rend le noeud courant (self) selectionne et deselectionne
394         tous les autres
395         """        
396         for item in self.tree.selectedItems() :
397             item.setSelected(0)
398         self.setSelected( True )    
399         self.tree.setCurrentItem( self )    
400                                
401     #------------------------------------------------------------------
402     # Methodes de creation et destruction de noeuds
403     # Certaines de ces methodes peuvent etre appelees depuis l'externe
404     #------------------------------------------------------------------
405     def append_brother(self,name,pos='after',plier=False):
406         """
407         Permet d'ajouter un objet frere a l'objet associe au noeud self
408         par defaut on l'ajoute immediatement apres 
409         Methode externe
410         """
411         self.editor.init_modif()
412
413         from InterfaceQT4 import compojdc
414         if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos)  : return 0
415         
416         index = self.treeParent.children.index(self)
417         if   pos == 'before': index = index
418         elif pos == 'after': index = index +1
419         else:
420             print unicode(pos), tr("  n'est pas un index valide pour append_brother")
421             return 0
422         return self.treeParent.append_child(name,pos=index,plier=plier)
423
424     def verifiePosition(self,name,pos,aLaRacine=False):
425         if name not in self.editor.Classement_Commandes_Ds_Arbre : return True
426         indexName=self.editor.Classement_Commandes_Ds_Arbre.index(name)
427
428         etapes=self.item.get_jdc().etapes
429         if etapes == [] : return True
430
431         if aLaRacine == False :indexOu=etapes.index(self.item.object)
432         else : indexOu=0
433
434         if pos=="after" : indexOu = indexOu+1
435         for e in etapes[:indexOu] :
436             nom=e.nom
437             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
438             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
439             if indexEtape > indexName :
440                comment=tr('le mot clef ')+name+tr(' doit etre insere avant ')+nom
441                QMessageBox.information( None,tr('insertion impossible'),comment, )
442                return False
443         for e in etapes[indexOu:] :
444             nom=e.nom
445             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
446             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
447             if indexEtape < indexName :
448                comment=tr('le mot clef ')+name+tr(' doit etre insere apres ')+nom
449                QMessageBox.information( None,tr('insertion impossible'),comment, )
450                return False
451         return True
452
453     def append_child(self,name,pos=None,plier=False):
454         """
455            Methode pour ajouter un objet fils a l'objet associe au noeud self.
456            On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
457            ou en position intermediaire.
458            Si pos vaut None, on le place a la position du catalogue.
459         """
460         #print "************** append_child ",self.item.GetLabelText(), plier
461
462          
463         self.editor.init_modif()
464         if pos == 'first':
465             index = 0
466         elif pos == 'last':
467             index = len(self.children)
468         elif type(pos) == types.IntType :
469             # position fixee
470             index = pos
471         elif type(pos) == types.InstanceType:
472             # pos est un item. Il faut inserer name apres pos
473             index = self.item.get_index(pos) +1
474         elif type(name) == types.InstanceType:
475             index = self.item.get_index_child(name.nom)
476         else:
477             index = self.item.get_index_child(name)
478
479         # si on essaye d inserer a la racine
480         if (isinstance(self.treeParent,JDCTree) and index==0) :
481            verifiePosition=self.verifiePosition(name,'first',aLaRacine=True)
482            if not verifiePosition : return 0
483
484         self.tree.inhibeExpand=True
485         obj=self.item.additem(name,index) #CS_pbruno emet le signal 'add'
486         if obj is None:obj=0
487         if obj == 0:return 0
488         try :
489            child=self.children[index]
490            if plier == True : child.setPlie()
491            else             : child.setDeplie() 
492         except :
493            child=self.children[index]
494         self.tree.inhibeExpand=False
495         #print " fin append child"
496         return child
497
498     def deplace(self):
499         self.editor.init_modif()
500         index = self.treeParent.children.index(self) - 1 
501         if index < 0 : index =0
502         ret=self.treeParent.item.deplaceEntite(self.item.getObject())
503
504     def delete(self):
505         """ 
506             Methode externe pour la destruction de l'objet associe au noeud
507         """
508         self.editor.init_modif()
509         index = self.vraiParent.children.index(self) - 1 
510         if index < 0 : index =0
511         recalcule=0
512         if self.item.nom == "VARIABLE" :
513            recalcule=1
514            jdc=self.item.jdc
515         ret,commentaire=self.vraiParent.item.suppitem(self.item)
516         if ret==0 :
517           self.editor.affiche_infos(commentaire,Qt.red)
518         else :
519           self.editor.affiche_infos(commentaire)
520         self.treeParent.build_children()
521         if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
522         else: toselect=self.treeParent
523         if recalcule : jdc.recalcule_etat_correlation()
524         from InterfaceQT4 import compojdc
525         # cas ou on detruit dans l arbre sans affichage
526         if isinstance(self.treeParent,compojdc.Node) : 
527            toselect.affichePanneau()
528         else :
529            if self.treeParent.fenetre== None : return
530            #print "J appelle reaffiche de browser apres delete"
531            self.treeParent.fenetre.reaffiche(toselect)
532
533     def deleteMultiple(self,liste=()):
534         """ 
535             Methode externe pour la destruction d une liste de noeud
536         """
537         from InterfaceQT4 import compojdc 
538         self.editor.init_modif()
539         index=9999
540         recalcule=0
541         jdc=self.treeParent
542         parentPosition=jdc
543         while not(isinstance(jdc,compojdc.Node)):
544               jdc=jdc.treeParent
545         for noeud in liste :
546             if not( isinstance(noeud.treeParent, compojdc.Node)): continue
547             if noeud.item.nom == "VARIABLE" : recalcule=1
548             if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
549         if index < 0 : index =0
550
551         # Cas ou on détruit dans une ETape
552         if index == 9999 : 
553               parentPosition=self.treeParent
554               while not(isinstance(parentPosition, compojdc.Node)):
555                  index=parentPosition.treeParent.children.index(parentPosition)
556                  parentPosition=parentPosition.treeParent
557
558         for noeud in liste:
559             noeud.treeParent.item.suppitem(noeud.item)
560
561         jdc.build_children()
562         if recalcule : jdc.recalcule_etat_correlation()
563         try    : toselect=parentPosition.children[index]
564         except : toselect=jdc
565         toselect.select()
566         toselect.affichePanneau()
567 #        
568 #    #------------------------------------------------------------------
569     def onValid(self):        
570
571         #print "onValid pour ", self.item.nom
572         if hasattr(self,'fenetre') and self.fenetre: self.fenetre.setValide()
573         if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isvalid():
574            self.item.jdc.recalcule_etat_correlation()
575         if hasattr(self.item,'forceRecalcul'):
576            self.forceRecalculChildren(self.item.forceRecalcul)
577         self.editor.init_modif()
578         
579         self.update_node_valid()
580         self.update_node_label()
581         self.update_node_texte()
582
583     def onAdd(self,object):
584         if self.JESUISOFF==1 : return
585         #print "onAdd pour ", self.item.nom, object.nom
586         self.editor.init_modif()
587         self.update_nodes()
588         # PN -- non necessaire si item=jdc
589         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
590  
591     def onSupp(self,object):
592         if self.JESUISOFF==1 : return
593         #print "onSup pour ", self.item.nom, object.nom
594         self.editor.init_modif()
595         self.update_nodes()
596         # PN -- non necessaire si item=jdc
597         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
598          
599
600
601
602     def update_node_valid(self):
603         """Cette methode remet a jour la validite du noeud (icone)
604            Elle appelle isvalid
605         """
606         repIcon=QString(self.appliEficas.repIcon)
607         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
608         self.setIcon(0,monIcone)
609
610
611     def update_node_label(self):
612         """ Met a jour le label du noeud """
613         #print "NODE update_node_label", self.item.GetLabelText()
614         labeltext,fonte,couleur = self.item.GetLabelText()
615         # PNPN a reflechir
616         #self.setText(0, labeltext)        
617     
618     
619     def update_node_label_in_blue(self):
620         if hasattr(self.appliEficas,'noeudColore'):
621            self.appliEficas.noeudColore.setTextColor( 0,Qt.black)
622            self.appliEficas.noeudColore.update_node_label()
623         self.setTextColor( 0,Qt.blue )
624         labeltext,fonte,couleur = self.item.GetLabelText()
625         self.setText(0, labeltext)        
626         self.appliEficas.noeudColore=self
627
628     def update_plusieurs_node_label_in_blue(self,liste):
629         if hasattr(self.appliEficas,'listeNoeudsColores'):
630            for noeud in self.appliEficas.listeNoeudsColores:
631                noeud.setTextColor( 0,Qt.black)
632                noeud.update_node_label()
633         self.appliEficas.listeNoeudsColores=[]
634         for noeud in liste :
635             noeud.setTextColor( 0,Qt.blue )
636             labeltext,fonte,couleur = noeud.item.GetLabelText()
637             noeud.setText(0, labeltext)        
638             self.appliEficas.listeNoeudsColores.append(noeud)
639
640     def update_node_texte_in_black(self):
641         """ Met a jour les noms des SD et valeurs des mots-cles """
642         self.setTextColor( 1,Qt.black )
643         value = self.item.GetText()
644         self.setText(1, value)
645
646     def update_node_texte(self):
647         """ Met a jour les noms des SD et valeurs des mots-cles """
648         value = self.item.GetText()
649         self.setText(1, value)
650         
651
652     def update_node_texte_in_blue(self):
653         self.setTextColor( 1,Qt.blue )
654         value = self.item.GetText()
655         self.setText(1, value)
656
657     def update_nodes(self):
658         #print 'NODE update_nodes', self.item.GetLabelText()
659         self.build_children()
660
661     def update_valid(self) :
662         """Cette methode a pour but de mettre a jour la validite du noeud
663            et de propager la demande de mise a jour a son parent
664         """
665         #print "NODE update_valid", self.item.GetLabelText()
666         self.update_node_valid()
667         try :
668           self.treeParent.update_valid()
669         except:
670           pass
671             
672     def update_texte(self):
673         """ Met a jour les noms des SD et valeurs des mots-cles """
674         #print "NODE update_texte", self.item.GetLabelText()
675         self.update_node_texte()
676         if self.isExpanded() :
677             for child in self.children:
678                 if child.isHidden() == false : child.update_texte()
679
680
681     def forceRecalculChildren(self,niveau):
682         if self.state=='recalcule' : 
683            self.state=""
684            return
685         self.state='recalcule'
686         if hasattr(self.item,'object'):
687            self.item.object.state="modified"
688         for child in self.children:
689            if niveau > 0 : child.forceRecalculChildren(niveau - 1)
690               
691         
692
693     def doPaste(self,node_selected,pos='after'):
694         """
695             Déclenche la copie de l'objet item avec pour cible
696             l'objet passé en argument : node_selected
697         """
698         #print 'je passe dans doPaste'
699         objet_a_copier = self.item.get_copie_objet()
700         child=node_selected.doPasteCommande(objet_a_copier,pos)
701         return child
702
703     def doPasteCommande(self,objet_a_copier,pos='after'):
704         """
705           Réalise la copie de l'objet passé en argument qui est nécessairement
706           une commande
707         """
708         child=None
709         try :
710           child = self.append_brother(objet_a_copier,pos)
711         except :
712            pass
713         return child
714
715     def doPastePremier(self,objet_a_copier):
716         """
717            Réalise la copie de l'objet passé en argument (objet_a_copier)
718         """
719         objet = objet_a_copier.item.get_copie_objet()
720         child = self.append_child(objet,pos='first')
721         return child
722
723     def plieToutEtReafficheSaufItem(self, itemADeplier):
724         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
725         self.editor.deplier = False
726         for item in self.children :
727             # il ne faut pas plier les blocs 
728             from InterfaceQT4 import compobloc
729             if (isinstance(item,compobloc.Node)) : continue
730             item.setPlie()
731             if item==itemADeplier : 
732                   print itemADeplier.item.nom
733                   itemADeplier.setDeplie()
734         
735         self.affichePanneau()
736
737     def plieToutEtReaffiche(self):
738         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
739         self.editor.deplier = False
740         for item in self.children :
741             # il ne faut pas plier les blocs 
742             from InterfaceQT4 import compobloc
743             if (isinstance(item,compobloc.Node)) : continue
744             item.setPlie()
745         self.affichePanneau()
746
747     def deplieToutEtReaffiche(self):
748         self.editor.deplier = True
749         for item in self.children :
750             item.setDeplie()
751         self.affichePanneau()
752
753     def setPlie(self):
754         #print "je mets inhibeExpand a true dans setPlie"
755         #print "je suis dans plieTout", self.item.get_nom()
756         import compojdc
757         if self.fenetre == self.editor.fenetreCentraleAffichee  and isinstance(self.treeParent,compojdc.Node): 
758            return
759         self.tree.inhibeExpand=True
760         self.tree.collapseItem(self)
761         self.setPlieChildren()
762         self.tree.inhibeExpand=False
763         #print "je mets inhibeExpand a false dans setPlie"
764
765
766         # on ne plie pas au niveau 1
767         #   self.plie=False
768         #   for item in self.children :
769         #       item.appartientAUnNoeudPlie=False
770
771     def setPlieChildren(self):
772         #print "dans setPlieChildren pour", self.item.nom
773         self.plie=True
774         for c in self.children :
775             c.setPlieChildren()
776             #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0]
777             c.appartientAUnNoeudPlie=True
778             c.plie=True
779             #print "dans setPlieChildren plie", c.item.nom
780             c.setExpanded(False)
781
782         # Pour les blocs et les motcles list
783         # on affiche un niveau de plus
784         from InterfaceQT4 import compobloc
785         from InterfaceQT4 import compomclist
786         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
787             niveauPere=self.treeParent
788             while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) : 
789                niveauPere=niveauPere.treeParent
790             for c in self.children :
791                 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
792                 c.setExpanded(False)
793
794         # on affiche un niveau de plus
795         #if isinstance(self,compomclist.Node)  : 
796         #if isinstance(self,compobloc.Node)  : 
797         #    niveauPere=self.treeParent
798         #    while (isinstance(niveauPere,compobloc.Node)):
799         #       niveauPere=niveauPere.treeParent
800         #    for c in self.children :
801         #        c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
802
803     def setDeplie(self):
804         #print "dans setPlieChildren pour", self.item.nom
805         #print "je mets inhibeExpand a true dans setDeplie"
806         self.tree.inhibeExpand=True
807         self.plie=False
808         self.tree.expandItem(self)
809         self.setDeplieChildren()
810         self.tree.inhibeExpand=False
811         #print "je mets inhibeExpand a false dans setDePlie"
812
813     def setDeplieChildren(self):
814         #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.GetLabelText()
815         for c in self.children :
816             c.setDeplieChildren()
817             #print "dans setDeplieChildren ", c.item.nom
818             c.appartientAUnNoeudPlie=False
819             c.setExpanded(True)
820             c.plie=False
821        
822     def selectAvant(self):
823         i=self.item.jdc.etapes.index(self.item.object)
824         try :
825            cherche=self.item.jdc.etapes[i-1]
826         except :
827            cherche=self.item.jdc.etapes[-1]
828         node=None
829         for i in self.tree.racine.children :
830             if i.item.object== cherche  : 
831                node=i
832                break
833         if node : node.affichePanneau()
834
835     def selectApres(self):
836         i=self.item.jdc.etapes.index(self.item.object)
837         try :
838            cherche=self.item.jdc.etapes[i+1]
839         except :
840            cherche=self.item.jdc.etapes[0]
841         node=None
842         for i in self.tree.racine.children :
843             if i.item.object== cherche  : 
844                node=i
845                break
846         if node : node.affichePanneau()