Salome HOME
0db619cb2d1642a17ba7ec672b189ad72928f11b
[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.GetLabelText()[0]))+" :")
218         else:   name  = tr(str(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         #print( 'debut affichePanneau pour', self.item.nom)
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            #self.editor.restoreSplitterSizes()
341          
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         if self.editor.fenetreCentraleAffichee != None : 
348             self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
349             self.editor.fenetreCentraleAffichee.setParent(None)
350             self.editor.fenetreCentraleAffichee.close()
351             self.editor.fenetreCentraleAffichee.deleteLater()
352
353         self.editor.widgetCentraleLayout.addWidget(self.fenetre)
354         #print ("j ajoute ", self.fenetre, self.fenetre.node.item.nom)
355         self.editor.fenetreCentraleAffichee=self.fenetre
356         self.tree.node_selected= self
357
358         if self.editor.first :
359            if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
360         self.tree.inhibeExpand=True
361         self.tree.expandItem(self)
362         self.tree.inhibeExpand=False
363         #print( 'fin affichePanneau pour', self.item.nom)
364           
365
366     def createPopUpMenu(self):
367         #implemente dans les noeuds derives si necessaire
368         self.existeMenu = 0
369
370     def commentIt(self):
371         """
372         Cette methode a pour but de commentariser la commande pointee par self
373         """
374         # On traite par une exception le cas ou l'utilisateur final cherche a desactiver
375         # (commentariser) un commentaire.
376         try :
377             pos=self.treeParent.children.index(self)
378             commande_comment = self.item.get_objet_commentarise()
379             # On signale a l editeur du panel (le JDCDisplay) une modification
380             self.editor.init_modif()
381             self.treeParent.build_children()
382             self.treeParent.children[pos].select()
383             self.treeParent.children[pos].affichePanneau()
384         except Exception as e:
385             traceback.print_exc()
386             QMessageBox.critical( self.editor, "TOO BAD",str(e))
387         
388     def unCommentIt(self):
389         """
390         Realise la decommentarisation de self
391         """
392         try :
393             pos=self.treeParent.children.index(self)
394             commande,nom = self.item.uncomment()
395             self.editor.init_modif()
396             self.treeParent.build_children()
397             self.treeParent.children[pos].select()
398             self.treeParent.children[pos].affichePanneau()
399         except Exception as e:
400             QMessageBox.critical( self.editor, "Erreur !",str(e))
401         
402     def addComment( self, after=True ):
403         """
404         Ajoute un commentaire a l'interieur du JDC :
405         """
406         self.editor.init_modif()
407         if after:
408             pos = 'after'
409         else:
410             pos = 'before'
411         return self.append_brother( COMMENT, pos )
412                 
413     def addParameters( self, after=True ):
414         """
415         Ajoute un parametre a l'interieur du JDC :
416         """
417         self.editor.init_modif()
418         if after: pos = 'after'
419         else: pos = 'before'
420         child=self.append_brother( PARAMETERS, pos )
421         return  child
422     
423     
424     def select( self ):
425         """
426         Rend le noeud courant (self) selectionne et deselectionne
427         tous les autres
428         """        
429         #print "select pour", self.item.nom
430         for item in self.tree.selectedItems() :
431             item.setSelected(0)
432         self.tree.setCurrentItem( self )    
433                                
434     #------------------------------------------------------------------
435     # Methodes de creation et destruction de noeuds
436     # Certaines de ces methodes peuvent etre appelees depuis l'externe
437     #------------------------------------------------------------------
438     def append_brother(self,name,pos='after',plier=False):
439         """
440         Permet d'ajouter un objet frere a l'objet associe au noeud self
441         par defaut on l'ajoute immediatement apres 
442         Methode externe
443         """
444         self.editor.init_modif()
445
446         from InterfaceQT4 import compojdc
447         if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos)  : return 0
448         
449         if self.treeParent != self.vraiParent :
450           index = self.vraiParent.children.index(self)
451           if   pos == 'before': index = index
452           elif pos == 'after': index = index +1
453           return self.vraiParent.append_child(name,pos=index,plier=plier)
454         else :
455           index = self.treeParent.children.index(self)
456           if   pos == 'before': index = index
457           elif pos == 'after': index = index +1
458           else:
459               print(six.text_type(pos), tr("  n'est pas un index valide pour append_brother"))
460               return 0
461           return self.treeParent.append_child(name,pos=index,plier=plier)
462
463     def verifiePosition(self,name,pos,aLaRacine=False):
464         if name not in self.editor.Classement_Commandes_Ds_Arbre : return True
465         indexName=self.editor.Classement_Commandes_Ds_Arbre.index(name)
466
467         etapes=self.item.get_jdc().etapes
468         if etapes == [] : return True
469
470         if aLaRacine == False :indexOu=etapes.index(self.item.object)
471         else : indexOu=0
472
473         if pos=="after" : indexOu = indexOu+1
474         for e in etapes[:indexOu] :
475             nom=e.nom
476             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
477             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
478             if indexEtape > indexName :
479                comment=tr('le mot clef ')+name+tr(' doit etre insere avant ')+nom
480                QMessageBox.information( None,tr('insertion impossible'),comment, )
481                return False
482         for e in etapes[indexOu:] :
483             nom=e.nom
484             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
485             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
486             if indexEtape < indexName :
487                comment=tr('le mot clef ')+name+tr(' doit etre insere apres ')+nom
488                QMessageBox.information( None,tr('insertion impossible'),comment, )
489                return False
490         return True
491
492     def append_child(self,name,pos=None,plier=False):
493         """
494            Methode pour ajouter un objet fils a l'objet associe au noeud self.
495            On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
496            ou en position intermediaire.
497            Si pos vaut None, on le place a la position du catalogue.
498         """
499         #print ("************** append_child ",self.item.GetLabelText(), plier)
500         #import traceback
501         #traceback.print_stack()
502
503          
504         self.editor.init_modif()
505         if pos == 'first':
506             index = 0
507         elif pos == 'last':
508             index = len(self.children)
509         elif type(pos) == int :
510             # position fixee
511             index = pos
512         elif type(pos) == types.InstanceType:
513             # pos est un item. Il faut inserer name apres pos
514             index = self.item.get_index(pos) +1
515         elif type(name) == types.InstanceType:
516             index = self.item.get_index_child(name.nom)
517         else:
518             index = self.item.get_index_child(name)
519
520         # si on essaye d inserer a la racine
521         if (isinstance(self.treeParent,JDCTree) and index==0) :
522            verifiePosition=self.verifiePosition(name,'first',aLaRacine=True)
523            if not verifiePosition : return 0
524
525         self.tree.inhibeExpand=True
526         obj=self.item.additem(name,index) # emet le signal 'add'
527         if obj is None:obj=0
528         if obj == 0:return 0
529         try :
530            child=self.children[index]
531            if plier == True : child.setPlie()
532            else             : child.setDeplie() 
533         except :
534            child=self.children[index]
535         self.tree.inhibeExpand=False
536         #print (" fin append child")
537         return child
538
539     def deplace(self):
540         self.editor.init_modif()
541         index = self.treeParent.children.index(self) - 1 
542         if index < 0 : index =0
543         ret=self.treeParent.item.deplaceEntite(self.item.getObject())
544
545     def delete(self):
546         """ 
547             Methode externe pour la destruction de l'objet associe au noeud
548         """
549         self.editor.init_modif()
550         index = self.vraiParent.children.index(self) - 1 
551         if index < 0 : index =0
552         recalcule=0
553         if self.item.nom == "VARIABLE" :
554            recalcule=1
555            jdc=self.item.jdc
556         ret,commentaire=self.vraiParent.item.suppitem(self.item)
557         if ret==0 :
558           self.editor.affiche_infos(commentaire,Qt.red)
559         else :
560           self.editor.affiche_infos(commentaire)
561         self.treeParent.build_children()
562         if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
563         else: toselect=self.treeParent
564         if recalcule : jdc.recalcule_etat_correlation()
565         if ret==0 :
566             if self.treeParent.childrenComplete :
567                 notdeleted=self.treeParent.childrenComplete[index+1]
568                 notdeleted.select()
569         else :
570             toselect.select()
571         from InterfaceQT4 import compojdc
572         # cas ou on detruit dans l arbre sans affichage
573         if isinstance(self.treeParent,compojdc.Node) : 
574            toselect.affichePanneau()
575         else :
576            if self.treeParent.fenetre== None : return
577            #print "J appelle reaffiche de browser apres delete"
578            self.treeParent.fenetre.reaffiche(toselect)
579
580     def deleteMultiple(self,liste=()):
581         """ 
582             Methode externe pour la destruction d une liste de noeud
583         """
584         from InterfaceQT4 import compojdc 
585         self.editor.init_modif()
586         index=9999
587         recalcule=0
588         jdc=self.treeParent
589         parentPosition=jdc
590         while not(isinstance(jdc,compojdc.Node)):
591               jdc=jdc.treeParent
592         for noeud in liste :
593             if not( isinstance(noeud.treeParent, compojdc.Node)): continue
594             if noeud.item.nom == "VARIABLE" : recalcule=1
595             if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
596         if index < 0 : index =0
597
598         # Cas ou on detruit dans une ETape
599         if index == 9999 : 
600               parentPosition=self.treeParent
601               while not(isinstance(parentPosition, compojdc.Node)):
602                  index=parentPosition.treeParent.children.index(parentPosition)
603                  parentPosition=parentPosition.treeParent
604
605         for noeud in liste:
606             noeud.treeParent.item.suppitem(noeud.item)
607
608         jdc.build_children()
609         if recalcule : jdc.recalcule_etat_correlation()
610         try    : toselect=parentPosition.children[index]
611         except : toselect=jdc
612         toselect.select()
613         toselect.affichePanneau()
614 #        
615 #    #------------------------------------------------------------------
616     def onValid(self):        
617
618         #print "onValid pour ", self.item.nom
619         if self.JESUISOFF==1 : return
620         if hasattr(self,'fenetre') and self.fenetre: 
621            try :
622              self.fenetre.setValide()
623            except :
624             # print "onValid pour ", self.item.nom, self,'pb'
625             pass
626
627         if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isvalid():
628            self.item.jdc.recalcule_etat_correlation()
629         if hasattr(self.item,'forceRecalcul'):
630            self.forceRecalculChildren(self.item.forceRecalcul)
631         self.editor.init_modif()
632         
633         self.update_node_valid()
634         self.update_node_label()
635         self.update_node_texte()
636
637     def onAdd(self,object):
638         if self.JESUISOFF==1 : return
639         #print "onAdd pour ", self.item.nom, object.nom
640         self.editor.init_modif()
641         self.update_nodes()
642         # PN -- non necessaire si item=jdc
643         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
644  
645     def onSupp(self,object):
646         if self.JESUISOFF==1 : return
647         #print "onSup pour ", self.item.nom, object.nom
648         self.editor.init_modif()
649         self.update_nodes()
650         # PN -- non necessaire si item=jdc
651         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
652          
653
654
655     def update_node_valid(self):
656         """Cette methode remet a jour la validite du noeud (icone)
657            Elle appelle isvalid
658         """
659         repIcon=self.appliEficas.repIcon
660         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
661         self.setIcon(0,monIcone)
662
663
664     def update_node_label(self):
665         """ Met a jour le label du noeud """
666         #print "NODE update_node_label", self.item.GetLabelText()
667         labeltext,fonte,couleur = self.item.GetLabelText()
668         # PNPN a reflechir
669         self.setText(0, labeltext)        
670     
671     def update_node_label_in_black(self):
672         if hasattr(self.appliEficas,'noeudColore'): 
673             self.appliEficas.noeudColore.setForeground(0,Qt.black)
674             self.appliEficas.noeudColore.update_node_label
675     
676     def update_node_label_in_blue(self):
677         if hasattr(self.appliEficas,'noeudColore'): self.appliEficas.noeudColore.setForeground(0,Qt.black)
678         self.setForeground(0,Qt.blue)
679         labeltext,fonte,couleur = self.item.GetLabelText()
680         self.setText(0, labeltext)        
681         self.appliEficas.noeudColore=self
682
683     def update_plusieurs_node_label_in_blue(self,liste):
684         if hasattr(self.appliEficas,'listeNoeudsColores'):
685            for noeud in self.appliEficas.listeNoeudsColores:
686                noeud.setTextColor( 0,Qt.black)
687                noeud.update_node_label()
688         self.appliEficas.listeNoeudsColores=[]
689         for noeud in liste :
690             noeud.setTextColor( 0,Qt.blue )
691             labeltext,fonte,couleur = noeud.item.GetLabelText()
692             noeud.setText(0, labeltext)        
693             self.appliEficas.listeNoeudsColores.append(noeud)
694
695     def update_node_texte_in_black(self):
696         """ Met a jour les noms des SD et valeurs des mots-cles """
697         self.setTextColor( 1,Qt.black )
698         value = self.item.GetText()
699         self.setText(1, value)
700
701     def update_node_texte(self):
702         """ Met a jour les noms des SD et valeurs des mots-cles """
703         value = self.item.GetText()
704         self.setText(1, value)
705         
706
707     def update_node_texte_in_blue(self):
708         self.setTextColor( 1,Qt.blue )
709         value = self.item.GetText()
710         self.setText(1, value)
711
712     def update_nodes(self):
713         #print 'NODE update_nodes', self.item.GetLabelText()
714         self.build_children()
715
716     def update_valid(self) :
717         """Cette methode a pour but de mettre a jour la validite du noeud
718            et de propager la demande de mise a jour a son parent
719         """
720         #print "NODE update_valid", self.item.GetLabelText()
721         self.update_node_valid()
722         try :
723           self.treeParent.update_valid()
724         except:
725           pass
726             
727     def update_texte(self):
728         """ Met a jour les noms des SD et valeurs des mots-cles """
729         #print "NODE update_texte", self.item.GetLabelText()
730         self.update_node_texte()
731         if self.isExpanded() :
732             for child in self.children:
733                 if child.isHidden() == false : child.update_texte()
734
735
736     def forceRecalculChildren(self,niveau):
737         if self.state=='recalcule' : 
738            self.state=""
739            return
740         self.state='recalcule'
741         if hasattr(self.item,'object'):
742            self.item.object.state="modified"
743         for child in self.children:
744            if niveau > 0 : child.forceRecalculChildren(niveau - 1)
745               
746         
747
748     def doPaste(self,node_selected,pos='after'):
749         """
750             Declenche la copie de l'objet item avec pour cible
751             l'objet passe en argument : node_selected
752         """
753         objet_a_copier = self.item.get_copie_objet()
754         child=node_selected.doPasteCommande(objet_a_copier,pos)
755         if self.editor.fenetreCentraleAffichee : self.editor.fenetreCentraleAffichee.node.affichePanneau()
756         self.update_node_label_in_black()
757         return child
758
759     def doPasteCommande(self,objet_a_copier,pos='after'):
760         """
761           Realise la copie de l'objet passe en argument qui est necessairement
762           un onjet
763         """
764         child=None
765         try :
766         #if 1 :
767           child = self.append_brother(objet_a_copier,pos)
768         except :
769            pass
770         return child
771
772     def doPastePremier(self,objet_a_copier):
773         """
774            Realise la copie de l'objet passe en argument (objet_a_copier)
775         """
776         objet = objet_a_copier.item.get_copie_objet()
777         child = self.append_child(objet,pos='first')
778         return child
779
780     def plieToutEtReafficheSaufItem(self, itemADeplier):
781         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
782         self.inhibeExpand=True
783         from InterfaceQT4 import compojdc
784         if (isinstance(self, compojdc.Node)) :
785             self.affichePanneau()
786             self.inhibeExpand=False
787             return 
788         self.editor.deplier = False
789         for item in self.children :
790             # il ne faut pas plier les blocs 
791             from InterfaceQT4 import compobloc
792             if (isinstance(item,compobloc.Node)) : continue
793             item.setPlie()
794             if item==itemADeplier : 
795                   itemADeplier.setDeplie()
796         self.affichePanneau()
797         self.inhibeExpand=False
798
799     def plieToutEtReaffiche(self):
800         from InterfaceQT4 import compojdc
801         if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return 
802         self.inhibeExpand=True
803         self.editor.deplier = False
804         for item in self.children :
805             # il ne faut pas plier les blocs 
806             from InterfaceQT4 import compobloc
807             if (isinstance(item,compobloc.Node)) : continue
808             item.setPlie()
809         self.affichePanneau()
810
811     def deplieToutEtReaffiche(self):
812         self.editor.deplier = True
813         for item in self.children :
814             item.setDeplie()
815         self.affichePanneau()
816
817     def setPlie(self):
818         #print "je mets inhibeExpand a true dans setPlie"
819         #print "je suis dans plieTout", self.item.get_nom()
820         from . import compojdc
821         if self.fenetre == self.editor.fenetreCentraleAffichee  and isinstance(self.treeParent,compojdc.Node): 
822            return
823         self.tree.inhibeExpand=True
824         self.tree.collapseItem(self)
825         self.setPlieChildren()
826         self.tree.inhibeExpand=False
827         #print "je mets inhibeExpand a false dans setPlie"
828
829
830         # on ne plie pas au niveau 1
831         #   self.plie=False
832         #   for item in self.children :
833         #       item.appartientAUnNoeudPlie=False
834
835     def setPlieChildren(self):
836         #print "dans setPlieChildren pour", self.item.nom
837         self.plie=True
838         for c in self.children :
839             c.setPlieChildren()
840             #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0]
841             c.appartientAUnNoeudPlie=True
842             c.plie=True
843             #print "dans setPlieChildren plie", c.item.nom
844             c.setExpanded(False)
845
846         # Pour les blocs et les motcles list
847         # on affiche un niveau de plus
848         from InterfaceQT4 import compobloc
849         from InterfaceQT4 import compomclist
850         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
851             niveauPere=self.treeParent
852             while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) : 
853                niveauPere=niveauPere.treeParent
854             for c in self.children :
855                 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
856                 #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0], "mis a la valeur ", niveauPere.appartientAUnNoeudPlie
857                 c.setExpanded(False)
858
859         # on affiche un niveau de plus
860         #if isinstance(self,compomclist.Node)  : 
861         #if isinstance(self,compobloc.Node)  : 
862         #    niveauPere=self.treeParent
863         #    while (isinstance(niveauPere,compobloc.Node)):
864         #       niveauPere=niveauPere.treeParent
865         #    for c in self.children :
866         #        c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
867
868     def setDeplie(self):
869         #print "dans setPlieChildren pour", self.item.nom
870         #print "je mets inhibeExpand a true dans setDeplie"
871         self.tree.inhibeExpand=True
872         self.plie=False
873         self.tree.expandItem(self)
874         self.setDeplieChildren()
875         self.tree.inhibeExpand=False
876         #print "je mets inhibeExpand a false dans setDePlie"
877
878     def setDeplieChildren(self):
879         #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.GetLabelText()
880         for c in self.children :
881             c.setDeplieChildren()
882             #print "dans setDeplieChildren ", c.item.nom
883             c.appartientAUnNoeudPlie=False
884             c.setExpanded(True)
885             c.plie=False
886        
887     def selectAvant(self):
888         i=self.item.jdc.etapes.index(self.item.object)
889         try :
890            cherche=self.item.jdc.etapes[i-1]
891         except :
892            cherche=self.item.jdc.etapes[-1]
893         node=None
894         for i in self.tree.racine.children :
895             if i.item.object== cherche  : 
896                node=i
897                break
898         if node : 
899           node.affichePanneau()
900           node.select()
901
902     def selectApres(self):
903         i=self.item.jdc.etapes.index(self.item.object)
904         try :
905            cherche=self.item.jdc.etapes[i+1]
906         except :
907            cherche=self.item.jdc.etapes[0]
908         node=None
909         for i in self.tree.racine.children :
910             if i.item.object== cherche  : 
911                node=i
912                break
913         if node : 
914            node.affichePanneau()
915            node.select()
916
917     def ouvreLesNoeudsDsLArbre(self):
918         return
919         self.inhibeExpand = True 
920         for i in range(self.childCount()):
921             self.child(i).inhibeExpand=True
922             self.child(i).setExpanded(True)
923             self.child(i).ouvreLesNoeudsDsLArbre()
924             self.child(i).inhibeExpand=False
925         self.inhibeExpand = False