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