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