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