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