Salome HOME
PourLaura
[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         self.inhibeExpand == False 
134
135
136     def handleOnItem(self,item,int):
137         print "je passe dans handleOnItem pour ",self, item.item.nom, item, item.item
138         
139         from InterfaceQT4 import composimp
140         self.inhibeExpand == True 
141         self.itemCourrant=item
142         itemParent=item
143
144         while not (hasattr (itemParent,'getPanel')) : 
145            if itemParent.plie==True : itemParent.setDeplie()
146            itemParent=itemParent.treeParent 
147
148         if itemParent.fenetre != self.editor.fenetreCentraleAffichee : 
149               
150             estUneFeuille=(isinstance(item,composimp.Node))
151              # il faut afficher le parent
152             print "estUneFeuille", estUneFeuille
153             print "afficheCommandesPliees", self.editor.afficheCommandesPliees
154             if estUneFeuille                        : itemParent.affichePanneau()
155             elif self.editor.afficheCommandesPliees : itemParent.plieToutEtReafficheSaufItem(item)
156             else                                    : itemParent.affichePanneau()
157
158
159         if (isinstance(item,composimp.Node)) and item.fenetre : item.fenetre.rendVisible()
160         elif itemParent!=item:
161              #self.tree.handleExpandedItem(item)
162              #item.fenetre.donnePremier()
163              #item.fenetre.rendActif()
164              print 'il faut afficher le 1er'
165         try :
166            fr = item.item.get_fr()
167            if self.editor: self.editor.labelCommentaire.setText(unicode(fr))
168         except:
169             pass
170         item.select()
171         self.inhibeExpand == False 
172         #print "je mets inhibeExpand a false handleOnItem"
173
174
175     def choisitPremier(self,name):
176         self.editor.layoutJDCCHOIX.removeWidget(self.racine.fenetre)
177         self.racine.fenetre.close()
178         new_node=self.racine.append_brother(name,'after')
179  
180 # type de noeud
181 COMMENT     = "COMMENTAIRE"
182 PARAMETERS  = "PARAMETRE"
183  
184 class JDCNode(QTreeWidgetItem,GereRegles):
185     def __init__( self, treeParent, item, itemExpand=False, ancien=False ):
186         #print "creation d'un noeud : ", item, " ",item.nom,"", treeParent, self
187         #self.a=0
188         self.item        = item
189         self.vraiParent  = treeParent
190         self.treeParent  = treeParent
191         self.tree        = self.treeParent.tree
192         self.editor      = self.treeParent.editor
193         self.appliEficas = treeParent.appliEficas
194         self.JESUISOFF=0
195         self.childrenComplete=[]
196
197                         
198         from InterfaceQT4 import compocomm
199         from InterfaceQT4 import compoparam
200         from InterfaceQT4 import composimp
201         if   (isinstance(self.item,compocomm.COMMTreeItem)) : name=tr("Commentaire")
202         elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=self.appliEficas.trUtf8(str(item.GetLabelText()[0]))
203         else:   name  = self.appliEficas.trUtf8(str(tr( item.nom))+" :")
204         value = self.appliEficas.trUtf8(str( item.GetText() ) )
205  
206
207         mesColonnes=QStringList()
208         if self.editor.enteteQTree=='complet': mesColonnes <<  name << value
209         else : mesColonnes <<  name
210
211         if self.treeParent.plie==True :
212             self.plie        = True
213             self.appartientAUnNoeudPlie=True
214         else :
215             self.plie        = False
216             self.appartientAUnNoeudPlie = False
217
218         if ancien and itemExpand     : self.plie = False
219         if ancien and not itemExpand : self.plie = True 
220         if (isinstance(self.item,composimp.SIMPTreeItem)) : self.plie=False
221
222         from InterfaceQT4 import compobloc
223         from InterfaceQT4 import compomclist
224
225         ajoutAuParentduNoeud=0
226         self.treeParent=treeParent
227         while (isinstance(self.treeParent,compobloc.Node) or ( isinstance(self.treeParent,compomclist.Node) and self.treeParent.item.isMCList())) : 
228               self.treeParent.childrenComplete.append(self)
229               self.treeParent=self.treeParent.vraiParent
230         self.treeParent.childrenComplete.append(self)
231         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
232            QTreeWidgetItem.__init__(self,None,mesColonnes)
233         else :
234            QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
235
236         self.setToolTip(0,QString(self.item.get_fr()))
237         self.setToolTip(1,QString(self.item.get_fr()))
238
239         repIcon=QString(self.appliEficas.repIcon)
240         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
241         self.setIcon(0,monIcone)
242
243         self.children = []
244         self.build_children()
245         self.menu=None
246         self.existeMenu=1
247
248         self.item.connect("valid",self.onValid,())
249         self.item.connect("supp" ,self.onSupp,())
250         self.item.connect("add"  ,self.onAdd,())
251
252         self.state=""
253         self.fenetre=None
254         try :
255           if self.item.getObject().isBLOC() : 
256                 self.setExpanded(True) 
257                 self.plie=False
258         except :
259           pass
260
261
262     def build_children(self,posInsertion=10000):
263         """ Construit la liste des enfants de self """
264         """ Se charge de remettre les noeuds Expanded dans le meme etat """
265         #print "*********** build_children ",self,self.item, self.item.nom
266         
267         self.listeItemExpanded=[]
268         self.listeItemPlie=[]
269
270         for enfant in self.childrenComplete :
271             if enfant.plie : self.listeItemPlie.append(enfant.item)
272             else : self.listeItemExpanded.append(enfant.item)
273
274         for enfant in self.childrenComplete :
275             p=enfant.vraiParent
276             parent=enfant.treeParent
277             parent.removeChild(enfant)
278             enfant.JESUISOFF=1
279          
280         
281         self.children = []
282         self.childrenComplete = []
283         sublist = self.item._GetSubList()
284         ind=0
285         
286         for item in sublist :
287             itemExpand=False
288             ancien=False
289             if item in self.listeItemExpanded : itemExpand=True;  ancien=True
290             if item in self.listeItemPlie     : itemExpand=False; ancien=True
291             nouvelItem=item.itemNode(self,item,itemExpand,ancien)
292             self.children.append(nouvelItem)
293
294         #print "fin *********** build_children ",self,self.item, self.item.nom
295
296         
297     def chercheNoeudCorrespondant(self,objSimp):
298         sublist = self.item._GetSubList()
299         for node in self.childrenComplete:
300             if node.item.object==objSimp : return node
301         return None
302
303
304     def affichePanneau(self) :
305         #print " affichePanneau " , self.item.nom 
306         if self.item.isactif(): 
307            itemParent=self
308            while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent 
309            if itemParent!=self : 
310               itemParent.affichePanneau()
311               return
312            self.fenetre=self.getPanel()
313         else:
314             from monInactifPanel import PanelInactif
315             self.fenetre = PanelInactif(self,self.editor)
316          
317         for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
318             widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
319             self.editor.widgetCentraleLayout.removeItem(widget)
320         # ceinture et bretelle
321         #print 'old fenetre = ',self.editor.fenetreCentraleAffichee
322         if self.editor.fenetreCentraleAffichee != None : 
323             #print "j enleve ", self.editor.fenetreCentraleAffichee, self.editor.fenetreCentraleAffichee.node.item.nom
324             self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
325             self.editor.fenetreCentraleAffichee.close()
326
327         self.editor.widgetCentraleLayout.addWidget(self.fenetre)
328         #print "j ajoute ", self.fenetre, self.fenetre.node.item.nom
329         self.editor.fenetreCentraleAffichee=self.fenetre
330         self.tree.node_selected= self
331
332         if self.editor.first :
333            self.editor.splitter.setSizes((400,1400,400))
334            if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
335         self.tree.inhibeExpand=True
336         self.tree.expandItem(self)
337         #self.select()
338         self.tree.inhibeExpand=False
339         #print "fin de affichePanneau", self.item.nom
340         #print "______________________________"
341           
342
343     def createPopUpMenu(self):
344         #implemente dans les noeuds derives si necessaire
345         self.existeMenu = 0
346
347     def commentIt(self):
348         """
349         Cette methode a pour but de commentariser la commande pointee par self
350         """
351         # On traite par une exception le cas ou l'utilisateur final cherche a désactiver
352         # (commentariser) un commentaire.
353         try :
354             pos=self.treeParent.children.index(self)
355             commande_comment = self.item.get_objet_commentarise()
356             # On signale a l editeur du panel (le JDCDisplay) une modification
357             self.editor.init_modif()
358             self.treeParent.build_children()
359             self.treeParent.children[pos].select()
360             self.treeParent.children[pos].affichePanneau()
361         except Exception,e:
362             traceback.print_exc()
363             QMessageBox.critical( self.editor, "TOO BAD",str(e))
364         
365     def unCommentIt(self):
366         """
367         Realise la decommentarisation de self
368         """
369         try :
370             pos=self.treeParent.children.index(self)
371             commande,nom = self.item.uncomment()
372             self.editor.init_modif()
373             self.treeParent.build_children()
374             self.treeParent.children[pos].select()
375             self.treeParent.children[pos].affichePanneau()
376         except Exception,e:
377             QMessageBox.critical( self.editor, "Erreur !",str(e))
378         
379     def addComment( self, after=True ):
380         """
381         Ajoute un commentaire a l'interieur du JDC :
382         """
383         self.editor.init_modif()
384         if after:
385             pos = 'after'
386         else:
387             pos = 'before'
388         return self.append_brother( COMMENT, pos )
389                 
390     def addParameters( self, after=True ):
391         """
392         Ajoute un parametre a l'interieur du JDC :
393         """
394         self.editor.init_modif()
395         if after: pos = 'after'
396         else: pos = 'before'
397         child=self.append_brother( PARAMETERS, pos )
398         return  child
399     
400     
401     def select( self ):
402         """
403         Rend le noeud courant (self) selectionne et deselectionne
404         tous les autres
405         """        
406         print "select pour", self.item.nom
407         for item in self.tree.selectedItems() :
408             item.setSelected(0)
409         self.tree.setCurrentItem( self )    
410                                
411     #------------------------------------------------------------------
412     # Methodes de creation et destruction de noeuds
413     # Certaines de ces methodes peuvent etre appelees depuis l'externe
414     #------------------------------------------------------------------
415     def append_brother(self,name,pos='after',plier=False):
416         """
417         Permet d'ajouter un objet frere a l'objet associe au noeud self
418         par defaut on l'ajoute immediatement apres 
419         Methode externe
420         """
421         self.editor.init_modif()
422
423         from InterfaceQT4 import compojdc
424         if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos)  : return 0
425         
426         index = self.treeParent.children.index(self)
427         if   pos == 'before': index = index
428         elif pos == 'after': index = index +1
429         else:
430             print unicode(pos), tr("  n'est pas un index valide pour append_brother")
431             return 0
432         return self.treeParent.append_child(name,pos=index,plier=plier)
433
434     def verifiePosition(self,name,pos,aLaRacine=False):
435         if name not in self.editor.Classement_Commandes_Ds_Arbre : return True
436         indexName=self.editor.Classement_Commandes_Ds_Arbre.index(name)
437
438         etapes=self.item.get_jdc().etapes
439         if etapes == [] : return True
440
441         if aLaRacine == False :indexOu=etapes.index(self.item.object)
442         else : indexOu=0
443
444         if pos=="after" : indexOu = indexOu+1
445         for e in etapes[:indexOu] :
446             nom=e.nom
447             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
448             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
449             if indexEtape > indexName :
450                comment=tr('le mot clef ')+name+tr(' doit etre insere avant ')+nom
451                QMessageBox.information( None,tr('insertion impossible'),comment, )
452                return False
453         for e in etapes[indexOu:] :
454             nom=e.nom
455             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
456             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
457             if indexEtape < indexName :
458                comment=tr('le mot clef ')+name+tr(' doit etre insere apres ')+nom
459                QMessageBox.information( None,tr('insertion impossible'),comment, )
460                return False
461         return True
462
463     def append_child(self,name,pos=None,plier=False):
464         """
465            Methode pour ajouter un objet fils a l'objet associe au noeud self.
466            On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
467            ou en position intermediaire.
468            Si pos vaut None, on le place a la position du catalogue.
469         """
470         #print "************** append_child ",self.item.GetLabelText(), plier
471
472          
473         self.editor.init_modif()
474         if pos == 'first':
475             index = 0
476         elif pos == 'last':
477             index = len(self.children)
478         elif type(pos) == types.IntType :
479             # position fixee
480             index = pos
481         elif type(pos) == types.InstanceType:
482             # pos est un item. Il faut inserer name apres pos
483             index = self.item.get_index(pos) +1
484         elif type(name) == types.InstanceType:
485             index = self.item.get_index_child(name.nom)
486         else:
487             index = self.item.get_index_child(name)
488
489         # si on essaye d inserer a la racine
490         if (isinstance(self.treeParent,JDCTree) and index==0) :
491            verifiePosition=self.verifiePosition(name,'first',aLaRacine=True)
492            if not verifiePosition : return 0
493
494         self.tree.inhibeExpand=True
495         obj=self.item.additem(name,index) #CS_pbruno emet le signal 'add'
496         if obj is None:obj=0
497         if obj == 0:return 0
498         try :
499            child=self.children[index]
500            if plier == True : child.setPlie()
501            else             : child.setDeplie() 
502         except :
503            child=self.children[index]
504         self.tree.inhibeExpand=False
505         #print " fin append child"
506         return child
507
508     def deplace(self):
509         self.editor.init_modif()
510         index = self.treeParent.children.index(self) - 1 
511         if index < 0 : index =0
512         ret=self.treeParent.item.deplaceEntite(self.item.getObject())
513
514     def delete(self):
515         """ 
516             Methode externe pour la destruction de l'objet associe au noeud
517         """
518         self.editor.init_modif()
519         index = self.vraiParent.children.index(self) - 1 
520         if index < 0 : index =0
521         recalcule=0
522         if self.item.nom == "VARIABLE" :
523            recalcule=1
524            jdc=self.item.jdc
525         ret,commentaire=self.vraiParent.item.suppitem(self.item)
526         if ret==0 :
527           self.editor.affiche_infos(commentaire,Qt.red)
528         else :
529           self.editor.affiche_infos(commentaire)
530         self.treeParent.build_children()
531         if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
532         else: toselect=self.treeParent
533         if recalcule : jdc.recalcule_etat_correlation()
534         from InterfaceQT4 import compojdc
535         # cas ou on detruit dans l arbre sans affichage
536         if isinstance(self.treeParent,compojdc.Node) : 
537            toselect.affichePanneau()
538         else :
539            if self.treeParent.fenetre== None : return
540            #print "J appelle reaffiche de browser apres delete"
541            self.treeParent.fenetre.reaffiche(toselect)
542
543     def deleteMultiple(self,liste=()):
544         """ 
545             Methode externe pour la destruction d une liste de noeud
546         """
547         from InterfaceQT4 import compojdc 
548         self.editor.init_modif()
549         index=9999
550         recalcule=0
551         jdc=self.treeParent
552         parentPosition=jdc
553         while not(isinstance(jdc,compojdc.Node)):
554               jdc=jdc.treeParent
555         for noeud in liste :
556             if not( isinstance(noeud.treeParent, compojdc.Node)): continue
557             if noeud.item.nom == "VARIABLE" : recalcule=1
558             if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
559         if index < 0 : index =0
560
561         # Cas ou on détruit dans une ETape
562         if index == 9999 : 
563               parentPosition=self.treeParent
564               while not(isinstance(parentPosition, compojdc.Node)):
565                  index=parentPosition.treeParent.children.index(parentPosition)
566                  parentPosition=parentPosition.treeParent
567
568         for noeud in liste:
569             noeud.treeParent.item.suppitem(noeud.item)
570
571         jdc.build_children()
572         if recalcule : jdc.recalcule_etat_correlation()
573         try    : toselect=parentPosition.children[index]
574         except : toselect=jdc
575         toselect.select()
576         toselect.affichePanneau()
577 #        
578 #    #------------------------------------------------------------------
579     def onValid(self):        
580
581         #print "onValid pour ", self.item.nom
582         if hasattr(self,'fenetre') and self.fenetre: self.fenetre.setValide()
583         if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isvalid():
584            self.item.jdc.recalcule_etat_correlation()
585         if hasattr(self.item,'forceRecalcul'):
586            self.forceRecalculChildren(self.item.forceRecalcul)
587         self.editor.init_modif()
588         
589         self.update_node_valid()
590         self.update_node_label()
591         self.update_node_texte()
592
593     def onAdd(self,object):
594         if self.JESUISOFF==1 : return
595         #print "onAdd pour ", self.item.nom, object.nom
596         self.editor.init_modif()
597         self.update_nodes()
598         # PN -- non necessaire si item=jdc
599         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
600  
601     def onSupp(self,object):
602         if self.JESUISOFF==1 : return
603         #print "onSup pour ", self.item.nom, object.nom
604         self.editor.init_modif()
605         self.update_nodes()
606         # PN -- non necessaire si item=jdc
607         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
608          
609
610
611
612     def update_node_valid(self):
613         """Cette methode remet a jour la validite du noeud (icone)
614            Elle appelle isvalid
615         """
616         repIcon=QString(self.appliEficas.repIcon)
617         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
618         self.setIcon(0,monIcone)
619
620
621     def update_node_label(self):
622         """ Met a jour le label du noeud """
623         #print "NODE update_node_label", self.item.GetLabelText()
624         labeltext,fonte,couleur = self.item.GetLabelText()
625         # PNPN a reflechir
626         #self.setText(0, labeltext)        
627     
628     
629     def update_node_label_in_blue(self):
630         if hasattr(self.appliEficas,'noeudColore'):
631            self.appliEficas.noeudColore.setTextColor( 0,Qt.black)
632            self.appliEficas.noeudColore.update_node_label()
633         self.setTextColor( 0,Qt.blue )
634         labeltext,fonte,couleur = self.item.GetLabelText()
635         self.setText(0, labeltext)        
636         self.appliEficas.noeudColore=self
637
638     def update_plusieurs_node_label_in_blue(self,liste):
639         if hasattr(self.appliEficas,'listeNoeudsColores'):
640            for noeud in self.appliEficas.listeNoeudsColores:
641                noeud.setTextColor( 0,Qt.black)
642                noeud.update_node_label()
643         self.appliEficas.listeNoeudsColores=[]
644         for noeud in liste :
645             noeud.setTextColor( 0,Qt.blue )
646             labeltext,fonte,couleur = noeud.item.GetLabelText()
647             noeud.setText(0, labeltext)        
648             self.appliEficas.listeNoeudsColores.append(noeud)
649
650     def update_node_texte_in_black(self):
651         """ Met a jour les noms des SD et valeurs des mots-cles """
652         self.setTextColor( 1,Qt.black )
653         value = self.item.GetText()
654         self.setText(1, value)
655
656     def update_node_texte(self):
657         """ Met a jour les noms des SD et valeurs des mots-cles """
658         value = self.item.GetText()
659         self.setText(1, value)
660         
661
662     def update_node_texte_in_blue(self):
663         self.setTextColor( 1,Qt.blue )
664         value = self.item.GetText()
665         self.setText(1, value)
666
667     def update_nodes(self):
668         #print 'NODE update_nodes', self.item.GetLabelText()
669         self.build_children()
670
671     def update_valid(self) :
672         """Cette methode a pour but de mettre a jour la validite du noeud
673            et de propager la demande de mise a jour a son parent
674         """
675         #print "NODE update_valid", self.item.GetLabelText()
676         self.update_node_valid()
677         try :
678           self.treeParent.update_valid()
679         except:
680           pass
681             
682     def update_texte(self):
683         """ Met a jour les noms des SD et valeurs des mots-cles """
684         #print "NODE update_texte", self.item.GetLabelText()
685         self.update_node_texte()
686         if self.isExpanded() :
687             for child in self.children:
688                 if child.isHidden() == false : child.update_texte()
689
690
691     def forceRecalculChildren(self,niveau):
692         if self.state=='recalcule' : 
693            self.state=""
694            return
695         self.state='recalcule'
696         if hasattr(self.item,'object'):
697            self.item.object.state="modified"
698         for child in self.children:
699            if niveau > 0 : child.forceRecalculChildren(niveau - 1)
700               
701         
702
703     def doPaste(self,node_selected,pos='after'):
704         """
705             Déclenche la copie de l'objet item avec pour cible
706             l'objet passé en argument : node_selected
707         """
708         #print 'je passe dans doPaste'
709         objet_a_copier = self.item.get_copie_objet()
710         child=node_selected.doPasteCommande(objet_a_copier,pos)
711         return child
712
713     def doPasteCommande(self,objet_a_copier,pos='after'):
714         """
715           Réalise la copie de l'objet passé en argument qui est nécessairement
716           une commande
717         """
718         child=None
719         try :
720           child = self.append_brother(objet_a_copier,pos)
721         except :
722            pass
723         return child
724
725     def doPastePremier(self,objet_a_copier):
726         """
727            Réalise la copie de l'objet passé en argument (objet_a_copier)
728         """
729         objet = objet_a_copier.item.get_copie_objet()
730         child = self.append_child(objet,pos='first')
731         return child
732
733     def plieToutEtReafficheSaufItem(self, itemADeplier):
734         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
735         from InterfaceQT4 import compojdc
736         if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return 
737         self.editor.deplier = False
738         for item in self.children :
739             # il ne faut pas plier les blocs 
740             from InterfaceQT4 import compobloc
741             if (isinstance(item,compobloc.Node)) : continue
742             item.setPlie()
743             if item==itemADeplier : 
744                   itemADeplier.setDeplie()
745         self.affichePanneau()
746
747     def plieToutEtReaffiche(self):
748         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
749         from InterfaceQT4 import compojdc
750         if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return 
751         self.editor.deplier = False
752         for item in self.children :
753             # il ne faut pas plier les blocs 
754             from InterfaceQT4 import compobloc
755             if (isinstance(item,compobloc.Node)) : continue
756             item.setPlie()
757         self.affichePanneau()
758
759     def deplieToutEtReaffiche(self):
760         self.editor.deplier = True
761         for item in self.children :
762             item.setDeplie()
763         self.affichePanneau()
764
765     def setPlie(self):
766         #print "je mets inhibeExpand a true dans setPlie"
767         #print "je suis dans plieTout", self.item.get_nom()
768         import compojdc
769         if self.fenetre == self.editor.fenetreCentraleAffichee  and isinstance(self.treeParent,compojdc.Node): 
770            return
771         self.tree.inhibeExpand=True
772         self.tree.collapseItem(self)
773         self.setPlieChildren()
774         self.tree.inhibeExpand=False
775         #print "je mets inhibeExpand a false dans setPlie"
776
777
778         # on ne plie pas au niveau 1
779         #   self.plie=False
780         #   for item in self.children :
781         #       item.appartientAUnNoeudPlie=False
782
783     def setPlieChildren(self):
784         #print "dans setPlieChildren pour", self.item.nom
785         self.plie=True
786         for c in self.children :
787             c.setPlieChildren()
788             #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0]
789             c.appartientAUnNoeudPlie=True
790             c.plie=True
791             #print "dans setPlieChildren plie", c.item.nom
792             c.setExpanded(False)
793
794         # Pour les blocs et les motcles list
795         # on affiche un niveau de plus
796         from InterfaceQT4 import compobloc
797         from InterfaceQT4 import compomclist
798         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
799             niveauPere=self.treeParent
800             while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) : 
801                niveauPere=niveauPere.treeParent
802             for c in self.children :
803                 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
804                 c.setExpanded(False)
805
806         # on affiche un niveau de plus
807         #if isinstance(self,compomclist.Node)  : 
808         #if isinstance(self,compobloc.Node)  : 
809         #    niveauPere=self.treeParent
810         #    while (isinstance(niveauPere,compobloc.Node)):
811         #       niveauPere=niveauPere.treeParent
812         #    for c in self.children :
813         #        c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
814
815     def setDeplie(self):
816         #print "dans setPlieChildren pour", self.item.nom
817         #print "je mets inhibeExpand a true dans setDeplie"
818         self.tree.inhibeExpand=True
819         self.plie=False
820         self.tree.expandItem(self)
821         self.setDeplieChildren()
822         self.tree.inhibeExpand=False
823         #print "je mets inhibeExpand a false dans setDePlie"
824
825     def setDeplieChildren(self):
826         #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.GetLabelText()
827         for c in self.children :
828             c.setDeplieChildren()
829             #print "dans setDeplieChildren ", c.item.nom
830             c.appartientAUnNoeudPlie=False
831             c.setExpanded(True)
832             c.plie=False
833        
834     def selectAvant(self):
835         i=self.item.jdc.etapes.index(self.item.object)
836         try :
837            cherche=self.item.jdc.etapes[i-1]
838         except :
839            cherche=self.item.jdc.etapes[-1]
840         node=None
841         for i in self.tree.racine.children :
842             if i.item.object== cherche  : 
843                node=i
844                break
845         if node : node.affichePanneau()
846
847     def selectApres(self):
848         i=self.item.jdc.etapes.index(self.item.object)
849         try :
850            cherche=self.item.jdc.etapes[i+1]
851         except :
852            cherche=self.item.jdc.etapes[0]
853         node=None
854         for i in self.tree.racine.children :
855             if i.item.object== cherche  : 
856                node=i
857                break
858         if node : node.affichePanneau()