1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 from __future__ import absolute_import
22 from __future__ import print_function
24 from builtins import str
25 from builtins import range
31 from . import typeNode
34 from six.moves import range
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
43 #------------------------------------------
44 class JDCTree( QTreeWidget,GereRegles ):
45 #------------------------------------------
47 def __init__( self, jdc_item, QWParent):
48 #if hasattr(QWParent,'widgetTree') :
49 self.editor = QWParent
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")
58 self.headerItem().setText(0, "Commande ")
59 self.setColumnWidth(0,200)
60 self.setExpandsOnDoubleClick(False)
61 self.setSelectionMode(3)
63 QTreeWidget.__init__(self, None )
66 self.appliEficas = self.editor.appliEficas
67 self.childrenComplete=[]
68 self.racine=self.item.itemNode(self,self.item)
72 self.itemClicked.connect(self.handleOnItem)
73 self.itemCollapsed.connect(self.handleCollapsedItem)
74 self.itemExpanded.connect(self.handleExpandedItem)
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()
88 #self.editor.initSplitterSizes(2)
89 self.racine.affichePanneau()
90 #print self.editor.splitter.sizes()
94 def contextMenuEvent(self,event) :
95 #print "contextMenuEvent"
96 coord=event.globalPos()
97 item= self.currentItem()
98 self.handleContextMenu(item,coord)
100 def handleContextMenu(self,item,coord):
102 Private slot to show the context menu of the listview.
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
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)
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
126 while not (hasattr (itemParent,'getPanel')) :
127 itemParent=itemParent.treeParent
128 if self.tree.node_selected != itemParent :
129 item.setExpanded(False)
134 item.plieToutEtReaffiche()
137 def handleExpandedItem(self,item):
138 #print ("handleExpandedItem pour ", item.item.nom, self.inhibeExpand)
140 #traceback.print_stack()
141 if self.inhibeExpand == True : return
142 self.itemCourant=item
143 self.inhibeExpand = True
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
152 item.deplieToutEtReaffiche()
153 self.inhibeExpand = False
156 def handleOnItem(self,item,int):
157 #print ("je passe dans handleOnItem pour ",self, item.item.nom, item, item.item, item.item.getLabelText())
159 from InterfaceQT4 import composimp
160 self.inhibeExpand = True
161 self.itemCourant=item
164 while not (hasattr (itemParent,'getPanel')) :
165 if itemParent.plie==True : itemParent.setDeplie()
167 itemParent=itemParent.treeParent
169 if itemParent.fenetre != self.editor.fenetreCentraleAffichee :
170 estUneFeuille=(isinstance(item,composimp.Node))
171 # il faut afficher le parent
172 if estUneFeuille and itemParent.fenetreIhm=='deplie1Niveau' :
173 itemAvant.afficheCeNiveau()
175 if estUneFeuille : itemParent.affichePanneau()
176 elif self.editor.maConfiguration.afficheCommandesPliees : itemParent.plieToutEtReafficheSaufItem(item)
177 else : itemParent.affichePanneau()
180 elif (isinstance(item,composimp.Node)) and item.fenetre : item.fenetre.rendVisible()
181 elif itemParent!=item:
182 self.tree.handleExpandedItem(item)
183 #item.fenetre.donnePremier()
184 #item.fenetre.rendActif()
185 #print 'il faut afficher le 1er'
188 fr = item.item.getFr()
189 chaineDecoupee= fr.split('\n')
190 if len(chaineDecoupee) > 3 :
191 txt='\n'.join(chaineDecoupee[0:2])+'...\nfull help : double clicked on validity chip of '+ str(item.item.nom)+ ' in central widget'
195 self.editor.afficheCommentaire(six.text_type(txt))
199 self.inhibeExpand = False
200 #print "je mets inhibeExpand a false handleOnItem"
203 def choisitPremier(self,name):
204 self.editor.layoutJDCCHOIX.removeWidget(self.racine.fenetre)
205 self.racine.fenetre.close()
206 new_node=self.racine.appendBrother(name,'after')
209 COMMENT = "COMMENTAIRE"
210 PARAMETERS = "PARAMETRE"
212 #------------------------------------------
213 class JDCNode(QTreeWidgetItem,GereRegles):
214 #------------------------------------------
215 def __init__( self, treeParent, item, itemExpand=False, ancien=False ):
216 #print ("creation d'un noeud : ", item, " ",item.nom,"", treeParent, self)
221 self.vraiParent = treeParent
222 self.treeParent = treeParent
223 self.tree = self.treeParent.tree
224 self.editor = self.treeParent.editor
225 self.appliEficas = treeParent.appliEficas
227 self.childrenComplete=[]
230 from InterfaceQT4 import compocomm
231 from InterfaceQT4 import compoparam
232 from InterfaceQT4 import composimp
233 if (isinstance(self.item,compocomm.COMMTreeItem)) : name=tr("Commentaire")
234 elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=tr(str(item.getLabelText()[0]))
235 #else: name = tr(str(tr(item.getLabelText()[0]))+" :")
236 else: name = tr(item.getLabelText()[0])
237 if item.nom != tr(item.nom) : name = str(tr(item.nom)+" :")
238 value = tr(str( item.getText() ) )
240 # si specialisation de la fenetre
241 if self.item.object.definition == None : self.fenetreIhm = None
242 # Cas des listes de mots_clefs
243 else : self.fenetreIhm = self.item.object.definition.fenetreIhm
245 if self.editor.enteteQTree=='complet':mesColonnes=(name,value)
246 else : mesColonnes=(name,)
248 if self.treeParent.plie==True :
250 self.appartientAUnNoeudPlie=True
251 if self.treeParent.item.isMCList() : self.appartientAUnNoeudPlie = self.treeParent.appartientAUnNoeudPlie
254 self.appartientAUnNoeudPlie = False
256 #if item.nom == "POUTRE" :print "creation d'un noeud : ", item, " ",item.nom,"", self.treeParent, self.appartientAUnNoeudPlie , self.plie
258 if ancien and itemExpand : self.plie = False
259 if ancien and not itemExpand : self.plie = True
260 if (isinstance(self.item,composimp.SIMPTreeItem)) : self.plie=False
262 from InterfaceQT4 import compobloc
263 from InterfaceQT4 import compomclist
265 ajoutAuParentduNoeud=0
266 self.treeParent=treeParent
267 while (isinstance(self.treeParent,compobloc.Node) or ( isinstance(self.treeParent,compomclist.Node) and self.treeParent.item.isMCList())) :
268 self.treeParent.childrenComplete.append(self)
269 self.treeParent=self.treeParent.vraiParent
270 self.treeParent.childrenComplete.append(self)
273 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)) :
274 # Le dernier or ne sert que lorsqu'on est en train de creer une liste par les validator
275 QTreeWidgetItem.__init__(self,None,mesColonnes)
277 QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
279 self.setToolTip(0,self.item.getFr())
280 self.setToolTip(1,self.item.getFr())
281 repIcon=self.appliEficas.repIcon
283 couleur=self.item.getIconName()
284 monIcone = QIcon(repIcon+"/" + couleur + ".png")
286 self.setIcon(0,monIcone)
293 self.item.connect("valid",self.onValid,())
294 self.item.connect("supp" ,self.onSupp,())
295 self.item.connect("add" ,self.onAdd,())
300 if self.item.getObject().isBLOC() :
301 self.setExpanded(True)
307 def buildChildren(self,posInsertion=10000):
308 """ Construit la liste des enfants de self """
309 """ Se charge de remettre les noeuds Expanded dans le meme etat """
310 #print ("*********** buildChildren ",self,self.item, self.item.nom)
313 self.listeItemExpanded=[]
314 self.listeItemPlie=[]
316 for enfant in self.childrenComplete :
317 if enfant.plie : self.listeItemPlie.append(enfant.item)
318 else : self.listeItemExpanded.append(enfant.item)
320 for enfant in self.childrenComplete :
321 parent=enfant.treeParent
322 parent.removeChild(enfant)
327 self.childrenComplete = []
328 sublist = self.item._getSubList()
331 for item in sublist :
334 if item in self.listeItemExpanded : itemExpand=True; ancien=True
335 if item in self.listeItemPlie : itemExpand=False; ancien=True
336 nouvelItem=item.itemNode(self,item,itemExpand,ancien)
337 self.children.append(nouvelItem)
339 #print ("fin *********** buildChildren ",self,self.item, self.item.nom, self.children)
342 def chercheNoeudCorrespondant(self,objSimp):
343 sublist = self.item._getSubList()
344 for node in self.childrenComplete:
345 if node.item.object==objSimp : return node
349 def afficheCeNiveau(self):
350 #print ('afficheCeNiveau pour ', self.item.nom, self.item.getLabelText())
351 for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
352 widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
353 self.editor.widgetCentraleLayout.removeItem(widget)
354 if self.editor.fenetreCentraleAffichee != None :
355 self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
356 self.editor.fenetreCentraleAffichee.setParent(None)
357 self.editor.fenetreCentraleAffichee.close()
358 self.editor.fenetreCentraleAffichee.deleteLater()
360 from monWidgetNiveauFact import MonWidgetNiveauFact, MonWidgetNiveauFactTableau
361 maDefinition=self.item.get_definition()
362 monObjet=self.item.object
363 if maDefinition.fenetreIhm=='Tableau' : self.maFenetreCadre=MonWidgetNiveauFactTableau(self,self.editor,maDefinition,monObjet)
364 else : self.maFenetreCadre=MonWidgetNiveauFact(self,self.editor,maDefinition,monObjet)
366 self.fenetre=self.maFenetreCadre
367 self.editor.widgetCentraleLayout.addWidget(self.maFenetreCadre)
368 self.editor.fenetreCentraleAffichee=self.maFenetreCadre
370 #print ('fin afficheCeNiveau pour ', self.item.nom)
373 def getPanelModifie(self):
375 if self.fenetreIhm == None : return None
376 if self.fenetreIhm=='deplie1Niveau':
377 from InterfaceQT4.monWidgetCommandeDeplie1Niveau import MonWidgetCommandeDeplie1Niveau
378 return MonWidgetCommandeDeplie1Niveau (self,self.editor ,self.item.object)
382 def affichePanneau(self) :
383 #if self.editor.code == 'ASTER' and not(self.item.isActif()) :
384 # posera des pb si un code decide d appeler FIN un mot clef
385 # on resoudera a ce moment la
386 # pour l pas de poussiere sous le tapis
387 #print ('_________________ds affichePanneau pour', self.item.nom)
388 if not(self.item.isActif()) :
389 from .monWidgetInactif import MonWidgetInactif
390 self.fenetre = MonWidgetInactif(self,self.editor)
393 while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent
394 if itemParent!=self :
395 #print ('j appelle affichePanneau pour ', itemParent.item.nom , 'par', self.item.nom)
396 itemParent.affichePanneau()
397 #print ('fin _________________ds affichePanneau pour', self.item.nom)
399 self.fenetre=self.getPanelModifie()
400 if self.fenetre == None : self.fenetre=self.getPanel()
401 self.editor.restoreSplitterSizes()
403 for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
404 widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
405 self.editor.widgetCentraleLayout.removeItem(widget)
406 # ceinture et bretelle
407 #print 'old fenetre = ',self.editor.fenetreCentraleAffichee
408 if self.editor.fenetreCentraleAffichee != None :
409 self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
410 self.editor.fenetreCentraleAffichee.setParent(None)
411 self.editor.fenetreCentraleAffichee.close()
412 self.editor.fenetreCentraleAffichee.deleteLater()
414 self.editor.widgetCentraleLayout.addWidget(self.fenetre)
415 #print ("j ajoute ", self.fenetre, self.fenetre.node.item.nom)
416 self.editor.fenetreCentraleAffichee=self.fenetre
417 self.tree.node_selected= self
419 if self.editor.first :
420 if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
421 self.tree.inhibeExpand=True
422 self.tree.expandItem(self)
423 self.tree.inhibeExpand=False
424 #print( '_________________fin affichePanneau pour', self.item.nom)
427 def createPopUpMenu(self):
428 #implemente dans les noeuds derives si necessaire
433 Cette methode a pour but de commentariser la commande pointee par self
435 # On traite par une exception le cas ou l'utilisateur final cherche a desactiver
436 # (commentariser) un commentaire.
438 pos=self.treeParent.children.index(self)
439 commande_comment = self.item.getObjetCommentarise()
440 # On signale a l editeur du panel (le JDCDisplay) une modification
441 self.editor.initModif()
442 self.treeParent.buildChildren()
443 self.treeParent.children[pos].select()
444 self.treeParent.children[pos].affichePanneau()
445 except Exception as e:
446 traceback.print_exc()
447 QMessageBox.critical( self.editor, "TOO BAD",str(e))
449 def unCommentIt(self):
451 Realise la decommentarisation de self
454 pos=self.treeParent.children.index(self)
455 commande,nom = self.item.unComment()
456 self.editor.initModif()
457 self.treeParent.buildChildren()
458 self.treeParent.children[pos].select()
459 self.treeParent.children[pos].affichePanneau()
460 except Exception as e:
461 QMessageBox.critical( self.editor, "Erreur !",str(e))
463 def addComment( self, after=True ):
465 Ajoute un commentaire a l'interieur du JDC :
467 self.editor.initModif()
472 return self.appendBrother( COMMENT, pos )
474 def addParameters( self, after=True ):
476 Ajoute un parametre a l'interieur du JDC :
478 self.editor.initModif()
479 if after: pos = 'after'
481 child=self.appendBrother( PARAMETERS, pos )
487 Rend le noeud courant (self) selectionne et deselectionne
490 #print "select pour", self.item.nom
491 for item in self.tree.selectedItems() :
493 self.tree.setCurrentItem( self )
495 #------------------------------------------------------------------
496 # Methodes de creation et destruction de noeuds
497 # Certaines de ces methodes peuvent etre appelees depuis l'externe
498 #------------------------------------------------------------------
499 def appendBrother(self,name,pos='after',plier=False):
501 Permet d'ajouter un objet frere a l'objet associe au noeud self
502 par defaut on l'ajoute immediatement apres
505 self.editor.initModif()
507 from InterfaceQT4 import compojdc
508 if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos) : return 0
510 if self.treeParent != self.vraiParent :
511 index = self.vraiParent.children.index(self)
512 if pos == 'before': index = index
513 elif pos == 'after': index = index +1
514 return self.vraiParent.appendChild(name,pos=index,plier=plier)
516 index = self.treeParent.children.index(self)
517 if pos == 'before': index = index
518 elif pos == 'after': index = index +1
520 print(six.text_type(pos), tr(" n'est pas un index valide pour appendBrother"))
522 return self.treeParent.appendChild(name,pos=index,plier=plier)
524 def verifiePosition(self,name,pos,aLaRacine=False):
525 if name not in self.editor.readercata.Classement_Commandes_Ds_Arbre : return True
526 indexName=self.editor.readercata.Classement_Commandes_Ds_Arbre.index(name)
528 etapes=self.item.getJdc().etapes
529 if etapes == [] : return True
531 if aLaRacine == False :indexOu=etapes.index(self.item.object)
534 if pos=="after" : indexOu = indexOu+1
535 for e in etapes[:indexOu] :
537 if nom not in self.editor.readercata.Classement_Commandes_Ds_Arbre : continue
538 indexEtape=self.editor.readercata.Classement_Commandes_Ds_Arbre.index(nom)
539 if indexEtape > indexName :
540 comment=tr('le mot clef ')+name+tr(' doit etre insere avant ')+nom
541 QMessageBox.information( None,tr('insertion impossible'),comment, )
543 for e in etapes[indexOu:] :
545 if nom not in self.editor.readercata.Classement_Commandes_Ds_Arbre : continue
546 indexEtape=self.editor.readercata.Classement_Commandes_Ds_Arbre.index(nom)
547 if indexEtape < indexName :
548 comment=tr('le mot clef ')+name+tr(' doit etre insere apres ')+nom
549 QMessageBox.information( None,tr('insertion impossible'),comment, )
553 def appendChild(self,name,pos=None,plier=False):
555 Methode pour ajouter un objet fils a l'objet associe au noeud self.
556 On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
557 ou en position intermediaire.
558 Si pos vaut None, on le place a la position du catalogue.
560 #print ("************** appendChild ",self.item.getLabelText(), pos, plier)
562 #traceback.print_stack()
565 self.editor.initModif()
569 index = len(self.children)
570 elif type(pos) == int :
573 elif type(pos) == object:
574 #elif type(pos) == types.InstanceType:
575 # pos est un item. Il faut inserer name apres pos
576 index = self.item.getIndex(pos) +1
577 #elif type(name) == types.InstanceType:
578 elif type(name) == object:
579 index = self.item.getIndexChild(name.nom)
581 index = self.item.getIndexChild(name)
583 # si on essaye d inserer a la racine
584 if (isinstance(self.treeParent,JDCTree) and index==0) :
585 verifiePosition=self.verifiePosition(name,'first',aLaRacine=True)
586 if not verifiePosition : return 0
588 self.tree.inhibeExpand=True
589 obj=self.item.addItem(name,index) # emet le signal 'add'
594 child=self.children[index]
595 if plier == True : child.setPlie()
596 else : child.setDeplie()
598 child=self.children[index]
600 if len(obj) > 1 : self.buildChildren()
602 self.tree.inhibeExpand=False
603 #print (" fin append child")
607 self.editor.initModif()
608 index = self.treeParent.children.index(self) - 1
609 if index < 0 : index =0
610 ret=self.treeParent.item.deplaceEntite(self.item.getObject())
614 Methode externe pour la destruction de l'objet associe au noeud
616 self.editor.initModif()
617 index = self.vraiParent.children.index(self) - 1
618 if index < 0 : index =0
620 if self.item.nom == "VARIABLE" :
623 ret,commentaire=self.vraiParent.item.suppItem(self.item)
625 self.editor.afficheInfos(commentaire,Qt.red)
627 self.editor.afficheInfos(commentaire)
628 self.treeParent.buildChildren()
629 if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
630 else: toselect=self.treeParent
631 if recalcule : jdc.recalculeEtatCorrelation()
633 if self.treeParent.childrenComplete :
634 notdeleted=self.treeParent.childrenComplete[index+1]
638 from InterfaceQT4 import compojdc
639 # cas ou on detruit dans l arbre sans affichage
640 if isinstance(self.treeParent,compojdc.Node) :
641 toselect.affichePanneau()
643 if self.treeParent.fenetre== None : return
644 #print "J appelle reaffiche de browser apres delete"
645 self.treeParent.fenetre.reaffiche(toselect)
647 def deleteMultiple(self,liste=()):
649 Methode externe pour la destruction d une liste de noeud
651 from InterfaceQT4 import compojdc
652 self.editor.initModif()
657 while not(isinstance(jdc,compojdc.Node)):
660 if not( isinstance(noeud.treeParent, compojdc.Node)): continue
661 if noeud.item.nom == "VARIABLE" : recalcule=1
662 if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
663 if index < 0 : index =0
665 # Cas ou on detruit dans une ETape
667 parentPosition=self.treeParent
668 while not(isinstance(parentPosition, compojdc.Node)):
669 index=parentPosition.treeParent.children.index(parentPosition)
670 parentPosition=parentPosition.treeParent
673 noeud.treeParent.item.suppItem(noeud.item)
676 if recalcule : jdc.recalculeEtatCorrelation()
677 try : toselect=parentPosition.children[index]
678 except : toselect=jdc
680 toselect.affichePanneau()
682 # #------------------------------------------------------------------
685 #print ("onValid pour ", self.item.nom)
686 if self.JESUISOFF==1 : return
687 if hasattr(self,'fenetre') and self.fenetre:
689 self.fenetre.setValide()
691 # print "onValid pour ", self.item.nom, self,'pb'
694 if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isValid():
695 self.item.jdc.recalculeEtatCorrelation()
696 if hasattr(self.item,'forceRecalcul'):
697 self.forceRecalculChildren(self.item.forceRecalcul)
698 self.editor.initModif()
700 self.updateNodeValid()
701 self.updateNodeLabel()
702 self.updateNodeTexte()
704 def onAdd(self,object):
705 if self.JESUISOFF==1 : return
706 #print ("onAdd pour ", self.item.nom, object)
707 self.editor.initModif()
709 # PN -- non necessaire si item=jdc
710 if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
712 def onSupp(self,object):
713 if self.JESUISOFF==1 : return
714 #print "onSup pour ", self.item.nom, object
715 self.editor.initModif()
717 # PN -- non necessaire si item=jdc
718 if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
722 def updateNodeValid(self):
723 """Cette methode remet a jour la validite du noeud (icone)
726 repIcon=self.appliEficas.repIcon
727 couleur=self.item.getIconName()
728 monIcone = QIcon(repIcon+"/" + couleur + ".png")
729 self.setIcon(0,monIcone)
733 def updateNodeLabel(self):
734 """ Met a jour le label du noeud """
735 #print "NODE updateNodeLabel", self.item.getLabelText()
736 labeltext,fonte,couleur = self.item.getLabelText()
738 if item.nom != tr(item.nom) : labeltext = str(tr(item.nom)+" :")
739 self.setText(0, tr(labeltext))
741 def updateNodeLabelInBlack(self):
742 if hasattr(self.appliEficas,'noeudColore'):
743 self.appliEficas.noeudColore.setForeground(0,Qt.black)
744 self.appliEficas.noeudColore.updateNodeLabel
746 def updateNodeLabelInBlue(self):
747 if hasattr(self.appliEficas,'noeudColore'): self.appliEficas.noeudColore.setForeground(0,Qt.black)
748 self.setForeground(0,Qt.blue)
749 labeltext,fonte,couleur = self.item.getLabelText()
750 if item.nom != tr(item.nom) : labeltext = str(tr(item.nom)+" :")
751 self.setText(0, labeltext)
752 self.appliEficas.noeudColore=self
754 def updatePlusieursNodeLabelInBlue(self,liste):
755 if hasattr(self.appliEficas,'listeNoeudsColores'):
756 for noeud in self.appliEficas.listeNoeudsColores:
757 noeud.setTextColor( 0,Qt.black)
758 noeud.updateNodeLabel()
759 self.appliEficas.listeNoeudsColores=[]
761 noeud.setTextColor( 0,Qt.blue )
762 labeltext,fonte,couleur = noeud.item.getLabelText()
763 noeud.setText(0, labeltext)
764 self.appliEficas.listeNoeudsColores.append(noeud)
766 def updateNodeTexteInBlack(self):
767 """ Met a jour les noms des SD et valeurs des mots-cles """
768 self.setTextColor( 1,Qt.black )
769 value = self.item.getText()
770 self.setText(1, value)
772 def updateNodeTexte(self):
773 """ Met a jour les noms des SD et valeurs des mots-cles """
774 value = self.item.getText()
775 self.setText(1, value)
778 def updateNodeTexteInBlue(self):
779 self.setTextColor( 1,Qt.blue )
780 value = self.item.getText()
781 self.setText(1, value)
783 def updateNodes(self):
784 #print 'NODE updateNodes', self.item.getLabelText()
787 def updateValid(self) :
788 """Cette methode a pour but de mettre a jour la validite du noeud
789 et de propager la demande de mise a jour a son parent
791 #print "NODE updateValid", self.item.getLabelText()
792 self.updateNodeValid()
794 self.treeParent.updateValid()
798 def updateTexte(self):
799 """ Met a jour les noms des SD et valeurs des mots-cles """
800 #print "NODE updateTexte", self.item.getLabelText()
801 self.updateNodeVexte()
802 if self.isExpanded() :
803 for child in self.children:
804 if child.isHidden() == false : child.updateTexte()
807 def forceRecalculChildren(self,niveau):
808 if self.state=='recalcule' :
811 self.state='recalcule'
812 if hasattr(self.item,'object'):
813 self.item.object.state="modified"
814 for child in self.children:
815 if niveau > 0 : child.forceRecalculChildren(niveau - 1)
819 def doPaste(self,node_selected,pos='after'):
821 Declenche la copie de l'objet item avec pour cible
822 l'objet passe en argument : node_selected
824 objet_a_copier = self.item.getCopieObjet()
825 child=node_selected.doPasteCommande(objet_a_copier,pos)
826 if self.editor.fenetreCentraleAffichee : self.editor.fenetreCentraleAffichee.node.affichePanneau()
827 self.updateNodeLabelInBlack()
830 def doPasteCommande(self,objet_a_copier,pos='after'):
832 Realise la copie de l'objet passe en argument qui est necessairement
838 child = self.appendBrother(objet_a_copier,pos)
843 def doPastePremier(self,objet_a_copier):
845 Realise la copie de l'objet passe en argument (objet_a_copier)
847 objet = objet_a_copier.item.getCopieObjet()
848 child = self.appendChild(objet,pos='first')
851 def plieToutEtReafficheSaufItem(self, itemADeplier):
852 self.inhibeExpand=True
853 from InterfaceQT4 import compojdc
854 if (isinstance(self, compojdc.Node)) :
855 self.affichePanneau()
856 self.inhibeExpand=False
858 self.editor.deplier = False
859 for item in self.children :
860 # il ne faut pas plier les blocs
861 from InterfaceQT4 import compobloc
862 if (isinstance(item,compobloc.Node)) : continue
864 if item==itemADeplier :
865 itemADeplier.setDeplie()
866 self.affichePanneau()
867 self.inhibeExpand=False
869 def plieToutEtReaffiche(self):
870 #print ('plieToutEtReaffiche', self.item.getNom())
871 from InterfaceQT4 import compojdc
872 if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return
873 self.inhibeExpand=True
874 self.editor.deplier = False
875 for item in self.children :
876 # il ne faut pas plier les blocs
877 from InterfaceQT4 import compobloc
878 if (isinstance(item,compobloc.Node)) : continue
880 self.affichePanneau()
881 #print ("fin plieToutEtReaffiche", self.item.getNom())
883 def deplieToutEtReaffiche(self):
884 self.editor.deplier = True
885 for item in self.children :
887 self.affichePanneau()
890 #print "je mets inhibeExpand a true dans setPlie"
891 #print ("je suis dans plieTout", self.item.getNom())
892 from . import compojdc
893 if self.fenetre == self.editor.fenetreCentraleAffichee and isinstance(self.treeParent,compojdc.Node):
895 self.tree.inhibeExpand=True
896 self.tree.collapseItem(self)
897 self.setPlieChildren()
898 self.tree.inhibeExpand=False
899 #print "je mets inhibeExpand a false dans setPlie"
902 # on ne plie pas au niveau 1
904 # for item in self.children :
905 # item.appartientAUnNoeudPlie=False
907 def setPlieChildren(self):
909 from InterfaceQT4 import composimp
910 if isinstance(self,composimp.Node) : return
911 for c in self.children :
913 #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.getLabelText()[0]
914 c.appartientAUnNoeudPlie=True
916 #print "dans setPlieChildren plie", c.item.nom
917 # 01/2018 PNPN : boucle sur MT __ La ligne suivante ne me semble pas necessaire
918 #if not (isinstance(c,composimp.Node)) :c.setExpanded(False)
920 # Pour les blocs et les motcles list
921 # on affiche un niveau de plus
922 from InterfaceQT4 import compobloc
923 from InterfaceQT4 import compomclist
924 if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) :
925 niveauPere=self.treeParent
926 while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) :
927 niveauPere=niveauPere.treeParent
928 for c in self.children :
929 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
930 #print ("dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.getLabelText()[0], "mis a la valeur ", niveauPere.appartientAUnNoeudPlie)
935 self.tree.inhibeExpand=True
937 self.tree.expandItem(self)
938 self.setDeplieChildren()
939 self.tree.inhibeExpand=False
940 #print "je mets inhibeExpand a false dans setDePlie"
942 def setDeplieChildren(self):
943 #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.getLabelText()
944 for c in self.children :
945 c.setDeplieChildren()
946 #print "dans setDeplieChildren ", c.item.nom
947 c.appartientAUnNoeudPlie=False
951 def selectAvant(self):
952 i=self.item.jdc.etapes.index(self.item.object)
954 cherche=self.item.jdc.etapes[i-1]
956 cherche=self.item.jdc.etapes[-1]
958 for i in self.tree.racine.children :
959 if i.item.object== cherche :
963 node.affichePanneau()
966 def selectApres(self):
967 i=self.item.jdc.etapes.index(self.item.object)
969 cherche=self.item.jdc.etapes[i+1]
971 cherche=self.item.jdc.etapes[0]
973 for i in self.tree.racine.children :
974 if i.item.object== cherche :
978 node.affichePanneau()
981 def ouvreLesNoeudsDsLArbre(self):
983 self.inhibeExpand = True
984 for i in range(self.childCount()):
985 self.child(i).inhibeExpand=True
986 self.child(i).setExpanded(True)
987 self.child(i).ouvreLesNoeudsDsLArbre()
988 self.child(i).inhibeExpand=False
989 self.inhibeExpand = False