Salome HOME
2745b6b11adb766bf2fa652f5e2b9c2938e29b62
[tools/eficas.git] / InterfaceQT4 / browser.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import string,re
22 import types,sys,os
23 import traceback
24 import typeNode
25 import pdb
26 from PyQt4 import *
27 from PyQt4.QtGui  import *
28 from PyQt4.QtCore import *
29 from Extensions.i18n import tr
30 from gereRegles import GereRegles
31 from monChoixCommande import MonChoixCommande
32
33 class JDCTree( QTreeWidget,GereRegles ):
34     def __init__( self, jdc_item, QWParent):        
35         #if hasattr(QWParent,'widgetTree') : 
36         self.editor        = QWParent
37         self.plie=False
38         if self.editor.widgetTree !=None  :
39            QTreeWidget.__init__(self, self.editor.widgetTree ) 
40            self.editor.verticalLayout_2.addWidget(self)
41            if self.editor.enteteQTree=='complet':
42                  self.headerItem().setText(0,  "Commande   ")
43                  self.headerItem().setText(1, "Concept/Valeur")
44            else :
45                  self.headerItem().setText(0,  "Commande   ")
46            self.setColumnWidth(0,200)
47            self.setExpandsOnDoubleClick(False)
48            self.setSelectionMode(3)
49         else :
50            QTreeWidget.__init__(self, None ) 
51         self.item          = jdc_item
52         self.tree          = self        
53         self.appliEficas   = self.editor.appliEficas
54         self.childrenComplete=[]
55         self.racine=self.item.itemNode(self,self.item)
56  
57         self.itemCourrant=None
58
59         self.connect(self, SIGNAL("itemClicked ( QTreeWidgetItem * ,int) "), self.handleOnItem)
60         self.connect(self, SIGNAL("itemCollapsed ( QTreeWidgetItem *) "), self.handleCollapsedItem)
61         self.connect(self, SIGNAL("itemExpanded ( QTreeWidgetItem *) "), self.handleExpandedItem)
62
63         #PNPNPN verifier dans quel cas on se trouve : affiche l arbre ou la commande
64         self.node_selected=self.racine
65         self.inhibeExpand=True
66         self.expandItem(self.racine)
67         self.inhibeExpand=False
68         #print "self.editor.afficheCommandesPliees", self.editor.afficheCommandesPliees
69         if self.racine.children !=[] :  
70
71             
72            if self.editor.afficheCommandesPliees : self.racine.children[0].plieToutEtReaffiche()
73            else : self.racine.children[0].deplieToutEtReaffiche()
74         
75
76            self.racine.children[0].fenetre.donnePremier()
77         else : self.racine.affichePanneau()
78         #PNPNPN
79         #pdb.set_trace()
80
81     def contextMenuEvent(self,event) :
82         #print "contextMenuEvent"
83         coord=event.globalPos()
84         item= self.currentItem()
85         self.handleContextMenu(item,coord)
86
87     def handleContextMenu(self,item,coord):
88         """
89         Private slot to show the context menu of the listview.
90         
91         @param itm the selected listview item (QListWidgetItem)
92         @param coord the position of the mouse pointer (QPoint)
93         Attention : existeMenu permet de savoir si un menu est associe a cet item
94         """
95         #print "handleContextMenu"
96         if item == None : return
97         if item.existeMenu == 0 : return
98         if item.menu == None:
99            item.createPopUpMenu()
100         if item.menu != None:
101            if item.item.get_nom() == "DISTRIBUTION" and item.item.isvalid() :
102               item.Graphe.setEnabled(1)
103            item.menu.exec_(coord)            
104             
105
106     def handleCollapsedItem(self,item):
107         print "dans CollapsedItem", self.inhibeExpand  
108         if self.inhibeExpand == True : return
109         # On traite le cas de l item non selectionne
110         itemParent=item
111         while not (hasattr (itemParent,'getPanel')) : 
112            itemParent=itemParent.treeParent 
113         if self.tree.node_selected != itemParent : 
114              item.setExpanded(False)
115              return
116
117         itemParent=item
118         item.setPlie()
119         item.plieToutEtReaffiche()
120         item.select()
121
122     def handleExpandedItem(self,item):
123         #print "handleExpandedItem pour ", item.item.nom, self.inhibeExpand
124         if self.inhibeExpand == True : return
125         itemParent=item
126         while not (hasattr (itemParent,'getPanel')) : 
127            if itemParent.plie==True : itemParent.setDeplie()
128            itemParent=itemParent.treeParent 
129         if self.tree.node_selected != itemParent : 
130              item.setExpanded(True)
131              return
132         item.deplieToutEtReaffiche()
133         self.inhibeExpand == False 
134
135
136     def handleOnItem(self,item,int):
137         print "je passe dans handleOnItem pour ",self, item.item.nom, item, item.item
138         
139         from InterfaceQT4 import composimp
140         self.inhibeExpand == True 
141         self.itemCourrant=item
142         itemParent=item
143
144         while not (hasattr (itemParent,'getPanel')) : 
145            if itemParent.plie==True : itemParent.setDeplie()
146            itemParent=itemParent.treeParent 
147
148         if itemParent.fenetre != self.editor.fenetreCentraleAffichee : 
149               
150             estUneFeuille=(isinstance(item,composimp.Node))
151              # il faut afficher le parent
152             print "estUneFeuille", estUneFeuille
153             print "afficheCommandesPliees", self.editor.afficheCommandesPliees
154             if estUneFeuille                        : itemParent.affichePanneau()
155             elif self.editor.afficheCommandesPliees : itemParent.plieToutEtReafficheSaufItem(item)
156             else                                    : itemParent.affichePanneau()
157
158
159         if (isinstance(item,composimp.Node)) and item.fenetre : item.fenetre.rendVisible()
160         elif itemParent!=item:
161              #self.tree.handleExpandedItem(item)
162              #item.fenetre.donnePremier()
163              #item.fenetre.rendActif()
164              print 'il faut afficher le 1er'
165         try :
166            fr = item.item.get_fr()
167            if self.editor: self.editor.affiche_commentaire(unicode(fr))
168         except:
169             pass
170         item.select()
171         self.inhibeExpand == False 
172         #print "je mets inhibeExpand a false handleOnItem"
173
174
175     def choisitPremier(self,name):
176         self.editor.layoutJDCCHOIX.removeWidget(self.racine.fenetre)
177         self.racine.fenetre.close()
178         new_node=self.racine.append_brother(name,'after')
179  
180 # type de noeud
181 COMMENT     = "COMMENTAIRE"
182 PARAMETERS  = "PARAMETRE"
183  
184 class JDCNode(QTreeWidgetItem,GereRegles):
185     def __init__( self, treeParent, item, itemExpand=False, ancien=False ):
186         #print "creation d'un noeud : ", item, " ",item.nom,"", treeParent, self
187         #self.a=0
188         self.item        = item
189         self.vraiParent  = treeParent
190         self.treeParent  = treeParent
191         self.tree        = self.treeParent.tree
192         self.editor      = self.treeParent.editor
193         self.appliEficas = treeParent.appliEficas
194         self.JESUISOFF=0
195         self.childrenComplete=[]
196
197                         
198         from InterfaceQT4 import compocomm
199         from InterfaceQT4 import compoparam
200         from InterfaceQT4 import composimp
201         if   (isinstance(self.item,compocomm.COMMTreeItem)) : name=tr("Commentaire")
202         elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=self.appliEficas.trUtf8(str(item.GetLabelText()[0]))
203         else:   name  = self.appliEficas.trUtf8(str(tr( item.nom))+" :")
204         value = self.appliEficas.trUtf8(str( item.GetText() ) )
205  
206
207         mesColonnes=QStringList()
208         if self.editor.enteteQTree=='complet': mesColonnes <<  name << value
209         else : mesColonnes <<  name
210
211         if self.treeParent.plie==True :
212             self.plie        = True
213             self.appartientAUnNoeudPlie=True
214         else :
215             self.plie        = False
216             self.appartientAUnNoeudPlie = False
217
218         if ancien and itemExpand     : self.plie = False
219         if ancien and not itemExpand : self.plie = True 
220         if (isinstance(self.item,composimp.SIMPTreeItem)) : self.plie=False
221
222         from InterfaceQT4 import compobloc
223         from InterfaceQT4 import compomclist
224
225         ajoutAuParentduNoeud=0
226         self.treeParent=treeParent
227         while (isinstance(self.treeParent,compobloc.Node) or ( isinstance(self.treeParent,compomclist.Node) and self.treeParent.item.isMCList())) : 
228               self.treeParent.childrenComplete.append(self)
229               self.treeParent=self.treeParent.vraiParent
230         self.treeParent.childrenComplete.append(self)
231         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
232            QTreeWidgetItem.__init__(self,None,mesColonnes)
233         else :
234            QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
235
236         self.setToolTip(0,QString(self.item.get_fr()))
237         self.setToolTip(1,QString(self.item.get_fr()))
238
239         repIcon=QString(self.appliEficas.repIcon)
240         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
241         self.setIcon(0,monIcone)
242
243         self.children = []
244         self.build_children()
245         self.menu=None
246         self.existeMenu=1
247
248         self.item.connect("valid",self.onValid,())
249         self.item.connect("supp" ,self.onSupp,())
250         self.item.connect("add"  ,self.onAdd,())
251
252         self.state=""
253         self.fenetre=None
254         try :
255           if self.item.getObject().isBLOC() : 
256                 self.setExpanded(True) 
257                 self.plie=False
258         except :
259           pass
260
261
262     def build_children(self,posInsertion=10000):
263         """ Construit la liste des enfants de self """
264         """ Se charge de remettre les noeuds Expanded dans le meme etat """
265         #print "*********** build_children ",self,self.item, self.item.nom
266         
267         self.listeItemExpanded=[]
268         self.listeItemPlie=[]
269
270         for enfant in self.childrenComplete :
271             if enfant.plie : self.listeItemPlie.append(enfant.item)
272             else : self.listeItemExpanded.append(enfant.item)
273
274         for enfant in self.childrenComplete :
275             p=enfant.vraiParent
276             parent=enfant.treeParent
277             parent.removeChild(enfant)
278             enfant.JESUISOFF=1
279          
280         
281         self.children = []
282         self.childrenComplete = []
283         sublist = self.item._GetSubList()
284         ind=0
285         
286         for item in sublist :
287             itemExpand=False
288             ancien=False
289             if item in self.listeItemExpanded : itemExpand=True;  ancien=True
290             if item in self.listeItemPlie     : itemExpand=False; ancien=True
291             nouvelItem=item.itemNode(self,item,itemExpand,ancien)
292             self.children.append(nouvelItem)
293
294         #print "fin *********** build_children ",self,self.item, self.item.nom
295
296         
297     def chercheNoeudCorrespondant(self,objSimp):
298         sublist = self.item._GetSubList()
299         for node in self.childrenComplete:
300             if node.item.object==objSimp : return node
301         return None
302
303
304     def affichePanneau(self) :
305         #print " affichePanneau " , self.item.nom 
306         #if self.item.isactif(): 
307         #if self.editor.code == 'ASTER' and not(self.item.isactif()) : 
308         # posera des pb si un code decide d appeler FIN un mot clef
309         # on resoudera a ce moment la
310         # pour l instant pas de poussiere sous le tapis
311         if  not(self.item.isactif()) : 
312             from monWidgetInactif import MonWidgetInactif
313             self.fenetre = MonWidgetInactif(self,self.editor)
314         else:
315            itemParent=self
316            while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent 
317            if itemParent!=self : 
318               itemParent.affichePanneau()
319               return
320            self.fenetre=self.getPanel()
321          
322         for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
323             widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
324             self.editor.widgetCentraleLayout.removeItem(widget)
325         # ceinture et bretelle
326         #print 'old fenetre = ',self.editor.fenetreCentraleAffichee
327         if self.editor.fenetreCentraleAffichee != None : 
328             #print "j enleve ", self.editor.fenetreCentraleAffichee, self.editor.fenetreCentraleAffichee.node.item.nom
329             self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
330             self.editor.fenetreCentraleAffichee.close()
331
332         self.editor.widgetCentraleLayout.addWidget(self.fenetre)
333         #print "j ajoute ", self.fenetre, self.fenetre.node.item.nom
334         self.editor.fenetreCentraleAffichee=self.fenetre
335         self.tree.node_selected= self
336
337         if self.editor.first :
338            self.editor.splitter.setSizes((400,1400,400))
339            if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
340         self.tree.inhibeExpand=True
341         self.tree.expandItem(self)
342         #self.select()
343         self.tree.inhibeExpand=False
344         #print "fin de affichePanneau", self.item.nom
345         #print "______________________________"
346           
347
348     def createPopUpMenu(self):
349         #implemente dans les noeuds derives si necessaire
350         self.existeMenu = 0
351
352     def commentIt(self):
353         """
354         Cette methode a pour but de commentariser la commande pointee par self
355         """
356         # On traite par une exception le cas ou l'utilisateur final cherche a désactiver
357         # (commentariser) un commentaire.
358         try :
359             pos=self.treeParent.children.index(self)
360             commande_comment = self.item.get_objet_commentarise()
361             # On signale a l editeur du panel (le JDCDisplay) une modification
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             traceback.print_exc()
368             QMessageBox.critical( self.editor, "TOO BAD",str(e))
369         
370     def unCommentIt(self):
371         """
372         Realise la decommentarisation de self
373         """
374         try :
375             pos=self.treeParent.children.index(self)
376             commande,nom = self.item.uncomment()
377             self.editor.init_modif()
378             self.treeParent.build_children()
379             self.treeParent.children[pos].select()
380             self.treeParent.children[pos].affichePanneau()
381         except Exception,e:
382             QMessageBox.critical( self.editor, "Erreur !",str(e))
383         
384     def addComment( self, after=True ):
385         """
386         Ajoute un commentaire a l'interieur du JDC :
387         """
388         self.editor.init_modif()
389         if after:
390             pos = 'after'
391         else:
392             pos = 'before'
393         return self.append_brother( COMMENT, pos )
394                 
395     def addParameters( self, after=True ):
396         """
397         Ajoute un parametre a l'interieur du JDC :
398         """
399         self.editor.init_modif()
400         if after: pos = 'after'
401         else: pos = 'before'
402         child=self.append_brother( PARAMETERS, pos )
403         return  child
404     
405     
406     def select( self ):
407         """
408         Rend le noeud courant (self) selectionne et deselectionne
409         tous les autres
410         """        
411         print "select pour", self.item.nom
412         for item in self.tree.selectedItems() :
413             item.setSelected(0)
414         self.tree.setCurrentItem( self )    
415                                
416     #------------------------------------------------------------------
417     # Methodes de creation et destruction de noeuds
418     # Certaines de ces methodes peuvent etre appelees depuis l'externe
419     #------------------------------------------------------------------
420     def append_brother(self,name,pos='after',plier=False):
421         """
422         Permet d'ajouter un objet frere a l'objet associe au noeud self
423         par defaut on l'ajoute immediatement apres 
424         Methode externe
425         """
426         self.editor.init_modif()
427
428         from InterfaceQT4 import compojdc
429         if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos)  : return 0
430         
431         index = self.treeParent.children.index(self)
432         if   pos == 'before': index = index
433         elif pos == 'after': index = index +1
434         else:
435             print unicode(pos), tr("  n'est pas un index valide pour append_brother")
436             return 0
437         return self.treeParent.append_child(name,pos=index,plier=plier)
438
439     def verifiePosition(self,name,pos,aLaRacine=False):
440         if name not in self.editor.Classement_Commandes_Ds_Arbre : return True
441         indexName=self.editor.Classement_Commandes_Ds_Arbre.index(name)
442
443         etapes=self.item.get_jdc().etapes
444         if etapes == [] : return True
445
446         if aLaRacine == False :indexOu=etapes.index(self.item.object)
447         else : indexOu=0
448
449         if pos=="after" : indexOu = indexOu+1
450         for e in etapes[:indexOu] :
451             nom=e.nom
452             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
453             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
454             if indexEtape > indexName :
455                comment=tr('le mot clef ')+name+tr(' doit etre insere avant ')+nom
456                QMessageBox.information( None,tr('insertion impossible'),comment, )
457                return False
458         for e in etapes[indexOu:] :
459             nom=e.nom
460             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
461             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
462             if indexEtape < indexName :
463                comment=tr('le mot clef ')+name+tr(' doit etre insere apres ')+nom
464                QMessageBox.information( None,tr('insertion impossible'),comment, )
465                return False
466         return True
467
468     def append_child(self,name,pos=None,plier=False):
469         """
470            Methode pour ajouter un objet fils a l'objet associe au noeud self.
471            On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
472            ou en position intermediaire.
473            Si pos vaut None, on le place a la position du catalogue.
474         """
475         #print "************** append_child ",self.item.GetLabelText(), plier
476
477          
478         self.editor.init_modif()
479         if pos == 'first':
480             index = 0
481         elif pos == 'last':
482             index = len(self.children)
483         elif type(pos) == types.IntType :
484             # position fixee
485             index = pos
486         elif type(pos) == types.InstanceType:
487             # pos est un item. Il faut inserer name apres pos
488             index = self.item.get_index(pos) +1
489         elif type(name) == types.InstanceType:
490             index = self.item.get_index_child(name.nom)
491         else:
492             index = self.item.get_index_child(name)
493
494         # si on essaye d inserer a la racine
495         if (isinstance(self.treeParent,JDCTree) and index==0) :
496            verifiePosition=self.verifiePosition(name,'first',aLaRacine=True)
497            if not verifiePosition : return 0
498
499         self.tree.inhibeExpand=True
500         obj=self.item.additem(name,index) #CS_pbruno emet le signal 'add'
501         if obj is None:obj=0
502         if obj == 0:return 0
503         try :
504            child=self.children[index]
505            if plier == True : child.setPlie()
506            else             : child.setDeplie() 
507         except :
508            child=self.children[index]
509         self.tree.inhibeExpand=False
510         #print " fin append child"
511         return child
512
513     def deplace(self):
514         self.editor.init_modif()
515         index = self.treeParent.children.index(self) - 1 
516         if index < 0 : index =0
517         ret=self.treeParent.item.deplaceEntite(self.item.getObject())
518
519     def delete(self):
520         """ 
521             Methode externe pour la destruction de l'objet associe au noeud
522         """
523         self.editor.init_modif()
524         index = self.vraiParent.children.index(self) - 1 
525         if index < 0 : index =0
526         recalcule=0
527         if self.item.nom == "VARIABLE" :
528            recalcule=1
529            jdc=self.item.jdc
530         ret,commentaire=self.vraiParent.item.suppitem(self.item)
531         if ret==0 :
532           self.editor.affiche_infos(commentaire,Qt.red)
533         else :
534           self.editor.affiche_infos(commentaire)
535         self.treeParent.build_children()
536         if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
537         else: toselect=self.treeParent
538         if recalcule : jdc.recalcule_etat_correlation()
539         if ret==0 :
540             if self.treeParent.childrenComplete :
541                 notdeleted=self.treeParent.childrenComplete[index+1]
542                 notdeleted.select()
543         else :
544             toselect.select()
545         from InterfaceQT4 import compojdc
546         # cas ou on detruit dans l arbre sans affichage
547         if isinstance(self.treeParent,compojdc.Node) : 
548            toselect.affichePanneau()
549         else :
550            if self.treeParent.fenetre== None : return
551            #print "J appelle reaffiche de browser apres delete"
552            self.treeParent.fenetre.reaffiche(toselect)
553
554     def deleteMultiple(self,liste=()):
555         """ 
556             Methode externe pour la destruction d une liste de noeud
557         """
558         from InterfaceQT4 import compojdc 
559         self.editor.init_modif()
560         index=9999
561         recalcule=0
562         jdc=self.treeParent
563         parentPosition=jdc
564         while not(isinstance(jdc,compojdc.Node)):
565               jdc=jdc.treeParent
566         for noeud in liste :
567             if not( isinstance(noeud.treeParent, compojdc.Node)): continue
568             if noeud.item.nom == "VARIABLE" : recalcule=1
569             if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
570         if index < 0 : index =0
571
572         # Cas ou on détruit dans une ETape
573         if index == 9999 : 
574               parentPosition=self.treeParent
575               while not(isinstance(parentPosition, compojdc.Node)):
576                  index=parentPosition.treeParent.children.index(parentPosition)
577                  parentPosition=parentPosition.treeParent
578
579         for noeud in liste:
580             noeud.treeParent.item.suppitem(noeud.item)
581
582         jdc.build_children()
583         if recalcule : jdc.recalcule_etat_correlation()
584         try    : toselect=parentPosition.children[index]
585         except : toselect=jdc
586         toselect.select()
587         toselect.affichePanneau()
588 #        
589 #    #------------------------------------------------------------------
590     def onValid(self):        
591
592         #print "onValid pour ", self.item.nom
593         if hasattr(self,'fenetre') and self.fenetre: self.fenetre.setValide()
594         if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isvalid():
595            self.item.jdc.recalcule_etat_correlation()
596         if hasattr(self.item,'forceRecalcul'):
597            self.forceRecalculChildren(self.item.forceRecalcul)
598         self.editor.init_modif()
599         
600         self.update_node_valid()
601         self.update_node_label()
602         self.update_node_texte()
603
604     def onAdd(self,object):
605         if self.JESUISOFF==1 : return
606         #print "onAdd pour ", self.item.nom, object.nom
607         self.editor.init_modif()
608         self.update_nodes()
609         # PN -- non necessaire si item=jdc
610         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
611  
612     def onSupp(self,object):
613         if self.JESUISOFF==1 : return
614         #print "onSup pour ", self.item.nom, object.nom
615         self.editor.init_modif()
616         self.update_nodes()
617         # PN -- non necessaire si item=jdc
618         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
619          
620
621
622
623     def update_node_valid(self):
624         """Cette methode remet a jour la validite du noeud (icone)
625            Elle appelle isvalid
626         """
627         repIcon=QString(self.appliEficas.repIcon)
628         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
629         self.setIcon(0,monIcone)
630
631
632     def update_node_label(self):
633         """ Met a jour le label du noeud """
634         #print "NODE update_node_label", self.item.GetLabelText()
635         labeltext,fonte,couleur = self.item.GetLabelText()
636         # PNPN a reflechir
637         #self.setText(0, labeltext)        
638     
639     
640     def update_node_label_in_blue(self):
641         if hasattr(self.appliEficas,'noeudColore'):
642            self.appliEficas.noeudColore.setTextColor( 0,Qt.black)
643            self.appliEficas.noeudColore.update_node_label()
644         self.setTextColor( 0,Qt.blue )
645         labeltext,fonte,couleur = self.item.GetLabelText()
646         self.setText(0, labeltext)        
647         self.appliEficas.noeudColore=self
648
649     def update_plusieurs_node_label_in_blue(self,liste):
650         if hasattr(self.appliEficas,'listeNoeudsColores'):
651            for noeud in self.appliEficas.listeNoeudsColores:
652                noeud.setTextColor( 0,Qt.black)
653                noeud.update_node_label()
654         self.appliEficas.listeNoeudsColores=[]
655         for noeud in liste :
656             noeud.setTextColor( 0,Qt.blue )
657             labeltext,fonte,couleur = noeud.item.GetLabelText()
658             noeud.setText(0, labeltext)        
659             self.appliEficas.listeNoeudsColores.append(noeud)
660
661     def update_node_texte_in_black(self):
662         """ Met a jour les noms des SD et valeurs des mots-cles """
663         self.setTextColor( 1,Qt.black )
664         value = self.item.GetText()
665         self.setText(1, value)
666
667     def update_node_texte(self):
668         """ Met a jour les noms des SD et valeurs des mots-cles """
669         value = self.item.GetText()
670         self.setText(1, value)
671         
672
673     def update_node_texte_in_blue(self):
674         self.setTextColor( 1,Qt.blue )
675         value = self.item.GetText()
676         self.setText(1, value)
677
678     def update_nodes(self):
679         #print 'NODE update_nodes', self.item.GetLabelText()
680         self.build_children()
681
682     def update_valid(self) :
683         """Cette methode a pour but de mettre a jour la validite du noeud
684            et de propager la demande de mise a jour a son parent
685         """
686         #print "NODE update_valid", self.item.GetLabelText()
687         self.update_node_valid()
688         try :
689           self.treeParent.update_valid()
690         except:
691           pass
692             
693     def update_texte(self):
694         """ Met a jour les noms des SD et valeurs des mots-cles """
695         #print "NODE update_texte", self.item.GetLabelText()
696         self.update_node_texte()
697         if self.isExpanded() :
698             for child in self.children:
699                 if child.isHidden() == false : child.update_texte()
700
701
702     def forceRecalculChildren(self,niveau):
703         if self.state=='recalcule' : 
704            self.state=""
705            return
706         self.state='recalcule'
707         if hasattr(self.item,'object'):
708            self.item.object.state="modified"
709         for child in self.children:
710            if niveau > 0 : child.forceRecalculChildren(niveau - 1)
711               
712         
713
714     def doPaste(self,node_selected,pos='after'):
715         """
716             Déclenche la copie de l'objet item avec pour cible
717             l'objet passé en argument : node_selected
718         """
719         #print 'je passe dans doPaste'
720         objet_a_copier = self.item.get_copie_objet()
721         child=node_selected.doPasteCommande(objet_a_copier,pos)
722         return child
723
724     def doPasteCommande(self,objet_a_copier,pos='after'):
725         """
726           Réalise la copie de l'objet passé en argument qui est nécessairement
727           une commande
728         """
729         child=None
730         try :
731           child = self.append_brother(objet_a_copier,pos)
732         except :
733            pass
734         return child
735
736     def doPastePremier(self,objet_a_copier):
737         """
738            Réalise la copie de l'objet passé en argument (objet_a_copier)
739         """
740         objet = objet_a_copier.item.get_copie_objet()
741         child = self.append_child(objet,pos='first')
742         return child
743
744     def plieToutEtReafficheSaufItem(self, itemADeplier):
745         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
746         from InterfaceQT4 import compojdc
747         if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return 
748         self.editor.deplier = False
749         for item in self.children :
750             # il ne faut pas plier les blocs 
751             from InterfaceQT4 import compobloc
752             if (isinstance(item,compobloc.Node)) : continue
753             item.setPlie()
754             if item==itemADeplier : 
755                   itemADeplier.setDeplie()
756         self.affichePanneau()
757
758     def plieToutEtReaffiche(self):
759         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
760         from InterfaceQT4 import compojdc
761         if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return 
762         self.editor.deplier = False
763         for item in self.children :
764             # il ne faut pas plier les blocs 
765             from InterfaceQT4 import compobloc
766             if (isinstance(item,compobloc.Node)) : continue
767             item.setPlie()
768         self.affichePanneau()
769
770     def deplieToutEtReaffiche(self):
771         self.editor.deplier = True
772         for item in self.children :
773             item.setDeplie()
774         self.affichePanneau()
775
776     def setPlie(self):
777         #print "je mets inhibeExpand a true dans setPlie"
778         #print "je suis dans plieTout", self.item.get_nom()
779         import compojdc
780         if self.fenetre == self.editor.fenetreCentraleAffichee  and isinstance(self.treeParent,compojdc.Node): 
781            return
782         self.tree.inhibeExpand=True
783         self.tree.collapseItem(self)
784         self.setPlieChildren()
785         self.tree.inhibeExpand=False
786         #print "je mets inhibeExpand a false dans setPlie"
787
788
789         # on ne plie pas au niveau 1
790         #   self.plie=False
791         #   for item in self.children :
792         #       item.appartientAUnNoeudPlie=False
793
794     def setPlieChildren(self):
795         #print "dans setPlieChildren pour", self.item.nom
796         self.plie=True
797         for c in self.children :
798             c.setPlieChildren()
799             #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0]
800             c.appartientAUnNoeudPlie=True
801             c.plie=True
802             #print "dans setPlieChildren plie", c.item.nom
803             c.setExpanded(False)
804
805         # Pour les blocs et les motcles list
806         # on affiche un niveau de plus
807         from InterfaceQT4 import compobloc
808         from InterfaceQT4 import compomclist
809         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
810             niveauPere=self.treeParent
811             while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) : 
812                niveauPere=niveauPere.treeParent
813             for c in self.children :
814                 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
815                 c.setExpanded(False)
816
817         # on affiche un niveau de plus
818         #if isinstance(self,compomclist.Node)  : 
819         #if isinstance(self,compobloc.Node)  : 
820         #    niveauPere=self.treeParent
821         #    while (isinstance(niveauPere,compobloc.Node)):
822         #       niveauPere=niveauPere.treeParent
823         #    for c in self.children :
824         #        c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
825
826     def setDeplie(self):
827         #print "dans setPlieChildren pour", self.item.nom
828         #print "je mets inhibeExpand a true dans setDeplie"
829         self.tree.inhibeExpand=True
830         self.plie=False
831         self.tree.expandItem(self)
832         self.setDeplieChildren()
833         self.tree.inhibeExpand=False
834         #print "je mets inhibeExpand a false dans setDePlie"
835
836     def setDeplieChildren(self):
837         #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.GetLabelText()
838         for c in self.children :
839             c.setDeplieChildren()
840             #print "dans setDeplieChildren ", c.item.nom
841             c.appartientAUnNoeudPlie=False
842             c.setExpanded(True)
843             c.plie=False
844        
845     def selectAvant(self):
846         i=self.item.jdc.etapes.index(self.item.object)
847         try :
848            cherche=self.item.jdc.etapes[i-1]
849         except :
850            cherche=self.item.jdc.etapes[-1]
851         node=None
852         for i in self.tree.racine.children :
853             if i.item.object== cherche  : 
854                node=i
855                break
856         if node : 
857           node.affichePanneau()
858           node.select()
859
860     def selectApres(self):
861         i=self.item.jdc.etapes.index(self.item.object)
862         try :
863            cherche=self.item.jdc.etapes[i+1]
864         except :
865            cherche=self.item.jdc.etapes[0]
866         node=None
867         for i in self.tree.racine.children :
868             if i.item.object== cherche  : 
869                node=i
870                break
871         if node : 
872            node.affichePanneau()
873            node.select()