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