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