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