Salome HOME
Pour V1 Carmel
[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:
386             pos = 'after'
387         else:
388             pos = 'before'
389         return self.append_brother( PARAMETERS, pos )
390     
391     
392     def select( self ):
393         """
394         Rend le noeud courant (self) selectionne et deselectionne
395         tous les autres
396         """        
397         #print "je suis sur select"
398         for item in self.tree.selectedItems() :
399             item.setSelected(0)
400         self.setSelected( True )    
401         #self.setExpanded( True )    
402         self.tree.setCurrentItem( self )    
403         self.tree.node_selected= self
404                                
405     #------------------------------------------------------------------
406     # Methodes de creation et destruction de noeuds
407     # Certaines de ces methodes peuvent etre appelees depuis l'externe
408     #------------------------------------------------------------------
409     def append_brother(self,name,pos='after',plier=False):
410         """
411         Permet d'ajouter un objet frere a l'objet associe au noeud self
412         par defaut on l'ajoute immediatement apres 
413         Methode externe
414         """
415         self.editor.init_modif()
416         index = self.treeParent.children.index(self)
417         if   pos == 'before': index = index
418         elif pos == 'after': index = index +1
419         else:
420             print unicode(pos), tr("  n'est pas un index valide pour append_brother")
421             return 0
422         return self.treeParent.append_child(name,pos=index,plier=plier)
423
424     def append_child(self,name,pos=None,plier=False):
425         """
426            Methode pour ajouter un objet fils a l'objet associe au noeud self.
427            On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
428            ou en position intermediaire.
429            Si pos vaut None, on le place a la position du catalogue.
430         """
431         #print "************** append_child ",self.item.GetLabelText(), plier
432         self.editor.init_modif()
433         if pos == 'first':
434             index = 0
435         elif pos == 'last':
436             index = len(self.children)
437         elif type(pos) == types.IntType :
438             # position fixee
439             index = pos
440         elif type(pos) == types.InstanceType:
441             # pos est un item. Il faut inserer name apres pos
442             index = self.item.get_index(pos) +1
443         elif type(name) == types.InstanceType:
444             index = self.item.get_index_child(name.nom)
445         else:
446             index = self.item.get_index_child(name)
447         self.tree.inhibeExpand=True
448         obj=self.item.additem(name,index) #CS_pbruno emet le signal 'add'
449         if obj is None:obj=0
450         if obj == 0:return 0
451         #try :
452         #  old_obj = self.item.object.get_child(name.nom,restreint = 'oui')
453         #  child=old_obj[-1]
454         #  if plier : child.plieToutEtReaffiche()
455         #  else     : child.affichePanneau() 
456         #  print "dans le 1er Try"
457         #else :
458         #except:
459           # Souci pour gerer les copies des AFFE d'une commande à l autre
460         #  try :
461         #     child=self.children[index]
462         #     if plier == True : child.setPlie()
463         #     else             : child.setDeplie() 
464         #     print "dans le 2nd Try"
465         #  except :
466         #     child=self.children[index]
467         #     print "dans le except"
468         try :
469         #if 1:
470            child=self.children[index]
471            if plier == True : child.setPlie()
472            else             : child.setDeplie() 
473         except :
474            child=self.children[index]
475            #print "dans le except"
476         self.tree.inhibeExpand=False
477         return child
478
479     def deplace(self):
480         self.editor.init_modif()
481         index = self.treeParent.children.index(self) - 1 
482         if index < 0 : index =0
483         ret=self.treeParent.item.deplaceEntite(self.item.getObject())
484
485     def delete(self):
486         """ 
487             Methode externe pour la destruction de l'objet associe au noeud
488         """
489         self.editor.init_modif()
490         index = self.vraiParent.children.index(self) - 1 
491         if index < 0 : index =0
492         recalcule=0
493         if self.item.nom == "VARIABLE" :
494            recalcule=1
495            jdc=self.item.jdc
496         ret=self.vraiParent.item.suppitem(self.item)
497         self.treeParent.build_children()
498         if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
499         else: toselect=self.treeParent
500         if recalcule : jdc.recalcule_etat_correlation()
501         from InterfaceQT4 import compojdc
502         # cas ou on detruit dans l arbre sans affichage
503         if isinstance(self.treeParent,compojdc.Node) : 
504            toselect.affichePanneau()
505         else :
506            if self.treeParent.fenetre== None : return
507            #print "J appelle reaffiche de browser apres delete"
508            self.treeParent.fenetre.reaffiche(toselect)
509
510     def deleteMultiple(self,liste=()):
511         """ 
512             Methode externe pour la destruction d une liste de noeud
513         """
514         from InterfaceQT4 import compojdc 
515         self.editor.init_modif()
516         index=9999
517         recalcule=0
518         jdc=self.treeParent
519         parentPosition=jdc
520         while not(isinstance(jdc,compojdc.Node)):
521               jdc=jdc.treeParent
522         for noeud in liste :
523             if not( isinstance(noeud.treeParent, compojdc.Node)): continue
524             if noeud.item.nom == "VARIABLE" : recalcule=1
525             if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
526         if index < 0 : index =0
527
528         # Cas ou on détruit dans une ETape
529         if index == 9999 : 
530               parentPosition=self.treeParent
531               while not(isinstance(parentPosition, compojdc.Node)):
532                  index=parentPosition.treeParent.children.index(parentPosition)
533                  parentPosition=parentPosition.treeParent
534
535         for noeud in liste:
536             noeud.treeParent.item.suppitem(noeud.item)
537
538         jdc.build_children()
539         if recalcule : jdc.recalcule_etat_correlation()
540         try    : toselect=parentPosition.children[index]
541         except : toselect=jdc
542         toselect.select()
543         toselect.affichePanneau()
544 #        
545 #    #------------------------------------------------------------------
546     def onValid(self):        
547
548         #print "onValid pour ", self.item.nom
549         if hasattr(self,'fenetre') and self.fenetre: 
550            self.fenetre.setValide()
551         if self.item.nom == "VARIABLE" and self.item.isvalid():
552            self.item.jdc.recalcule_etat_correlation()
553         if hasattr(self.item,'forceRecalcul'):
554            self.forceRecalculChildren(self.item.forceRecalcul)
555         self.editor.init_modif()
556         
557         self.update_node_valid()
558         self.update_node_label()
559         self.update_node_texte()
560
561     def onAdd(self,object):
562         #print "onAdd pour ", self.item.nom
563         self.editor.init_modif()
564         self.update_nodes()
565         #print "dans onAdd" ,self.item 
566         # PN -- non necessaire si item=jdc
567         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
568  
569     def onSupp(self,object):
570         #print "onSupp pour ", self.item.nom
571         self.editor.init_modif()
572         self.update_nodes()
573         # PN -- non necessaire si item=jdc
574         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
575          
576     def detruit_les_noeuds_issus_de_blocs(self,bloc):
577         from InterfaceQT4 import compobloc
578         if (isinstance(bloc,compobloc.Node)) :
579            for node in bloc.childrenComplete :
580                self.detruit_les_noeuds_issus_de_blocs(node)
581                parent=node.treeParent
582                #print "je detruit " , node.item.GetLabelText()
583                parent.removeChild(node)
584
585     def update_node_valid(self):
586         """Cette methode remet a jour la validite du noeud (icone)
587            Elle appelle isvalid
588         """
589         repIcon=QString(self.appliEficas.repIcon)
590         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
591         self.setIcon(0,monIcone)
592
593
594     def update_node_label(self):
595         """ Met a jour le label du noeud """
596         #print "NODE update_node_label", self.item.GetLabelText()
597         labeltext,fonte,couleur = self.item.GetLabelText()
598         # PNPN a reflechir
599         #self.setText(0, labeltext)        
600     
601     
602     def update_node_label_in_blue(self):
603         if hasattr(self.appliEficas,'noeudColore'):
604            self.appliEficas.noeudColore.setTextColor( 0,Qt.black)
605            self.appliEficas.noeudColore.update_node_label()
606         self.setTextColor( 0,Qt.blue )
607         labeltext,fonte,couleur = self.item.GetLabelText()
608         self.setText(0, labeltext)        
609         self.appliEficas.noeudColore=self
610
611     def update_plusieurs_node_label_in_blue(self,liste):
612         if hasattr(self.appliEficas,'listeNoeudsColores'):
613            for noeud in self.appliEficas.listeNoeudsColores:
614                noeud.setTextColor( 0,Qt.black)
615                noeud.update_node_label()
616         self.appliEficas.listeNoeudsColores=[]
617         for noeud in liste :
618             noeud.setTextColor( 0,Qt.blue )
619             labeltext,fonte,couleur = noeud.item.GetLabelText()
620             noeud.setText(0, labeltext)        
621             self.appliEficas.listeNoeudsColores.append(noeud)
622
623     def update_node_texte_in_black(self):
624         """ Met a jour les noms des SD et valeurs des mots-cles """
625         self.setTextColor( 1,Qt.black )
626         value = self.item.GetText()
627         self.setText(1, value)
628
629     def update_node_texte(self):
630         """ Met a jour les noms des SD et valeurs des mots-cles """
631         value = self.item.GetText()
632         self.setText(1, value)
633
634     def update_node_texte_in_blue(self):
635         self.setTextColor( 1,Qt.blue )
636         value = self.item.GetText()
637         self.setText(1, value)
638
639     def update_nodes(self):
640         #print 'NODE update_nodes', self.item.GetLabelText()
641         self.build_children()
642
643     def update_valid(self) :
644         """Cette methode a pour but de mettre a jour la validite du noeud
645            et de propager la demande de mise a jour a son parent
646         """
647         #print "NODE update_valid", self.item.GetLabelText()
648         self.update_node_valid()
649         try :
650           self.treeParent.update_valid()
651         except:
652           pass
653             
654     def update_texte(self):
655         """ Met a jour les noms des SD et valeurs des mots-cles """
656         #print "NODE update_texte", self.item.GetLabelText()
657         self.update_node_texte()
658         if self.isExpanded() :
659             for child in self.children:
660                 if child.isHidden() == false : child.update_texte()
661
662
663     def forceRecalculChildren(self,niveau):
664         if self.state=='recalcule' : 
665            self.state=""
666            return
667         self.state='recalcule'
668         if hasattr(self.item,'object'):
669            self.item.object.state="modified"
670         for child in self.children:
671            if niveau > 0 : child.forceRecalculChildren(niveau - 1)
672               
673         
674
675     def doPaste(self,node_selected,pos='after'):
676         """
677             Déclenche la copie de l'objet item avec pour cible
678             l'objet passé en argument : node_selected
679         """
680         #print 'je passe dans doPaste'
681         objet_a_copier = self.item.get_copie_objet()
682         child=node_selected.doPasteCommande(objet_a_copier,pos)
683         return child
684
685     def doPasteCommande(self,objet_a_copier,pos='after'):
686         """
687           Réalise la copie de l'objet passé en argument qui est nécessairement
688           une commande
689         """
690         child=None
691         try :
692           child = self.append_brother(objet_a_copier,pos)
693         except :
694            pass
695         return child
696
697     def doPastePremier(self,objet_a_copier):
698         """
699            Réalise la copie de l'objet passé en argument (objet_a_copier)
700         """
701         objet = objet_a_copier.item.get_copie_objet()
702         child = self.append_child(objet,pos='first')
703         return child
704
705
706     def plieToutEtReaffiche(self):
707         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
708         self.editor.deplier = False
709         for item in self.children :
710             item.setPlie()
711         self.affichePanneau()
712
713     def deplieToutEtReaffiche(self):
714         self.editor.deplier = True
715         for item in self.children :
716             item.setDeplie()
717         self.affichePanneau()
718
719     def setPlie(self):
720         #print "je mets inhibeExpand a true dans setPlie"
721         #print "je suis dans plieTout", self.item.get_nom()
722         import compojdc
723         if self.fenetre == self.editor.fenetreCentraleAffichee  and isinstance(self.treeParent,compojdc.Node): 
724            return
725         self.tree.inhibeExpand=True
726         self.tree.collapseItem(self)
727         self.setPlieChildren()
728         self.tree.inhibeExpand=False
729         #print "je mets inhibeExpand a false dans setPlie"
730
731
732         # on ne plie pas au niveau 1
733         #   self.plie=False
734         #   for item in self.children :
735         #       item.appartientAUnNoeudPlie=False
736
737     def setPlieChildren(self):
738         self.plie=True
739         for c in self.children :
740             c.setPlieChildren()
741             #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0]
742             c.appartientAUnNoeudPlie=True
743             c.plie=True
744             c.setExpanded(False)
745
746         # Pour les blocs et les motcles list
747         # on affiche un niveau de plus
748         from InterfaceQT4 import compobloc
749         from InterfaceQT4 import compomclist
750         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
751             niveauPere=self.treeParent
752             while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) : 
753                niveauPere=niveauPere.treeParent
754             for c in self.children :
755                 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
756                 c.setExpanded(False)
757
758         # on affiche un niveau de plus
759         #if isinstance(self,compomclist.Node)  : 
760         #if isinstance(self,compobloc.Node)  : 
761         #    niveauPere=self.treeParent
762         #    while (isinstance(niveauPere,compobloc.Node)):
763         #       niveauPere=niveauPere.treeParent
764         #    for c in self.children :
765         #        c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
766
767     def setDeplie(self):
768         #print "je mets inhibeExpand a true dans setDeplie"
769         self.tree.inhibeExpand=True
770         self.plie=False
771         self.tree.expandItem(self)
772         self.setDeplieChildren()
773         self.tree.inhibeExpand=False
774         #print "je mets inhibeExpand a false dans setDePlie"
775
776     def setDeplieChildren(self):
777         #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.GetLabelText()
778         for c in self.children :
779             c.setDeplieChildren()
780             #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", c.item.GetLabelText()
781             c.appartientAUnNoeudPlie=False
782             c.setExpanded(True)
783             c.plie=False
784        
785     def selectAvant(self):
786         i=self.item.jdc.etapes.index(self.item.object)
787         try :
788            cherche=self.item.jdc.etapes[i-1]
789         except :
790            cherche=self.item.jdc.etapes[-1]
791         node=None
792         for i in self.tree.racine.children :
793             if i.item.object== cherche  : 
794                node=i
795                break
796         if node : node.affichePanneau()
797
798     def selectApres(self):
799         i=self.item.jdc.etapes.index(self.item.object)
800         try :
801            cherche=self.item.jdc.etapes[i+1]
802         except :
803            cherche=self.item.jdc.etapes[0]
804         node=None
805         for i in self.tree.racine.children :
806             if i.item.object== cherche  : 
807                node=i
808                break
809         if node : node.affichePanneau()