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