1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021 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 PyQt5.QtWidgets import QTreeWidget , QTreeWidgetItem, QApplication, QMessageBox
35 from PyQt5.QtGui import QIcon
36 from PyQt5.QtCore import Qt
38 from Extensions.i18n import tr
39 from .gereRegles import GereRegles
40 from .monChoixCommande import MonChoixCommande
42 #------------------------------------------
43 class JDCTree( QTreeWidget,GereRegles ):
44 #------------------------------------------
46 def __init__( self, jdc_item, QWParent):
47 #----------------------------------------
48 self.editor = QWParent
50 if self.editor.widgetTree !=None :
51 QTreeWidget.__init__(self, self.editor.widgetTree )
52 self.editor.verticalLayout_2.addWidget(self)
53 if self.editor.enteteQTree=='complet':
54 self.headerItem().setText(0, "Commande ")
55 self.headerItem().setText(1, "Concept/Valeur")
57 self.headerItem().setText(0, "Commande ")
58 self.setColumnWidth(0,200)
59 self.setExpandsOnDoubleClick(False)
60 self.setSelectionMode(3)
62 QTreeWidget.__init__(self, None )
65 self.appliEficas = self.editor.appliEficas
66 self.childrenComplete=[]
67 self.racine=self.item.itemNode(self,self.item)
71 self.itemClicked.connect(self.handleOnItem)
72 self.itemCollapsed.connect(self.handleCollapsedItem)
73 self.itemExpanded.connect(self.handleExpandedItem)
75 self.node_selected = self.racine
76 self.inhibeExpand = True
77 self.expandItem(self.racine)
78 self.inhibeExpand = False
79 if self.racine.children !=[] :
80 if self.editor.maConfiguration.afficheCommandesPliees : self.racine.children[0].plieToutEtReaffiche()
81 else : self.racine.children[0].deplieToutEtReaffiche()
82 self.racine.children[0].fenetre.donnePremier()
84 self.racine.affichePanneau()
86 def contextMenuEvent(self,event) :
87 #---------------------------------
88 coord = event.globalPos()
89 item = self.currentItem()
90 self.handleContextMenu(item,coord)
92 def handleContextMenu(self,item,coord):
93 #-------------------------------------
95 Private slot to show the context menu of the listview.
97 @param itm the selected listview item (QListWidgetItem)
98 @param coord the position of the mouse pointer (QPoint)
99 Attention : existeMenu permet de savoir si un menu est associe a cet item
101 print ("handleContextMenu")
102 if item == None : return
103 self.itemCourant = item
104 if item.existeMenu == 0 : return
106 if item.menu == None:
107 item.createPopUpMenu()
108 if item.menu != None:
109 # PNPN reflechir a qqchose de generique pour remplacer cette fonctionnalite
110 # if item.item.getNom() == "DISTRIBUTION" and item.item.isValid() :
111 # item.Graphe.setEnabled(1)
112 item.menu.exec_(coord)
115 def handleCollapsedItem(self,item):
116 #----------------------------------
117 #print ("dans CollapsedItem", self.inhibeExpand )
118 if self.inhibeExpand == True : return
120 # On traite le cas de l item non selectionne
121 self.itemCourant = item
123 while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent
124 if self.tree.node_selected != itemParent :
125 item.setExpanded(False)
129 item.plieToutEtReaffiche()
132 def handleExpandedItem(self,item):
133 #----------------------------------
134 #print ("handleExpandedItem pour ", item.item.nom, self.inhibeExpand)
136 #traceback.print_stack()
137 if self.inhibeExpand == True : return
139 self.itemCourant = item
140 self.inhibeExpand = True
142 while not (hasattr (itemParent,'getPanel')) :
143 if itemParent.plie==True : itemParent.setDeplie()
144 itemParent=itemParent.treeParent
145 if self.tree.node_selected != itemParent :
146 item.setExpanded(True)
147 self.inhibeExpand = False
149 item.deplieToutEtReaffiche()
150 self.inhibeExpand = False
153 def handleOnItem(self,item,int):
154 #----------------------------------
155 #print ("je passe dans handleOnItem pour ",self, item.item.nom, item, item.item, item.item.getLabelText())
157 from InterfaceQT4 import composimp
158 self.inhibeExpand = True
159 self.itemCourant = item
163 # PN : 22 juil 2021 --> bizarre ce itemAvant Verifier le while
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 # Attention - Specification particuliere pour MT qui permet de nn afficher qu 1 niveau
173 # le catalogue contient cette indication dans fenetreIhm
174 if estUneFeuille and itemParent.fenetreIhm=='deplie1Niveau' :
175 if item == itemParent : itemParent.affichePanneau()
176 else : itemAvant.afficheCeNiveau()
177 elif estUneFeuille : itemParent.affichePanneau()
178 elif self.editor.maConfiguration.afficheCommandesPliees : itemParent.plieToutEtReafficheSaufItem(item)
179 else : itemParent.affichePanneau()
182 elif (isinstance(item,composimp.Node)) and item.fenetre : item.fenetre.rendVisible()
183 elif itemParent!=item: self.tree.handleExpandedItem(item)
187 fr = item.item.getFr()
188 chaineDecoupee= fr.split('\n')
189 if len(chaineDecoupee) > 3 :
190 txt='\n'.join(chaineDecoupee[0:2])+'...\nfull help : double clicked on validity chip of '+ str(item.item.nom)+ ' in central widget'
192 if self.editor: self.editor.afficheCommentaire(str(txt))
197 self.inhibeExpand = False
200 def choisitPremier(self,name):
201 #----------------------------
202 self.editor.layoutJDCCHOIX.removeWidget(self.racine.fenetre)
203 self.racine.fenetre.close()
204 new_node=self.racine.appendBrother(name,'after')
207 COMMENT = "COMMENTAIRE"
208 PARAMETERS = "PARAMETRE"
210 #------------------------------------------
211 class JDCNode(QTreeWidgetItem,GereRegles):
212 #------------------------------------------
213 def __init__( self, treeParent, item, itemExpand=False, ancien=False ):
214 #----------------------------------------------------------------------
215 #print ("creation d'un noeud : ", item, " ",item.nom,"", treeParent, self)
220 self.vraiParent = treeParent
221 self.treeParent = treeParent
222 self.tree = self.treeParent.tree
223 self.editor = self.treeParent.editor
224 self.appliEficas = treeParent.appliEficas
226 self.firstAffiche = True
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(item.getLabelText()[0])
236 if item.nom != tr(item.nom) : name = str(tr(item.nom)+" :")
237 value = tr(str(item.getText() ) )
239 # si specialisation de la fenetre
240 if self.item.object.definition == None : self.fenetreIhm = None
241 # Cas des listes de mots_clefs
242 else : self.fenetreIhm = self.item.object.definition.fenetreIhm
244 if self.editor.enteteQTree=='complet':mesColonnes=(name,value)
245 else : mesColonnes=(name,)
247 if self.treeParent.plie==True :
249 self.appartientAUnNoeudPlie = True
250 if self.treeParent.item.isMCList() : self.appartientAUnNoeudPlie = self.treeParent.appartientAUnNoeudPlie
253 self.appartientAUnNoeudPlie = False
255 #if item.nom == "POUTRE" :print "creation d'un noeud : ", item, " ",item.nom,"", self.treeParent, self.appartientAUnNoeudPlie , self.plie
257 if ancien and itemExpand : self.plie = False
258 if ancien and not itemExpand : self.plie = True
259 if (isinstance(self.item,composimp.SIMPTreeItem)) : self.plie=False
261 from InterfaceQT4 import compobloc
262 from InterfaceQT4 import compomclist
264 ajoutAuParentduNoeud=0
265 self.treeParent=treeParent
266 while (isinstance(self.treeParent,compobloc.Node) or ( isinstance(self.treeParent,compomclist.Node) and self.treeParent.item.isMCList())) :
267 self.treeParent.childrenComplete.append(self)
268 self.treeParent=self.treeParent.vraiParent
269 self.treeParent.childrenComplete.append(self)
272 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)) :
273 # Le dernier or ne sert que lorsqu'on est en train de creer une liste par les validator
274 QTreeWidgetItem.__init__(self,None,mesColonnes)
276 QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
278 self.setToolTip(0,self.item.getFr())
279 self.setToolTip(1,self.item.getFr())
280 repIcon=self.appliEficas.repIcon
282 couleur=self.item.getIconName()
283 monIcone = QIcon(repIcon+"/" + couleur + ".png")
285 self.setIcon(0,monIcone)
292 self.item.connect("valid",self.onValid,())
293 self.item.connect("supp" ,self.onSupp,())
294 self.item.connect("add" ,self.onAdd,())
295 self.item.connect("redessine" ,self.onRedessine,())
300 if self.item.getObject().isBLOC() :
301 self.setExpanded(True)
307 def buildChildren(self,posInsertion=10000):
308 #------------------------------------------
309 """ Construit la liste des enfants de self """
310 """ Se charge de remettre les noeuds Expanded dans le meme etat """
311 #print ("*********** buildChildren ",self,self.item, self.item.nom)
314 self.listeItemExpanded=[]
315 self.listeItemPlie=[]
317 for enfant in self.childrenComplete :
318 if enfant.plie : self.listeItemPlie.append(enfant.item)
319 else : self.listeItemExpanded.append(enfant.item)
321 for enfant in self.childrenComplete :
322 parent = enfant.treeParent
323 parent.removeChild(enfant)
328 self.childrenComplete = []
329 sublist = self.item._getSubList()
332 for item in sublist :
335 if item in self.listeItemExpanded : itemExpand=True; ancien=True
336 if item in self.listeItemPlie : itemExpand=False; ancien=True
337 nouvelItem=item.itemNode(self,item,itemExpand,ancien)
338 self.children.append(nouvelItem)
340 #print ("fin *********** buildChildren ",self,self.item, self.item.nom, self.children)
343 def chercheNoeudCorrespondant(self,objSimp):
344 #-------------------------------------------
345 sublist = self.item._getSubList()
346 for node in self.childrenComplete:
347 if node.item.object==objSimp : return node
351 def afficheCeNiveau(self):
352 #-------------------------
353 #print ('afficheCeNiveau pour ', self.item.nom, self.item.getLabelText())
354 for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
355 widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
356 self.editor.widgetCentraleLayout.removeItem(widget)
357 if self.editor.fenetreCentraleAffichee != None :
358 self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
359 self.editor.fenetreCentraleAffichee.setParent(None)
360 self.editor.fenetreCentraleAffichee.close()
361 self.editor.fenetreCentraleAffichee.deleteLater()
363 from monWidgetNiveauFact import MonWidgetNiveauFact, MonWidgetNiveauFactTableau
364 maDefinition = self.item.get_definition()
365 monObjet = self.item.object
366 if maDefinition.fenetreIhm=='Tableau' : self.maFenetreCadre=MonWidgetNiveauFactTableau(self,self.editor,maDefinition,monObjet)
367 else : self.maFenetreCadre=MonWidgetNiveauFact(self,self.editor,maDefinition,monObjet)
369 self.fenetre = self.maFenetreCadre
370 self.editor.widgetCentraleLayout.addWidget(self.maFenetreCadre)
371 self.editor.fenetreCentraleAffichee=self.maFenetreCadre
373 #print ('fin afficheCeNiveau pour ', self.item.nom)
376 def getPanelModifie(self):
377 #-------------------------
379 if self.fenetreIhm == None : return None
380 if self.fenetreIhm =='deplie1Niveau':
381 from InterfaceQT4.monWidgetCommandeDeplie1Niveau import MonWidgetCommandeDeplie1Niveau
382 return MonWidgetCommandeDeplie1Niveau (self,self.editor ,self.item.object)
386 def affichePanneau(self) :
387 #-------------------------
388 #print ('_________________ds affichePanneau pour', self.item.nom)
389 # pour l instant pas d inactif
390 if not(self.item.isActif()) :
391 from .monWidgetInactif import MonWidgetInactif
392 self.fenetre = MonWidgetInactif(self,self.editor)
395 while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent
396 if itemParent != self :
397 #print ('j appelle affichePanneau pour ', itemParent.item.nom , 'par', self.item.nom)
398 itemParent.affichePanneau()
399 #print ('fin _________________ds affichePanneau pour', self.item.nom)
402 self.fenetre = self.getPanelModifie()
403 if self.fenetre == None : self.fenetre=self.getPanel()
404 self.editor.restoreSplitterSizes()
406 for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
407 widget = self.editor.widgetCentraleLayout.itemAt(indiceWidget)
408 self.editor.widgetCentraleLayout.removeItem(widget)
410 # ceinture et bretelle
411 #print 'old fenetre = ',self.editor.fenetreCentraleAffichee
412 if self.editor.fenetreCentraleAffichee != None :
414 self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
415 self.editor.fenetreCentraleAffichee.setParent(None)
416 self.editor.fenetreCentraleAffichee.close()
417 self.editor.fenetreCentraleAffichee.deleteLater()
421 self.editor.widgetCentraleLayout.addWidget(self.fenetre)
422 #print ("j ajoute ", self.fenetre, self.fenetre.node.item.nom)
423 self.editor.fenetreCentraleAffichee=self.fenetre
424 self.tree.node_selected= self
426 if self.editor.first :
427 if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
428 self.tree.inhibeExpand=True
429 self.tree.expandItem(self)
430 self.tree.inhibeExpand=False
431 #print( '_________________fin affichePanneau pour', self.item.nom)
434 def createPopUpMenu(self):
435 #-------------------------
436 #implemente dans les noeuds derives si necessaire
440 #-------------------------
442 Cette methode a pour but de commentariser la commande pointee par self
444 # On traite par une exception le cas ou l'utilisateur final cherche a desactiver
445 # (commentariser) un commentaire.
447 pos=self.treeParent.children.index(self)
448 commande_comment = self.item.getObjetCommentarise()
449 # On signale a l editeur du panel (le JDCDisplay) une modification
450 self.editor.initModif()
451 self.treeParent.buildChildren()
452 self.treeParent.children[pos].select()
453 self.treeParent.children[pos].affichePanneau()
454 except Exception as e:
455 traceback.print_exc()
456 QMessageBox.critical( self.editor, "TOO BAD",str(e))
458 def unCommentIt(self):
459 #-------------------------
461 Realise la decommentarisation de self
464 pos=self.treeParent.children.index(self)
465 commande,nom = self.item.unComment()
466 self.editor.initModif()
467 self.treeParent.buildChildren()
468 self.treeParent.children[pos].select()
469 self.treeParent.children[pos].affichePanneau()
470 except Exception as e:
471 QMessageBox.critical( self.editor, "Erreur !",str(e))
473 def addComment( self, after=True ):
474 #-----------------------------------
476 Ajoute un commentaire a l'interieur du JDC :
478 self.editor.initModif()
483 return self.appendBrother( COMMENT, pos )
485 def addParameters( self, after=True ):
486 #-------------------------------------
488 Ajoute un parametre a l'interieur du JDC :
490 self.editor.initModif()
491 if after: pos = 'after'
493 child=self.appendBrother( PARAMETERS, pos )
500 Rend le noeud courant (self) selectionne et deselectionne
503 #print "select pour", self.item.nom
504 for item in self.tree.selectedItems() :
506 self.tree.setCurrentItem( self )
508 #------------------------------------------------------------------
509 # Methodes de creation et destruction de noeuds
510 #------------------------------------------------------------------
512 def appendBrother(self,name,pos='after',plier=False):
513 #----------------------------------------------------
515 Permet d'ajouter un objet frere a l'objet associe au noeud self
516 par defaut on l'ajoute immediatement apres
519 self.editor.initModif()
521 from InterfaceQT4 import compojdc
522 if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos) : return 0
524 if self.treeParent != self.vraiParent :
525 index = self.vraiParent.children.index(self)
526 if pos == 'before' : index = index
527 elif pos == 'after' : index = index +1
528 return self.vraiParent.appendChild(name,pos=index,plier=plier)
530 index = self.treeParent.children.index(self)
531 if pos == 'before': index = index
532 elif pos == 'after' : index = index +1
534 print(pos, tr(" n'est pas un index valide pour appendBrother"))
536 return self.treeParent.appendChild(name,pos=index,plier=plier)
538 def verifiePosition(self,name,pos,aLaRacine=False):
539 #----------------------------------------------------
540 if name not in self.editor.readercata.Classement_Commandes_Ds_Arbre : return True
541 indexName=self.editor.readercata.Classement_Commandes_Ds_Arbre.index(name)
543 etapes=self.item.getJdc().etapes
544 if etapes == [] : return True
546 if aLaRacine == False :indexOu=etapes.index(self.item.object)
549 if pos=="after" : indexOu = indexOu+1
550 for e in etapes[:indexOu] :
552 if nom not in self.editor.readercata.Classement_Commandes_Ds_Arbre : continue
553 indexEtape=self.editor.readercata.Classement_Commandes_Ds_Arbre.index(nom)
554 if indexEtape > indexName :
555 comment=tr('le mot clef ')+name+tr(' doit etre insere avant ')+nom
556 QMessageBox.information( None,tr('insertion impossible'),comment, )
558 for e in etapes[indexOu:] :
560 if nom not in self.editor.readercata.Classement_Commandes_Ds_Arbre : continue
561 indexEtape=self.editor.readercata.Classement_Commandes_Ds_Arbre.index(nom)
562 if indexEtape < indexName :
563 comment=tr('le mot clef ')+name+tr(' doit etre insere apres ')+nom
564 QMessageBox.information( None,tr('insertion impossible'),comment, )
568 def appendChild(self,name,pos=None,plier=False):
569 #------------------------------------------------
571 Methode pour ajouter un objet fils a l'objet associe au noeud self.
572 On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
573 ou en position intermediaire.
574 Si pos vaut None, on le place a la position du catalogue.
576 #print ("************** appendChild ",self.item.getLabelText(), pos, plier)
578 #traceback.print_stack()
581 self.editor.initModif()
582 if pos == 'first' : index = 0
583 elif pos == 'last' : index = len(self.children)
584 elif type(pos) == int : index = pos # position fixee
585 elif type(pos) == object : index = self.item.getIndex(pos) +1 # pos est un item. Il faut inserer name apres pos
586 elif type(name) == object : index = self.item.getIndexChild(name.nom)
587 else : index = self.item.getIndexChild(name)
589 # si on essaye d inserer a la racine
590 if (isinstance(self.treeParent,JDCTree) and index==0) :
591 verifiePosition=self.verifiePosition(name,'first',aLaRacine=True)
592 if not verifiePosition : return 0
594 self.tree.inhibeExpand = True
595 obj = self.item.addItem(name,index) # emet le signal 'add'
596 if obj is None : obj=0
597 if obj == 0 :return 0
601 child = self.children[index]
602 if plier == True : child.setPlie()
603 else : child.setDeplie()
605 child=self.children[index]
608 if len(obj) > 1 : self.buildChildren()
611 self.tree.inhibeExpand=False
612 #print (" fin append child")
617 self.editor.initModif()
618 index = self.treeParent.children.index(self) - 1
619 if index < 0 : index =0
620 ret=self.treeParent.item.deplaceEntite(self.item.getObject())
625 Methode externe pour la destruction de l'objet associe au noeud
627 self.editor.initModif()
628 index = self.vraiParent.children.index(self) - 1
629 if index < 0 : index =0
632 if self.item.nom == "VARIABLE" :
636 ret,commentaire=self.vraiParent.item.suppItem(self.item)
637 if ret==0 : self.editor.afficheInfos(commentaire,Qt.red)
638 else : self.editor.afficheInfos(commentaire)
639 self.treeParent.buildChildren()
640 if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
641 else : toselect=self.treeParent
643 if recalcule : jdc.recalculeEtatCorrelation()
645 if self.treeParent.childrenComplete :
646 notdeleted=self.treeParent.childrenComplete[index+1]
651 from InterfaceQT4 import compojdc
652 # cas ou on detruit dans l arbre sans affichage
653 if isinstance(self.treeParent,compojdc.Node) :
654 toselect.affichePanneau()
656 if self.treeParent.fenetre== None : return
657 #print "J appelle reaffiche de browser apres delete"
658 self.treeParent.fenetre.reaffiche(toselect)
660 def deleteMultiple(self,liste=()):
661 #--------------------------------
663 Methode externe pour la destruction d une liste de noeud
665 from InterfaceQT4 import compojdc
666 self.editor.initModif()
671 while not(isinstance(jdc,compojdc.Node)):
674 if not( isinstance(noeud.treeParent, compojdc.Node)): continue
675 if noeud.item.nom == "VARIABLE" : recalcule=1
676 if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
677 if index < 0 : index =0
679 # Cas ou on detruit dans une ETape
681 parentPosition=self.treeParent
682 while not(isinstance(parentPosition, compojdc.Node)):
683 index=parentPosition.treeParent.children.index(parentPosition)
684 parentPosition=parentPosition.treeParent
687 noeud.treeParent.item.suppItem(noeud.item)
690 if recalcule : jdc.recalculeEtatCorrelation()
691 try : toselect=parentPosition.children[index]
692 except : toselect=jdc
694 toselect.affichePanneau()
696 # ------------------------------------------------------------------
700 #print ("onValid pour ", self.item.nom)
701 if self.JESUISOFF==1 : return
703 if hasattr(self,'fenetre') and self.fenetre:
704 try : self.fenetre.setValide()
707 # PNPN lignes suivantes a repenser
708 if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isValid():
709 self.item.jdc.recalculeEtatCorrelation()
710 if hasattr(self.item,'forceRecalcul') : self.forceRecalculChildren(self.item.forceRecalcul)
711 self.editor.initModif()
713 self.updateNodeValid()
714 self.updateNodeLabel()
715 self.updateNodeTexte()
718 def onAdd(self,object):
719 #----------------------
720 #print ("onAdd pour ", self.item.nom, object)
721 if self.JESUISOFF == 1 : return
722 self.editor.initModif()
724 if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
726 def onSupp(self,object):
727 #-----------------------
728 #print ("onSup pour ", self.item.nom, object)
730 #traceback.print_stack()
731 if self.JESUISOFF==1 : return
732 self.editor.initModif()
734 if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
736 def onRedessine(self):
737 #---------------------
738 #print ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!je passe dans onRedessine pour', self.item.nom)
739 self.affichePanneau()
741 def updateNodeValid(self):
742 #-----------------------
743 """Cette methode remet a jour la validite du noeud (icone)
746 repIcon = self.appliEficas.repIcon
747 couleur = self.item.getIconName()
748 monIcone = QIcon(repIcon+"/" + couleur + ".png")
749 self.setIcon(0,monIcone)
753 def updateNodeLabel(self):
754 #-------------------------
755 """ Met a jour le label du noeud """
756 #print ("NODE updateNodeLabel", self.item.getLabelText())
757 labeltext,fonte,couleur = self.item.getLabelText()
759 if self.item.nom != tr(self.item.nom) : labeltext = str(tr(self.item.nom)+" :")
760 self.setText(0, tr(labeltext))
762 def updateNodeLabelInBlack(self):
763 #-------------------------------
764 if hasattr(self.appliEficas,'noeudColore'):
765 self.appliEficas.noeudColore.setForeground(0,Qt.black)
766 self.appliEficas.noeudColore.updateNodeLabel
768 def updateNodeLabelInBlue(self):
769 #-------------------------------
770 if hasattr(self.appliEficas,'noeudColore'): self.appliEficas.noeudColore.setForeground(0,Qt.black)
771 self.setForeground(0,Qt.blue)
772 labeltext,fonte,couleur = self.item.getLabelText()
773 if self.item.nom != tr(self.item.nom) : labeltext = str(tr(self.item.nom)+" :")
774 self.setText(0, labeltext)
775 self.appliEficas.noeudColore=self
777 def updatePlusieursNodeLabelInBlue(self,liste):
778 #----------------------------------------------
779 if hasattr(self.appliEficas,'listeNoeudsColores'):
780 for noeud in self.appliEficas.listeNoeudsColores:
781 noeud.setTextColor( 0,Qt.black)
782 noeud.updateNodeLabel()
783 self.appliEficas.listeNoeudsColores=[]
785 noeud.setTextColor( 0,Qt.blue )
786 labeltext,fonte,couleur = noeud.item.getLabelText()
787 if item.nom != tr(item.nom) : labeltext = str(tr(item.nom)+" :")
788 noeud.setText(0, labeltext)
789 self.appliEficas.listeNoeudsColores.append(noeud)
791 def updateNodeTexteInBlack(self):
792 #--------------------------------
793 """ Met a jour les noms des SD et valeurs des mots-cles """
794 self.setTextColor( 1,Qt.black )
795 value = self.item.getText()
796 self.setText(1, value)
798 def updateNodeTexte(self):
799 #----------------------------
800 """ Met a jour les noms des SD et valeurs des mots-cles """
801 value = self.item.getText()
802 self.setText(1, value)
805 def updateNodeTexteInBlue(self):
806 #--------------------------------
807 self.setTextColor( 1,Qt.blue )
808 value = self.item.getText()
809 self.setText(1, value)
811 def updateNodes(self):
812 #--------------------------------
813 #print 'NODE updateNodes', self.item.getLabelText()
816 def updateValid(self) :
817 #----------------------
818 """Cette methode a pour but de mettre a jour la validite du noeud
819 et de propager la demande de mise a jour a son parent
821 #print "NODE updateValid", self.item.getLabelText()
822 self.updateNodeValid()
823 try : self.treeParent.updateValid()
826 def updateTexte(self):
827 #----------------------
828 """ Met a jour les noms des SD et valeurs des mots-cles """
829 #print "NODE updateTexte", self.item.getLabelText()
830 self.updateNodeTexte()
831 if self.isExpanded() :
832 for child in self.children:
833 if child.isHidden() == false : child.updateTexte()
836 def forceRecalculChildren(self,niveau):
837 #--------------------------------------
838 if self.state == 'recalcule' :
841 self.state='recalcule'
842 if hasattr(self.item,'object'):
843 self.item.object.state="modified"
844 for child in self.children:
845 if niveau > 0 : child.forceRecalculChildren(niveau - 1)
849 def doPaste(self,node_selected,pos='after'):
850 #--------------------------------------------
852 Declenche la copie de l'objet item avec pour cible
853 l'objet passe en argument : node_selected
855 objet_a_copier = self.item.getCopieObjet()
856 child=node_selected.doPasteCommande(objet_a_copier,pos)
857 if self.editor.fenetreCentraleAffichee : self.editor.fenetreCentraleAffichee.node.affichePanneau()
858 self.updateNodeLabelInBlack()
861 def doPasteCommande(self,objet_a_copier,pos='after'):
862 #-----------------------------------------------------
864 Realise la copie de l'objet passe en argument qui est necessairement
870 child = self.appendBrother(objet_a_copier,pos)
875 def doPastePremier(self,objet_a_copier):
876 #---------------------------------------
878 Realise la copie de l'objet passe en argument (objet_a_copier)
880 objet = objet_a_copier.item.getCopieObjet()
881 child = self.appendChild(objet,pos='first')
884 def plieToutEtReafficheSaufItem(self, itemADeplier):
885 #---------------------------------------------------
886 self.inhibeExpand=True
887 from InterfaceQT4 import compojdc
888 if (isinstance(self, compojdc.Node)) :
889 self.affichePanneau()
890 self.inhibeExpand=False
892 self.editor.deplier = False
893 for item in self.children :
894 # il ne faut pas plier les blocs
895 from InterfaceQT4 import compobloc
896 if (isinstance(item,compobloc.Node)) : continue
898 if item==itemADeplier :
899 itemADeplier.setDeplie()
900 self.affichePanneau()
901 self.inhibeExpand=False
903 def plieToutEtReaffiche(self):
904 #-----------------------------
905 #print ('plieToutEtReaffiche', self.item.getNom())
906 from InterfaceQT4 import compojdc
907 if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return
908 self.inhibeExpand=True
909 self.editor.deplier = False
910 for item in self.children :
911 # il ne faut pas plier les blocs
912 from InterfaceQT4 import compobloc
913 if (isinstance(item,compobloc.Node)) : continue
915 self.affichePanneau()
916 #print ("fin plieToutEtReaffiche", self.item.getNom())
918 def deplieToutEtReaffiche(self):
919 #-----------------------------
920 self.editor.deplier = True
921 for item in self.children :
923 self.affichePanneau()
927 #print "je mets inhibeExpand a true dans setPlie"
928 #print ("je suis dans plieTout", self.item.getNom())
929 from . import compojdc
930 if self.fenetre == self.editor.fenetreCentraleAffichee and isinstance(self.treeParent,compojdc.Node):
932 self.tree.inhibeExpand=True
933 self.tree.collapseItem(self)
934 self.setPlieChildren()
935 self.tree.inhibeExpand=False
936 #print "je mets inhibeExpand a false dans setPlie"
939 # on ne plie pas au niveau 1
941 # for item in self.children :
942 # item.appartientAUnNoeudPlie=False
944 def setPlieChildren(self):
945 #-----------------------------
947 from InterfaceQT4 import composimp
948 if isinstance(self,composimp.Node) : return
949 for c in self.children :
951 #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.getLabelText()[0]
952 c.appartientAUnNoeudPlie=True
954 #print "dans setPlieChildren plie", c.item.nom
955 # 01/2018 PNPN : boucle sur MT __ La ligne suivante ne me semble pas necessaire
956 #if not (isinstance(c,composimp.Node)) :c.setExpanded(False)
958 # Pour les blocs et les motcles list
959 # on affiche un niveau de plus
960 from InterfaceQT4 import compobloc
961 from InterfaceQT4 import compomclist
962 if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) :
963 niveauPere=self.treeParent
964 while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) :
965 niveauPere=niveauPere.treeParent
966 for c in self.children :
967 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
968 #print ("dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.getLabelText()[0], "mis a la valeur ", niveauPere.appartientAUnNoeudPlie)
973 #-----------------------------
974 #print "dans setPlieChildren pour", self.item.nom
975 #print "je mets inhibeExpand a true dans setDeplie"
976 self.tree.inhibeExpand=True
978 self.tree.expandItem(self)
979 self.setDeplieChildren()
980 self.tree.inhibeExpand=False
981 #print "je mets inhibeExpand a false dans setDePlie"
983 def setDeplieChildren(self):
984 #-----------------------------
985 #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.getLabelText()
986 for c in self.children :
987 c.setDeplieChildren()
988 #print "dans setDeplieChildren ", c.item.nom
989 c.appartientAUnNoeudPlie=False
993 def selectAvant(self):
994 #-----------------------------
995 i=self.item.jdc.etapes.index(self.item.object)
996 try : cherche=self.item.jdc.etapes[i-1]
997 except : cherche=self.item.jdc.etapes[-1]
999 for i in self.tree.racine.children :
1000 if i.item.object== cherche :
1004 node.affichePanneau()
1007 def selectApres(self):
1008 #---------------------
1009 i=self.item.jdc.etapes.index(self.item.object)
1010 try : cherche=self.item.jdc.etapes[i+1]
1011 except : cherche=self.item.jdc.etapes[0]
1013 for i in self.tree.racine.children :
1014 if i.item.object== cherche :
1018 node.affichePanneau()