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 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
165 while not (hasattr (itemParent,'getPanel')) :
166 if itemParent.plie==True : itemParent.setDeplie()
168 itemParent=itemParent.treeParent
171 if itemParent.fenetre != self.editor.fenetreCentraleAffichee :
172 estUneFeuille=(isinstance(item,composimp.Node))
173 if itemParent.fenetreIhm == 'deplie1Niveau' :
174 if item == itemParent : itemParent.affichePanneau()
175 else : itemAvant.afficheCeNiveau()
176 elif estUneFeuille : itemParent.affichePanneau()
177 elif self.editor.maConfiguration.afficheCommandesPliees : itemParent.plieToutEtReafficheSaufItem(item)
178 else : itemParent.affichePanneau()
181 elif (isinstance(item,composimp.Node)) and item.fenetre : item.fenetre.rendVisible()
182 elif itemParent!=item:
183 self.tree.handleExpandedItem(item)
184 #item.fenetre.donnePremier()
185 #item.fenetre.rendActif()
186 #print 'il faut afficher le 1er'
189 fr = item.item.getFr()
190 chaineDecoupee= fr.split('\n')
191 if len(chaineDecoupee) > 3 :
192 txt='\n'.join(chaineDecoupee[0:2])+'...\nfull help : double clicked on validity chip of '+ str(item.item.nom)+ ' in central widget'
196 self.editor.afficheCommentaire(six.text_type(txt))
200 self.inhibeExpand = False
201 #print "je mets inhibeExpand a false handleOnItem"
204 def choisitPremier(self,name):
205 self.editor.layoutJDCCHOIX.removeWidget(self.racine.fenetre)
206 self.racine.fenetre.close()
207 new_node=self.racine.appendBrother(name,'after')
210 COMMENT = "COMMENTAIRE"
211 PARAMETERS = "PARAMETRE"
213 #------------------------------------------
214 class JDCNode(QTreeWidgetItem,GereRegles):
215 #------------------------------------------
216 def __init__( self, treeParent, item, itemExpand=False, ancien=False ):
217 #print ("creation d'un noeud : ", item, " ",item.nom,"", treeParent, self)
222 self.vraiParent = treeParent
223 self.treeParent = treeParent
224 self.tree = self.treeParent.tree
225 self.editor = self.treeParent.editor
226 self.appliEficas = treeParent.appliEficas
228 self.childrenComplete=[]
231 from InterfaceQT4 import compocomm
232 from InterfaceQT4 import compoparam
233 from InterfaceQT4 import composimp
234 if (isinstance(self.item,compocomm.COMMTreeItem)) : name=tr("Commentaire")
235 elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=tr(str(item.getLabelText()[0]))
236 #else: name = tr(str(tr(item.getLabelText()[0]))+" :")
237 else: name = tr(item.getLabelText()[0])
238 if item.nom != tr(item.nom) : name = str(tr(item.nom)+" :")
239 value = tr(str( item.getText() ) )
241 # si specialisation de la fenetre
242 if self.item.object.definition == None : self.fenetreIhm = None
243 # Cas des listes de mots_clefs
244 else : self.fenetreIhm = self.item.object.definition.fenetreIhm
246 if self.editor.enteteQTree=='complet':mesColonnes=(name,value)
247 else : mesColonnes=(name,)
249 if self.treeParent.plie==True :
251 self.appartientAUnNoeudPlie=True
252 if self.treeParent.item.isMCList() : self.appartientAUnNoeudPlie = self.treeParent.appartientAUnNoeudPlie
255 self.appartientAUnNoeudPlie = False
257 #if item.nom == "POUTRE" :print "creation d'un noeud : ", item, " ",item.nom,"", self.treeParent, self.appartientAUnNoeudPlie , self.plie
259 if ancien and itemExpand : self.plie = False
260 if ancien and not itemExpand : self.plie = True
261 if (isinstance(self.item,composimp.SIMPTreeItem)) : self.plie=False
263 from InterfaceQT4 import compobloc
264 from InterfaceQT4 import compomclist
266 ajoutAuParentduNoeud=0
267 self.treeParent=treeParent
268 while (isinstance(self.treeParent,compobloc.Node) or ( isinstance(self.treeParent,compomclist.Node) and self.treeParent.item.isMCList())) :
269 self.treeParent.childrenComplete.append(self)
270 self.treeParent=self.treeParent.vraiParent
271 self.treeParent.childrenComplete.append(self)
274 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)) :
275 # Le dernier or ne sert que lorsqu'on est en train de creer une liste par les validator
276 QTreeWidgetItem.__init__(self,None,mesColonnes)
278 QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
280 self.setToolTip(0,self.item.getFr())
281 self.setToolTip(1,self.item.getFr())
282 repIcon=self.appliEficas.repIcon
284 couleur=self.item.getIconName()
285 monIcone = QIcon(repIcon+"/" + couleur + ".png")
287 self.setIcon(0,monIcone)
294 self.item.connect("valid",self.onValid,())
295 self.item.connect("supp" ,self.onSupp,())
296 self.item.connect("add" ,self.onAdd,())
301 if self.item.getObject().isBLOC() :
302 self.setExpanded(True)
308 def buildChildren(self,posInsertion=10000):
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 sublist = self.item._getSubList()
345 for node in self.childrenComplete:
346 if node.item.object==objSimp : return node
350 def afficheCeNiveau(self):
351 #print ('afficheCeNiveau pour ', self.item.nom, self.item.getLabelText())
352 for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
353 widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
354 self.editor.widgetCentraleLayout.removeItem(widget)
355 if self.editor.fenetreCentraleAffichee != None :
356 self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
357 self.editor.fenetreCentraleAffichee.setParent(None)
358 self.editor.fenetreCentraleAffichee.close()
359 self.editor.fenetreCentraleAffichee.deleteLater()
361 from monWidgetNiveauFact import MonWidgetNiveauFact, MonWidgetNiveauFactTableau
362 maDefinition=self.item.get_definition()
363 monObjet=self.item.object
364 if maDefinition.fenetreIhm=='Tableau' : self.maFenetreCadre=MonWidgetNiveauFactTableau(self,self.editor,maDefinition,monObjet)
365 else : self.maFenetreCadre=MonWidgetNiveauFact(self,self.editor,maDefinition,monObjet)
367 self.fenetre=self.maFenetreCadre
368 self.editor.widgetCentraleLayout.addWidget(self.maFenetreCadre)
369 self.editor.fenetreCentraleAffichee=self.maFenetreCadre
371 #print ('fin afficheCeNiveau pour ', self.item.nom)
374 def getPanelModifie(self):
376 if self.fenetreIhm == None : return None
377 if self.fenetreIhm=='deplie1Niveau':
378 from InterfaceQT4.monWidgetCommandeDeplie1Niveau import MonWidgetCommandeDeplie1Niveau
379 return MonWidgetCommandeDeplie1Niveau (self,self.editor ,self.item.object)
383 def affichePanneau(self) :
384 #if self.editor.code == 'ASTER' and not(self.item.isActif()) :
385 # posera des pb si un code decide d appeler FIN un mot clef
386 # on resoudera a ce moment la
387 # pour l pas de poussiere sous le tapis
388 #print ('_________________ds affichePanneau pour', self.item.nom)
389 if not(self.item.isActif()) :
390 from .monWidgetInactif import MonWidgetInactif
391 self.fenetre = MonWidgetInactif(self,self.editor)
394 while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent
395 if itemParent!=self :
396 #print ('j appelle affichePanneau pour ', itemParent.item.nom , 'par', self.item.nom)
397 itemParent.affichePanneau()
398 #print ('fin _________________ds affichePanneau pour', self.item.nom)
400 self.fenetre=self.getPanelModifie()
401 if self.fenetre == None : self.fenetre=self.getPanel()
402 self.editor.restoreSplitterSizes()
404 for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
405 widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
406 self.editor.widgetCentraleLayout.removeItem(widget)
407 # ceinture et bretelle
408 #print 'old fenetre = ',self.editor.fenetreCentraleAffichee
409 if self.editor.fenetreCentraleAffichee != None :
410 self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
411 self.editor.fenetreCentraleAffichee.setParent(None)
412 self.editor.fenetreCentraleAffichee.close()
413 self.editor.fenetreCentraleAffichee.deleteLater()
415 self.editor.widgetCentraleLayout.addWidget(self.fenetre)
416 #print ("j ajoute ", self.fenetre, self.fenetre.node.item.nom)
417 self.editor.fenetreCentraleAffichee=self.fenetre
418 self.tree.node_selected= self
420 if self.editor.first :
421 if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
422 self.tree.inhibeExpand=True
423 self.tree.expandItem(self)
424 self.tree.inhibeExpand=False
425 #print( '_________________fin affichePanneau pour', self.item.nom)
428 def createPopUpMenu(self):
429 #implemente dans les noeuds derives si necessaire
434 Cette methode a pour but de commentariser la commande pointee par self
436 # On traite par une exception le cas ou l'utilisateur final cherche a desactiver
437 # (commentariser) un commentaire.
439 pos=self.treeParent.children.index(self)
440 commande_comment = self.item.getObjetCommentarise()
441 # On signale a l editeur du panel (le JDCDisplay) une modification
442 self.editor.initModif()
443 self.treeParent.buildChildren()
444 self.treeParent.children[pos].select()
445 self.treeParent.children[pos].affichePanneau()
446 except Exception as e:
447 traceback.print_exc()
448 QMessageBox.critical( self.editor, "TOO BAD",str(e))
450 def unCommentIt(self):
452 Realise la decommentarisation de self
455 pos=self.treeParent.children.index(self)
456 commande,nom = self.item.unComment()
457 self.editor.initModif()
458 self.treeParent.buildChildren()
459 self.treeParent.children[pos].select()
460 self.treeParent.children[pos].affichePanneau()
461 except Exception as e:
462 QMessageBox.critical( self.editor, "Erreur !",str(e))
464 def addComment( self, after=True ):
466 Ajoute un commentaire a l'interieur du JDC :
468 self.editor.initModif()
473 return self.appendBrother( COMMENT, pos )
475 def addParameters( self, after=True ):
477 Ajoute un parametre a l'interieur du JDC :
479 self.editor.initModif()
480 if after: pos = 'after'
482 child=self.appendBrother( PARAMETERS, pos )
488 Rend le noeud courant (self) selectionne et deselectionne
491 #print "select pour", self.item.nom
492 for item in self.tree.selectedItems() :
494 self.tree.setCurrentItem( self )
496 #------------------------------------------------------------------
497 # Methodes de creation et destruction de noeuds
498 # Certaines de ces methodes peuvent etre appelees depuis l'externe
499 #------------------------------------------------------------------
500 def appendBrother(self,name,pos='after',plier=False):
502 Permet d'ajouter un objet frere a l'objet associe au noeud self
503 par defaut on l'ajoute immediatement apres
506 self.editor.initModif()
508 from InterfaceQT4 import compojdc
509 if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos) : return 0
511 if self.treeParent != self.vraiParent :
512 index = self.vraiParent.children.index(self)
513 if pos == 'before': index = index
514 elif pos == 'after': index = index +1
515 return self.vraiParent.appendChild(name,pos=index,plier=plier)
517 index = self.treeParent.children.index(self)
518 if pos == 'before': index = index
519 elif pos == 'after': index = index +1
521 print(six.text_type(pos), tr(" n'est pas un index valide pour appendBrother"))
523 return self.treeParent.appendChild(name,pos=index,plier=plier)
525 def verifiePosition(self,name,pos,aLaRacine=False):
526 if name not in self.editor.readercata.Classement_Commandes_Ds_Arbre : return True
527 indexName=self.editor.readercata.Classement_Commandes_Ds_Arbre.index(name)
529 etapes=self.item.getJdc().etapes
530 if etapes == [] : return True
532 if aLaRacine == False :indexOu=etapes.index(self.item.object)
535 if pos=="after" : indexOu = indexOu+1
536 for e in etapes[:indexOu] :
538 if nom not in self.editor.readercata.Classement_Commandes_Ds_Arbre : continue
539 indexEtape=self.editor.readercata.Classement_Commandes_Ds_Arbre.index(nom)
540 if indexEtape > indexName :
541 comment=tr('le mot clef ')+name+tr(' doit etre insere avant ')+nom
542 QMessageBox.information( None,tr('insertion impossible'),comment, )
544 for e in etapes[indexOu:] :
546 if nom not in self.editor.readercata.Classement_Commandes_Ds_Arbre : continue
547 indexEtape=self.editor.readercata.Classement_Commandes_Ds_Arbre.index(nom)
548 if indexEtape < indexName :
549 comment=tr('le mot clef ')+name+tr(' doit etre insere apres ')+nom
550 QMessageBox.information( None,tr('insertion impossible'),comment, )
554 def appendChild(self,name,pos=None,plier=False):
556 Methode pour ajouter un objet fils a l'objet associe au noeud self.
557 On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
558 ou en position intermediaire.
559 Si pos vaut None, on le place a la position du catalogue.
561 #print ("************** appendChild ",self.item.getLabelText(), pos, plier)
563 #traceback.print_stack()
566 self.editor.initModif()
570 index = len(self.children)
571 elif type(pos) == int :
574 elif type(pos) == object:
575 #elif type(pos) == types.InstanceType:
576 # pos est un item. Il faut inserer name apres pos
577 index = self.item.getIndex(pos) +1
578 #elif type(name) == types.InstanceType:
579 elif type(name) == object:
580 index = self.item.getIndexChild(name.nom)
582 index = self.item.getIndexChild(name)
584 # si on essaye d inserer a la racine
585 if (isinstance(self.treeParent,JDCTree) and index==0) :
586 verifiePosition=self.verifiePosition(name,'first',aLaRacine=True)
587 if not verifiePosition : return 0
589 self.tree.inhibeExpand=True
590 obj=self.item.addItem(name,index) # emet le signal 'add'
595 child=self.children[index]
596 if plier == True : child.setPlie()
597 else : child.setDeplie()
599 child=self.children[index]
601 if len(obj) > 1 : self.buildChildren()
603 self.tree.inhibeExpand=False
604 #print (" fin append child")
608 self.editor.initModif()
609 index = self.treeParent.children.index(self) - 1
610 if index < 0 : index =0
611 ret=self.treeParent.item.deplaceEntite(self.item.getObject())
615 Methode externe pour la destruction de l'objet associe au noeud
617 self.editor.initModif()
618 index = self.vraiParent.children.index(self) - 1
619 if index < 0 : index =0
621 if self.item.nom == "VARIABLE" :
624 ret,commentaire=self.vraiParent.item.suppItem(self.item)
626 self.editor.afficheInfos(commentaire,Qt.red)
628 self.editor.afficheInfos(commentaire)
629 self.treeParent.buildChildren()
630 if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
631 else: toselect=self.treeParent
632 if recalcule : jdc.recalculeEtatCorrelation()
634 if self.treeParent.childrenComplete :
635 notdeleted=self.treeParent.childrenComplete[index+1]
639 from InterfaceQT4 import compojdc
640 # cas ou on detruit dans l arbre sans affichage
641 if isinstance(self.treeParent,compojdc.Node) :
642 toselect.affichePanneau()
644 if self.treeParent.fenetre== None : return
645 #print "J appelle reaffiche de browser apres delete"
646 self.treeParent.fenetre.reaffiche(toselect)
648 def deleteMultiple(self,liste=()):
650 Methode externe pour la destruction d une liste de noeud
652 from InterfaceQT4 import compojdc
653 self.editor.initModif()
658 while not(isinstance(jdc,compojdc.Node)):
661 if not( isinstance(noeud.treeParent, compojdc.Node)): continue
662 if noeud.item.nom == "VARIABLE" : recalcule=1
663 if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
664 if index < 0 : index =0
666 # Cas ou on detruit dans une ETape
668 parentPosition=self.treeParent
669 while not(isinstance(parentPosition, compojdc.Node)):
670 index=parentPosition.treeParent.children.index(parentPosition)
671 parentPosition=parentPosition.treeParent
674 noeud.treeParent.item.suppItem(noeud.item)
677 if recalcule : jdc.recalculeEtatCorrelation()
678 try : toselect=parentPosition.children[index]
679 except : toselect=jdc
681 toselect.affichePanneau()
683 # #------------------------------------------------------------------
686 #print ("onValid pour ", self.item.nom)
687 if self.JESUISOFF==1 : return
688 if hasattr(self,'fenetre') and self.fenetre:
690 self.fenetre.setValide()
692 # print "onValid pour ", self.item.nom, self,'pb'
695 if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isValid():
696 self.item.jdc.recalculeEtatCorrelation()
697 if hasattr(self.item,'forceRecalcul'):
698 self.forceRecalculChildren(self.item.forceRecalcul)
699 self.editor.initModif()
701 self.updateNodeValid()
702 self.updateNodeLabel()
703 self.updateNodeTexte()
705 def onAdd(self,object):
706 if self.JESUISOFF==1 : return
707 #print ("onAdd pour ", self.item.nom, object)
708 self.editor.initModif()
710 # PN -- non necessaire si item=jdc
711 if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
713 def onSupp(self,object):
714 if self.JESUISOFF==1 : return
715 #print "onSup pour ", self.item.nom, object
716 self.editor.initModif()
718 # PN -- non necessaire si item=jdc
719 if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
723 def updateNodeValid(self):
724 """Cette methode remet a jour la validite du noeud (icone)
727 repIcon=self.appliEficas.repIcon
728 couleur=self.item.getIconName()
729 monIcone = QIcon(repIcon+"/" + couleur + ".png")
730 self.setIcon(0,monIcone)
734 def updateNodeLabel(self):
735 """ Met a jour le label du noeud """
736 #print "NODE updateNodeLabel", self.item.getLabelText()
737 labeltext,fonte,couleur = self.item.getLabelText()
739 if self.item.nom != tr(self.item.nom) : labeltext = str(tr(self.item.nom)+" :")
740 self.setText(0, tr(labeltext))
742 def updateNodeLabelInBlack(self):
743 if hasattr(self.appliEficas,'noeudColore'):
744 self.appliEficas.noeudColore.setForeground(0,Qt.black)
745 self.appliEficas.noeudColore.updateNodeLabel
747 def updateNodeLabelInBlue(self):
748 if hasattr(self.appliEficas,'noeudColore'): self.appliEficas.noeudColore.setForeground(0,Qt.black)
749 self.setForeground(0,Qt.blue)
750 labeltext,fonte,couleur = self.item.getLabelText()
751 if self.item.nom != tr(self.item.nom) : labeltext = str(tr(self.item.nom)+" :")
752 self.setText(0, labeltext)
753 self.appliEficas.noeudColore=self
755 def updatePlusieursNodeLabelInBlue(self,liste):
756 if hasattr(self.appliEficas,'listeNoeudsColores'):
757 for noeud in self.appliEficas.listeNoeudsColores:
758 noeud.setTextColor( 0,Qt.black)
759 noeud.updateNodeLabel()
760 self.appliEficas.listeNoeudsColores=[]
762 noeud.setTextColor( 0,Qt.blue )
763 labeltext,fonte,couleur = noeud.item.getLabelText()
764 if item.nom != tr(item.nom) : labeltext = str(tr(item.nom)+" :")
765 noeud.setText(0, labeltext)
766 self.appliEficas.listeNoeudsColores.append(noeud)
768 def updateNodeTexteInBlack(self):
769 """ Met a jour les noms des SD et valeurs des mots-cles """
770 self.setTextColor( 1,Qt.black )
771 value = self.item.getText()
772 self.setText(1, value)
774 def updateNodeTexte(self):
775 """ Met a jour les noms des SD et valeurs des mots-cles """
776 value = self.item.getText()
777 self.setText(1, value)
780 def updateNodeTexteInBlue(self):
781 self.setTextColor( 1,Qt.blue )
782 value = self.item.getText()
783 self.setText(1, value)
785 def updateNodes(self):
786 #print 'NODE updateNodes', self.item.getLabelText()
789 def updateValid(self) :
790 """Cette methode a pour but de mettre a jour la validite du noeud
791 et de propager la demande de mise a jour a son parent
793 #print "NODE updateValid", self.item.getLabelText()
794 self.updateNodeValid()
796 self.treeParent.updateValid()
800 def updateTexte(self):
801 """ Met a jour les noms des SD et valeurs des mots-cles """
802 #print "NODE updateTexte", self.item.getLabelText()
803 self.updateNodeVexte()
804 if self.isExpanded() :
805 for child in self.children:
806 if child.isHidden() == false : child.updateTexte()
809 def forceRecalculChildren(self,niveau):
810 if self.state=='recalcule' :
813 self.state='recalcule'
814 if hasattr(self.item,'object'):
815 self.item.object.state="modified"
816 for child in self.children:
817 if niveau > 0 : child.forceRecalculChildren(niveau - 1)
821 def doPaste(self,node_selected,pos='after'):
823 Declenche la copie de l'objet item avec pour cible
824 l'objet passe en argument : node_selected
826 objet_a_copier = self.item.getCopieObjet()
827 child=node_selected.doPasteCommande(objet_a_copier,pos)
828 if self.editor.fenetreCentraleAffichee : self.editor.fenetreCentraleAffichee.node.affichePanneau()
829 self.updateNodeLabelInBlack()
832 def doPasteCommande(self,objet_a_copier,pos='after'):
834 Realise la copie de l'objet passe en argument qui est necessairement
840 child = self.appendBrother(objet_a_copier,pos)
845 def doPastePremier(self,objet_a_copier):
847 Realise la copie de l'objet passe en argument (objet_a_copier)
849 objet = objet_a_copier.item.getCopieObjet()
850 child = self.appendChild(objet,pos='first')
853 def plieToutEtReafficheSaufItem(self, itemADeplier):
854 self.inhibeExpand=True
855 from InterfaceQT4 import compojdc
856 if (isinstance(self, compojdc.Node)) :
857 self.affichePanneau()
858 self.inhibeExpand=False
860 self.editor.deplier = False
861 for item in self.children :
862 # il ne faut pas plier les blocs
863 from InterfaceQT4 import compobloc
864 if (isinstance(item,compobloc.Node)) : continue
866 if item==itemADeplier :
867 itemADeplier.setDeplie()
868 self.affichePanneau()
869 self.inhibeExpand=False
871 def plieToutEtReaffiche(self):
872 #print ('plieToutEtReaffiche', self.item.getNom())
873 from InterfaceQT4 import compojdc
874 if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return
875 self.inhibeExpand=True
876 self.editor.deplier = False
877 for item in self.children :
878 # il ne faut pas plier les blocs
879 from InterfaceQT4 import compobloc
880 if (isinstance(item,compobloc.Node)) : continue
882 self.affichePanneau()
883 #print ("fin plieToutEtReaffiche", self.item.getNom())
885 def deplieToutEtReaffiche(self):
886 self.editor.deplier = True
887 for item in self.children :
889 self.affichePanneau()
892 #print "je mets inhibeExpand a true dans setPlie"
893 #print ("je suis dans plieTout", self.item.getNom())
894 from . import compojdc
895 if self.fenetre == self.editor.fenetreCentraleAffichee and isinstance(self.treeParent,compojdc.Node):
897 self.tree.inhibeExpand=True
898 self.tree.collapseItem(self)
899 self.setPlieChildren()
900 self.tree.inhibeExpand=False
901 #print "je mets inhibeExpand a false dans setPlie"
904 # on ne plie pas au niveau 1
906 # for item in self.children :
907 # item.appartientAUnNoeudPlie=False
909 def setPlieChildren(self):
911 from InterfaceQT4 import composimp
912 if isinstance(self,composimp.Node) : return
913 for c in self.children :
915 #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.getLabelText()[0]
916 c.appartientAUnNoeudPlie=True
918 #print "dans setPlieChildren plie", c.item.nom
919 # 01/2018 PNPN : boucle sur MT __ La ligne suivante ne me semble pas necessaire
920 #if not (isinstance(c,composimp.Node)) :c.setExpanded(False)
922 # Pour les blocs et les motcles list
923 # on affiche un niveau de plus
924 from InterfaceQT4 import compobloc
925 from InterfaceQT4 import compomclist
926 if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) :
927 niveauPere=self.treeParent
928 while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) :
929 niveauPere=niveauPere.treeParent
930 for c in self.children :
931 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
932 #print ("dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.getLabelText()[0], "mis a la valeur ", niveauPere.appartientAUnNoeudPlie)
937 self.tree.inhibeExpand=True
939 self.tree.expandItem(self)
940 self.setDeplieChildren()
941 self.tree.inhibeExpand=False
942 #print "je mets inhibeExpand a false dans setDePlie"
944 def setDeplieChildren(self):
945 #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.getLabelText()
946 for c in self.children :
947 c.setDeplieChildren()
948 #print "dans setDeplieChildren ", c.item.nom
949 c.appartientAUnNoeudPlie=False
953 def selectAvant(self):
954 i=self.item.jdc.etapes.index(self.item.object)
956 cherche=self.item.jdc.etapes[i-1]
958 cherche=self.item.jdc.etapes[-1]
960 for i in self.tree.racine.children :
961 if i.item.object== cherche :
965 node.affichePanneau()
968 def selectApres(self):
969 i=self.item.jdc.etapes.index(self.item.object)
971 cherche=self.item.jdc.etapes[i+1]
973 cherche=self.item.jdc.etapes[0]
975 for i in self.tree.racine.children :
976 if i.item.object== cherche :
980 node.affichePanneau()
983 def ouvreLesNoeudsDsLArbre(self):
985 self.inhibeExpand = True
986 for i in range(self.childCount()):
987 self.child(i).inhibeExpand=True
988 self.child(i).setExpanded(True)
989 self.child(i).ouvreLesNoeudsDsLArbre()
990 self.child(i).inhibeExpand=False
991 self.inhibeExpand = False