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