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