Salome HOME
merge avec les devloppts de l ete
[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.appendBrother(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.GetLabelText()[0]))+" :")
218         else:   name  = tr(item.GetLabelText()[0])
219         if item.nom != tr(item.nom) : name = str(tr(item.nom)+" :")
220         value = tr(str( item.GetText() ) )
221  
222
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             if self.treeParent.item.isMCList() : self.appartientAUnNoeudPlie =  self.treeParent.appartientAUnNoeudPlie
230         else :
231             self.plie        = False
232             self.appartientAUnNoeudPlie = False
233
234         #if item.nom == "POUTRE" :print "creation d'un noeud : ", item, " ",item.nom,"", self.treeParent, self.appartientAUnNoeudPlie , self.plie
235
236         if ancien and itemExpand     : self.plie = False
237         if ancien and not itemExpand : self.plie = True 
238         if (isinstance(self.item,composimp.SIMPTreeItem)) : self.plie=False
239
240         from InterfaceQT4 import compobloc
241         from InterfaceQT4 import compomclist
242
243         ajoutAuParentduNoeud=0
244         self.treeParent=treeParent
245         while (isinstance(self.treeParent,compobloc.Node) or ( isinstance(self.treeParent,compomclist.Node) and self.treeParent.item.isMCList())) : 
246               self.treeParent.childrenComplete.append(self)
247               self.treeParent=self.treeParent.vraiParent
248         self.treeParent.childrenComplete.append(self)
249
250
251         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)) : 
252         # Le dernier or ne sert que lorsqu'on est en train de creer une liste par les validator
253            QTreeWidgetItem.__init__(self,None,mesColonnes)
254         else :
255            QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
256
257         self.setToolTip(0,self.item.get_fr())
258         self.setToolTip(1,self.item.get_fr())
259         repIcon=self.appliEficas.repIcon
260
261         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
262         self.setIcon(0,monIcone)
263
264         self.children = []
265         self.build_children()
266         self.menu=None
267         self.existeMenu=1
268
269         self.item.connect("valid",self.onValid,())
270         self.item.connect("supp" ,self.onSupp,())
271         self.item.connect("add"  ,self.onAdd,())
272
273         self.state=""
274         self.fenetre=None
275         try :
276           if self.item.getObject().isBLOC() : 
277                 self.setExpanded(True) 
278                 self.plie=False
279         except :
280           pass
281
282
283     def build_children(self,posInsertion=10000):
284         """ Construit la liste des enfants de self """
285         """ Se charge de remettre les noeuds Expanded dans le meme etat """
286         #print "*********** build_children ",self,self.item, self.item.nom
287         
288         self.listeItemExpanded=[]
289         self.listeItemPlie=[]
290
291         for enfant in self.childrenComplete :
292             if enfant.plie : self.listeItemPlie.append(enfant.item)
293             else : self.listeItemExpanded.append(enfant.item)
294
295         for enfant in self.childrenComplete :
296             parent=enfant.treeParent
297             parent.removeChild(enfant)
298             enfant.JESUISOFF=1
299          
300         
301         self.children = []
302         self.childrenComplete = []
303         sublist = self.item._GetSubList()
304         ind=0
305         
306         for item in sublist :
307             itemExpand=False
308             ancien=False
309             if item in self.listeItemExpanded : itemExpand=True;  ancien=True
310             if item in self.listeItemPlie     : itemExpand=False; ancien=True
311             nouvelItem=item.itemNode(self,item,itemExpand,ancien)
312             self.children.append(nouvelItem)
313
314         #print "fin *********** build_children ",self,self.item, self.item.nom, self.children
315
316         
317     def chercheNoeudCorrespondant(self,objSimp):
318         sublist = self.item._GetSubList()
319         for node in self.childrenComplete:
320             if node.item.object==objSimp : return node
321         return None
322
323
324     def affichePanneau(self) :
325         #if self.editor.code == 'ASTER' and not(self.item.isactif()) : 
326         # posera des pb si un code decide d appeler FIN un mot clef
327         # on resoudera a ce moment la
328         # pour l instant pas de poussiere sous le tapis
329         if  not(self.item.isactif()) : 
330             from .monWidgetInactif import MonWidgetInactif
331             self.fenetre = MonWidgetInactif(self,self.editor)
332         else:
333            itemParent=self
334            while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent 
335            if itemParent!=self : 
336               itemParent.affichePanneau()
337               return
338            self.fenetre=self.getPanel()
339            #self.editor.restoreSplitterSizes()
340          
341         for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
342             widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
343             self.editor.widgetCentraleLayout.removeItem(widget)
344         # ceinture et bretelle
345         #print 'old fenetre = ',self.editor.fenetreCentraleAffichee
346         if self.editor.fenetreCentraleAffichee != None : 
347             self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
348             self.editor.fenetreCentraleAffichee.setParent(None)
349             self.editor.fenetreCentraleAffichee.close()
350             self.editor.fenetreCentraleAffichee.deleteLater()
351
352         self.editor.widgetCentraleLayout.addWidget(self.fenetre)
353         #print ("j ajoute ", self.fenetre, self.fenetre.node.item.nom)
354         self.editor.fenetreCentraleAffichee=self.fenetre
355         self.tree.node_selected= self
356
357         if self.editor.first :
358            if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
359         self.tree.inhibeExpand=True
360         self.tree.expandItem(self)
361         self.tree.inhibeExpand=False
362         #print( 'fin affichePanneau pour', self.item.nom)
363           
364
365     def createPopUpMenu(self):
366         #implemente dans les noeuds derives si necessaire
367         self.existeMenu = 0
368
369     def commentIt(self):
370         """
371         Cette methode a pour but de commentariser la commande pointee par self
372         """
373         # On traite par une exception le cas ou l'utilisateur final cherche a desactiver
374         # (commentariser) un commentaire.
375         try :
376             pos=self.treeParent.children.index(self)
377             commande_comment = self.item.get_objet_commentarise()
378             # On signale a l editeur du panel (le JDCDisplay) une modification
379             self.editor.init_modif()
380             self.treeParent.build_children()
381             self.treeParent.children[pos].select()
382             self.treeParent.children[pos].affichePanneau()
383         except Exception as e:
384             traceback.print_exc()
385             QMessageBox.critical( self.editor, "TOO BAD",str(e))
386         
387     def unCommentIt(self):
388         """
389         Realise la decommentarisation de self
390         """
391         try :
392             pos=self.treeParent.children.index(self)
393             commande,nom = self.item.uncomment()
394             self.editor.init_modif()
395             self.treeParent.build_children()
396             self.treeParent.children[pos].select()
397             self.treeParent.children[pos].affichePanneau()
398         except Exception as e:
399             QMessageBox.critical( self.editor, "Erreur !",str(e))
400         
401     def addComment( self, after=True ):
402         """
403         Ajoute un commentaire a l'interieur du JDC :
404         """
405         self.editor.init_modif()
406         if after:
407             pos = 'after'
408         else:
409             pos = 'before'
410         return self.appendBrother( COMMENT, pos )
411                 
412     def addParameters( self, after=True ):
413         """
414         Ajoute un parametre a l'interieur du JDC :
415         """
416         self.editor.init_modif()
417         if after: pos = 'after'
418         else: pos = 'before'
419         child=self.appendBrother( PARAMETERS, pos )
420         return  child
421     
422     
423     def select( self ):
424         """
425         Rend le noeud courant (self) selectionne et deselectionne
426         tous les autres
427         """        
428         #print "select pour", self.item.nom
429         for item in self.tree.selectedItems() :
430             item.setSelected(0)
431         self.tree.setCurrentItem( self )    
432                                
433     #------------------------------------------------------------------
434     # Methodes de creation et destruction de noeuds
435     # Certaines de ces methodes peuvent etre appelees depuis l'externe
436     #------------------------------------------------------------------
437     def appendBrother(self,name,pos='after',plier=False):
438         """
439         Permet d'ajouter un objet frere a l'objet associe au noeud self
440         par defaut on l'ajoute immediatement apres 
441         Methode externe
442         """
443         self.editor.init_modif()
444
445         from InterfaceQT4 import compojdc
446         if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos)  : return 0
447         
448         if self.treeParent != self.vraiParent :
449           index = self.vraiParent.children.index(self)
450           if   pos == 'before': index = index
451           elif pos == 'after': index = index +1
452           return self.vraiParent.append_child(name,pos=index,plier=plier)
453         else :
454           index = self.treeParent.children.index(self)
455           if   pos == 'before': index = index
456           elif pos == 'after': index = index +1
457           else:
458               print(six.text_type(pos), tr("  n'est pas un index valide pour appendBrother"))
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         #import traceback
500         #traceback.print_stack()
501
502          
503         self.editor.init_modif()
504         if pos == 'first':
505             index = 0
506         elif pos == 'last':
507             index = len(self.children)
508         elif type(pos) == int :
509             # position fixee
510             index = pos
511         elif type(pos) == types.InstanceType:
512             # pos est un item. Il faut inserer name apres pos
513             index = self.item.get_index(pos) +1
514         elif type(name) == types.InstanceType:
515             index = self.item.get_index_child(name.nom)
516         else:
517             index = self.item.get_index_child(name)
518
519         # si on essaye d inserer a la racine
520         if (isinstance(self.treeParent,JDCTree) and index==0) :
521            verifiePosition=self.verifiePosition(name,'first',aLaRacine=True)
522            if not verifiePosition : return 0
523
524         self.tree.inhibeExpand=True
525         obj=self.item.additem(name,index) # emet le signal 'add'
526         if obj is None:obj=0
527         if obj == 0:return 0
528         try :
529         #if 1 :
530            child=self.children[index]
531            if plier == True : child.setPlie()
532            else             : child.setDeplie() 
533         except :
534            child=self.children[index]
535         try : 
536            if len(obj) > 1 : self.build_children()
537         except : pass
538         self.tree.inhibeExpand=False
539         #print (" fin append child")
540         return child
541
542     def deplace(self):
543         self.editor.init_modif()
544         index = self.treeParent.children.index(self) - 1 
545         if index < 0 : index =0
546         ret=self.treeParent.item.deplaceEntite(self.item.getObject())
547
548     def delete(self):
549         """ 
550             Methode externe pour la destruction de l'objet associe au noeud
551         """
552         self.editor.init_modif()
553         index = self.vraiParent.children.index(self) - 1 
554         if index < 0 : index =0
555         recalcule=0
556         if self.item.nom == "VARIABLE" :
557            recalcule=1
558            jdc=self.item.jdc
559         ret,commentaire=self.vraiParent.item.suppitem(self.item)
560         if ret==0 :
561           self.editor.affiche_infos(commentaire,Qt.red)
562         else :
563           self.editor.affiche_infos(commentaire)
564         self.treeParent.build_children()
565         if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
566         else: toselect=self.treeParent
567         if recalcule : jdc.recalcule_etat_correlation()
568         if ret==0 :
569             if self.treeParent.childrenComplete :
570                 notdeleted=self.treeParent.childrenComplete[index+1]
571                 notdeleted.select()
572         else :
573             toselect.select()
574         from InterfaceQT4 import compojdc
575         # cas ou on detruit dans l arbre sans affichage
576         if isinstance(self.treeParent,compojdc.Node) : 
577            toselect.affichePanneau()
578         else :
579            if self.treeParent.fenetre== None : return
580            #print "J appelle reaffiche de browser apres delete"
581            self.treeParent.fenetre.reaffiche(toselect)
582
583     def deleteMultiple(self,liste=()):
584         """ 
585             Methode externe pour la destruction d une liste de noeud
586         """
587         from InterfaceQT4 import compojdc 
588         self.editor.init_modif()
589         index=9999
590         recalcule=0
591         jdc=self.treeParent
592         parentPosition=jdc
593         while not(isinstance(jdc,compojdc.Node)):
594               jdc=jdc.treeParent
595         for noeud in liste :
596             if not( isinstance(noeud.treeParent, compojdc.Node)): continue
597             if noeud.item.nom == "VARIABLE" : recalcule=1
598             if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
599         if index < 0 : index =0
600
601         # Cas ou on detruit dans une ETape
602         if index == 9999 : 
603               parentPosition=self.treeParent
604               while not(isinstance(parentPosition, compojdc.Node)):
605                  index=parentPosition.treeParent.children.index(parentPosition)
606                  parentPosition=parentPosition.treeParent
607
608         for noeud in liste:
609             noeud.treeParent.item.suppitem(noeud.item)
610
611         jdc.build_children()
612         if recalcule : jdc.recalcule_etat_correlation()
613         try    : toselect=parentPosition.children[index]
614         except : toselect=jdc
615         toselect.select()
616         toselect.affichePanneau()
617 #        
618 #    #------------------------------------------------------------------
619     def onValid(self):        
620
621         #print "onValid pour ", self.item.nom
622         if self.JESUISOFF==1 : return
623         if hasattr(self,'fenetre') and self.fenetre: 
624            try :
625              self.fenetre.setValide()
626            except :
627             # print "onValid pour ", self.item.nom, self,'pb'
628             pass
629
630         if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isvalid():
631            self.item.jdc.recalcule_etat_correlation()
632         if hasattr(self.item,'forceRecalcul'):
633            self.forceRecalculChildren(self.item.forceRecalcul)
634         self.editor.init_modif()
635         
636         self.update_node_valid()
637         self.update_node_label()
638         self.update_node_texte()
639
640     def onAdd(self,object):
641         if self.JESUISOFF==1 : return
642         #print "onAdd pour ", self.item.nom, object.nom
643         self.editor.init_modif()
644         self.update_nodes()
645         # PN -- non necessaire si item=jdc
646         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
647  
648     def onSupp(self,object):
649         if self.JESUISOFF==1 : return
650         #print "onSup pour ", self.item.nom, object.nom
651         self.editor.init_modif()
652         self.update_nodes()
653         # PN -- non necessaire si item=jdc
654         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
655          
656
657
658     def update_node_valid(self):
659         """Cette methode remet a jour la validite du noeud (icone)
660            Elle appelle isvalid
661         """
662         repIcon=self.appliEficas.repIcon
663         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
664         self.setIcon(0,monIcone)
665
666
667     def update_node_label(self):
668         """ Met a jour le label du noeud """
669         #print "NODE update_node_label", self.item.GetLabelText()
670         labeltext,fonte,couleur = self.item.GetLabelText()
671         # PNPN a reflechir
672         self.setText(0, labeltext)        
673     
674     def update_node_label_in_black(self):
675         if hasattr(self.appliEficas,'noeudColore'): 
676             self.appliEficas.noeudColore.setForeground(0,Qt.black)
677             self.appliEficas.noeudColore.update_node_label
678     
679     def update_node_label_in_blue(self):
680         if hasattr(self.appliEficas,'noeudColore'): self.appliEficas.noeudColore.setForeground(0,Qt.black)
681         self.setForeground(0,Qt.blue)
682         labeltext,fonte,couleur = self.item.GetLabelText()
683         self.setText(0, labeltext)        
684         self.appliEficas.noeudColore=self
685
686     def update_plusieurs_node_label_in_blue(self,liste):
687         if hasattr(self.appliEficas,'listeNoeudsColores'):
688            for noeud in self.appliEficas.listeNoeudsColores:
689                noeud.setTextColor( 0,Qt.black)
690                noeud.update_node_label()
691         self.appliEficas.listeNoeudsColores=[]
692         for noeud in liste :
693             noeud.setTextColor( 0,Qt.blue )
694             labeltext,fonte,couleur = noeud.item.GetLabelText()
695             noeud.setText(0, labeltext)        
696             self.appliEficas.listeNoeudsColores.append(noeud)
697
698     def update_node_texte_in_black(self):
699         """ Met a jour les noms des SD et valeurs des mots-cles """
700         self.setTextColor( 1,Qt.black )
701         value = self.item.GetText()
702         self.setText(1, value)
703
704     def update_node_texte(self):
705         """ Met a jour les noms des SD et valeurs des mots-cles """
706         value = self.item.GetText()
707         self.setText(1, value)
708         
709
710     def update_node_texte_in_blue(self):
711         self.setTextColor( 1,Qt.blue )
712         value = self.item.GetText()
713         self.setText(1, value)
714
715     def update_nodes(self):
716         #print 'NODE update_nodes', self.item.GetLabelText()
717         self.build_children()
718
719     def update_valid(self) :
720         """Cette methode a pour but de mettre a jour la validite du noeud
721            et de propager la demande de mise a jour a son parent
722         """
723         #print "NODE update_valid", self.item.GetLabelText()
724         self.update_node_valid()
725         try :
726           self.treeParent.update_valid()
727         except:
728           pass
729             
730     def update_texte(self):
731         """ Met a jour les noms des SD et valeurs des mots-cles """
732         #print "NODE update_texte", self.item.GetLabelText()
733         self.update_node_texte()
734         if self.isExpanded() :
735             for child in self.children:
736                 if child.isHidden() == false : child.update_texte()
737
738
739     def forceRecalculChildren(self,niveau):
740         if self.state=='recalcule' : 
741            self.state=""
742            return
743         self.state='recalcule'
744         if hasattr(self.item,'object'):
745            self.item.object.state="modified"
746         for child in self.children:
747            if niveau > 0 : child.forceRecalculChildren(niveau - 1)
748               
749         
750
751     def doPaste(self,node_selected,pos='after'):
752         """
753             Declenche la copie de l'objet item avec pour cible
754             l'objet passe en argument : node_selected
755         """
756         objet_a_copier = self.item.get_copie_objet()
757         child=node_selected.doPasteCommande(objet_a_copier,pos)
758         if self.editor.fenetreCentraleAffichee : self.editor.fenetreCentraleAffichee.node.affichePanneau()
759         self.update_node_label_in_black()
760         return child
761
762     def doPasteCommande(self,objet_a_copier,pos='after'):
763         """
764           Realise la copie de l'objet passe en argument qui est necessairement
765           un onjet
766         """
767         child=None
768         try :
769         #if 1 :
770           child = self.appendBrother(objet_a_copier,pos)
771         except :
772            pass
773         return child
774
775     def doPastePremier(self,objet_a_copier):
776         """
777            Realise la copie de l'objet passe en argument (objet_a_copier)
778         """
779         objet = objet_a_copier.item.get_copie_objet()
780         child = self.append_child(objet,pos='first')
781         return child
782
783     def plieToutEtReafficheSaufItem(self, itemADeplier):
784         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
785         self.inhibeExpand=True
786         from InterfaceQT4 import compojdc
787         if (isinstance(self, compojdc.Node)) :
788             self.affichePanneau()
789             self.inhibeExpand=False
790             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             if item==itemADeplier : 
798                   itemADeplier.setDeplie()
799         self.affichePanneau()
800         self.inhibeExpand=False
801
802     def plieToutEtReaffiche(self):
803         from InterfaceQT4 import compojdc
804         if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return 
805         self.inhibeExpand=True
806         self.editor.deplier = False
807         for item in self.children :
808             # il ne faut pas plier les blocs 
809             from InterfaceQT4 import compobloc
810             if (isinstance(item,compobloc.Node)) : continue
811             item.setPlie()
812         self.affichePanneau()
813
814     def deplieToutEtReaffiche(self):
815         self.editor.deplier = True
816         for item in self.children :
817             item.setDeplie()
818         self.affichePanneau()
819
820     def setPlie(self):
821         #print "je mets inhibeExpand a true dans setPlie"
822         #print "je suis dans plieTout", self.item.get_nom()
823         from . import compojdc
824         if self.fenetre == self.editor.fenetreCentraleAffichee  and isinstance(self.treeParent,compojdc.Node): 
825            return
826         self.tree.inhibeExpand=True
827         self.tree.collapseItem(self)
828         self.setPlieChildren()
829         self.tree.inhibeExpand=False
830         #print "je mets inhibeExpand a false dans setPlie"
831
832
833         # on ne plie pas au niveau 1
834         #   self.plie=False
835         #   for item in self.children :
836         #       item.appartientAUnNoeudPlie=False
837
838     def setPlieChildren(self):
839         #print ("dans setPlieChildren pour", self.item.nom)
840         self.plie=True
841         for c in self.children :
842             c.setPlieChildren()
843             #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0]
844             c.appartientAUnNoeudPlie=True
845             c.plie=True
846             #print "dans setPlieChildren plie", c.item.nom
847             c.setExpanded(False)
848
849         # Pour les blocs et les motcles list
850         # on affiche un niveau de plus
851         from InterfaceQT4 import compobloc
852         from InterfaceQT4 import compomclist
853         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
854             niveauPere=self.treeParent
855             while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) : 
856                niveauPere=niveauPere.treeParent
857             for c in self.children :
858                 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
859                 #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0], "mis a la valeur ", niveauPere.appartientAUnNoeudPlie
860                 c.setExpanded(False)
861
862         # on affiche un niveau de plus
863         #if isinstance(self,compomclist.Node)  : 
864         #if isinstance(self,compobloc.Node)  : 
865         #    niveauPere=self.treeParent
866         #    while (isinstance(niveauPere,compobloc.Node)):
867         #       niveauPere=niveauPere.treeParent
868         #    for c in self.children :
869         #        c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
870
871     def setDeplie(self):
872         #print "dans setPlieChildren pour", self.item.nom
873         #print "je mets inhibeExpand a true dans setDeplie"
874         self.tree.inhibeExpand=True
875         self.plie=False
876         self.tree.expandItem(self)
877         self.setDeplieChildren()
878         self.tree.inhibeExpand=False
879         #print "je mets inhibeExpand a false dans setDePlie"
880
881     def setDeplieChildren(self):
882         #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.GetLabelText()
883         for c in self.children :
884             c.setDeplieChildren()
885             #print "dans setDeplieChildren ", c.item.nom
886             c.appartientAUnNoeudPlie=False
887             c.setExpanded(True)
888             c.plie=False
889        
890     def selectAvant(self):
891         i=self.item.jdc.etapes.index(self.item.object)
892         try :
893            cherche=self.item.jdc.etapes[i-1]
894         except :
895            cherche=self.item.jdc.etapes[-1]
896         node=None
897         for i in self.tree.racine.children :
898             if i.item.object== cherche  : 
899                node=i
900                break
901         if node : 
902           node.affichePanneau()
903           node.select()
904
905     def selectApres(self):
906         i=self.item.jdc.etapes.index(self.item.object)
907         try :
908            cherche=self.item.jdc.etapes[i+1]
909         except :
910            cherche=self.item.jdc.etapes[0]
911         node=None
912         for i in self.tree.racine.children :
913             if i.item.object== cherche  : 
914                node=i
915                break
916         if node : 
917            node.affichePanneau()
918            node.select()
919
920     def ouvreLesNoeudsDsLArbre(self):
921         return
922         self.inhibeExpand = True 
923         for i in range(self.childCount()):
924             self.child(i).inhibeExpand=True
925             self.child(i).setExpanded(True)
926             self.child(i).ouvreLesNoeudsDsLArbre()
927             self.child(i).inhibeExpand=False
928         self.inhibeExpand = False