1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 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
27 from determine import monEnvQT5
29 from PyQt5.QtWidgets import QTreeWidget , QTreeWidgetItem,QApplication
30 from PyQt5.QtGui import QIcon
31 from PyQt5.QtCore import Qt
33 from PyQt4.QtGui import *
34 from PyQt4.QtCore import *
35 from Extensions.i18n import tr
36 from gereRegles import GereRegles
37 from monChoixCommande import MonChoixCommande
39 class JDCTree( QTreeWidget,GereRegles ):
40 def __init__( self, jdc_item, QWParent):
41 #if hasattr(QWParent,'widgetTree') :
42 self.editor = QWParent
44 if self.editor.widgetTree !=None :
45 QTreeWidget.__init__(self, self.editor.widgetTree )
46 self.editor.verticalLayout_2.addWidget(self)
47 if self.editor.enteteQTree=='complet':
48 self.headerItem().setText(0, "Commande ")
49 self.headerItem().setText(1, "Concept/Valeur")
51 self.headerItem().setText(0, "Commande ")
52 self.setColumnWidth(0,200)
53 self.setExpandsOnDoubleClick(False)
54 self.setSelectionMode(3)
56 QTreeWidget.__init__(self, None )
59 self.appliEficas = self.editor.appliEficas
60 self.childrenComplete=[]
61 self.racine=self.item.itemNode(self,self.item)
63 self.itemCourrant=None
66 self.itemClicked.connect(self.handleOnItem)
67 self.itemCollapsed.connect(self.handleCollapsedItem)
68 self.itemExpanded.connect(self.handleExpandedItem)
70 self.connect(self, SIGNAL("itemClicked ( QTreeWidgetItem * ,int) "), self.handleOnItem)
71 self.connect(self, SIGNAL("itemCollapsed ( QTreeWidgetItem *) "), self.handleCollapsedItem)
72 self.connect(self, SIGNAL("itemExpanded ( QTreeWidgetItem *) "), self.handleExpandedItem)
74 #PNPNPN verifier dans quel cas on se trouve : affiche l arbre ou la commande
75 self.node_selected=self.racine
76 self.inhibeExpand=True
77 self.expandItem(self.racine)
78 self.inhibeExpand=False
79 #print "self.editor.afficheCommandesPliees", self.editor.afficheCommandesPliees
80 if self.racine.children !=[] :
81 self.editor.initSplitterSizes(3)
82 if self.editor.afficheCommandesPliees : self.racine.children[0].plieToutEtReaffiche()
83 else : self.racine.children[0].deplieToutEtReaffiche()
84 self.racine.children[0].fenetre.donnePremier()
86 self.editor.initSplitterSizes(2)
87 self.racine.affichePanneau()
88 #print self.editor.splitter.sizes()
92 def contextMenuEvent(self,event) :
93 #print "contextMenuEvent"
94 coord=event.globalPos()
95 item= self.currentItem()
96 self.handleContextMenu(item,coord)
98 def handleContextMenu(self,item,coord):
100 Private slot to show the context menu of the listview.
102 @param itm the selected listview item (QListWidgetItem)
103 @param coord the position of the mouse pointer (QPoint)
104 Attention : existeMenu permet de savoir si un menu est associe a cet item
106 #print "handleContextMenu"
107 if item == None : return
108 if item.existeMenu == 0 : return
109 if item.menu == None:
110 item.createPopUpMenu()
111 if item.menu != None:
112 if item.item.get_nom() == "DISTRIBUTION" and item.item.isvalid() :
113 item.Graphe.setEnabled(1)
114 item.menu.exec_(coord)
117 def handleCollapsedItem(self,item):
118 #print "dans CollapsedItem", self.inhibeExpand
119 if self.inhibeExpand == True : return
120 # On traite le cas de l item non selectionne
122 while not (hasattr (itemParent,'getPanel')) :
123 itemParent=itemParent.treeParent
124 if self.tree.node_selected != itemParent :
125 item.setExpanded(False)
130 item.plieToutEtReaffiche()
133 def handleExpandedItem(self,item):
134 #print "handleExpandedItem pour ", item.item.nom, self.inhibeExpand
136 #traceback.print_stack()
137 if self.inhibeExpand == True : return
138 self.inhibeExpand = True
140 while not (hasattr (itemParent,'getPanel')) :
141 if itemParent.plie==True : itemParent.setDeplie()
142 itemParent=itemParent.treeParent
143 if self.tree.node_selected != itemParent :
144 item.setExpanded(True)
145 self.inhibeExpand = False
147 item.deplieToutEtReaffiche()
148 self.inhibeExpand = False
151 def handleOnItem(self,item,int):
152 #print "je passe dans handleOnItem pour ",self, item.item.nom, item, item.item
154 from InterfaceQT4 import composimp
155 self.inhibeExpand = True
156 self.itemCourrant=item
159 while not (hasattr (itemParent,'getPanel')) :
160 if itemParent.plie==True : itemParent.setDeplie()
161 itemParent=itemParent.treeParent
163 if itemParent.fenetre != self.editor.fenetreCentraleAffichee :
165 estUneFeuille=(isinstance(item,composimp.Node))
166 # il faut afficher le parent
167 #print "estUneFeuille", estUneFeuille
168 #print "afficheCommandesPliees", self.editor.afficheCommandesPliees
169 if estUneFeuille : itemParent.affichePanneau()
170 elif self.editor.afficheCommandesPliees : itemParent.plieToutEtReafficheSaufItem(item)
171 else : itemParent.affichePanneau()
174 elif (isinstance(item,composimp.Node)) and item.fenetre : item.fenetre.rendVisible()
175 elif itemParent!=item:
176 self.tree.handleExpandedItem(item)
177 #item.fenetre.donnePremier()
178 #item.fenetre.rendActif()
179 #print 'il faut afficher le 1er'
182 fr = item.item.get_fr()
183 if self.editor: self.editor.affiche_commentaire(unicode(fr))
187 self.inhibeExpand = False
188 #print "je mets inhibeExpand a false handleOnItem"
191 def choisitPremier(self,name):
192 self.editor.layoutJDCCHOIX.removeWidget(self.racine.fenetre)
193 self.racine.fenetre.close()
194 new_node=self.racine.append_brother(name,'after')
197 COMMENT = "COMMENTAIRE"
198 PARAMETERS = "PARAMETRE"
200 class JDCNode(QTreeWidgetItem,GereRegles):
201 def __init__( self, treeParent, item, itemExpand=False, ancien=False ):
202 #print "creation d'un noeud : ", item, " ",item.nom,"", treeParent, self
205 self.vraiParent = treeParent
206 self.treeParent = treeParent
207 self.tree = self.treeParent.tree
208 self.editor = self.treeParent.editor
209 self.appliEficas = treeParent.appliEficas
211 self.childrenComplete=[]
214 from InterfaceQT4 import compocomm
215 from InterfaceQT4 import compoparam
216 from InterfaceQT4 import composimp
217 if (isinstance(self.item,compocomm.COMMTreeItem)) : name=tr("Commentaire")
218 elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=tr(str(item.GetLabelText()[0]))
219 else: name = tr(str(tr( item.nom))+" :")
220 value = tr(str( item.GetText() ) )
224 if self.editor.enteteQTree=='complet':mesColonnes=(name,value)
225 else : mesColonnes=(name,)
227 mesColonnes=QStringList()
228 if self.editor.enteteQTree=='complet': mesColonnes << name << value
229 else : mesColonnes << name
231 if self.treeParent.plie==True :
233 self.appartientAUnNoeudPlie=True
234 if self.treeParent.item.isMCList() : self.appartientAUnNoeudPlie = self.treeParent.appartientAUnNoeudPlie
237 self.appartientAUnNoeudPlie = False
239 #if item.nom == "POUTRE" :print "creation d'un noeud : ", item, " ",item.nom,"", self.treeParent, self.appartientAUnNoeudPlie , self.plie
241 if ancien and itemExpand : self.plie = False
242 if ancien and not itemExpand : self.plie = True
243 if (isinstance(self.item,composimp.SIMPTreeItem)) : self.plie=False
245 from InterfaceQT4 import compobloc
246 from InterfaceQT4 import compomclist
248 ajoutAuParentduNoeud=0
249 self.treeParent=treeParent
250 while (isinstance(self.treeParent,compobloc.Node) or ( isinstance(self.treeParent,compomclist.Node) and self.treeParent.item.isMCList())) :
251 self.treeParent.childrenComplete.append(self)
252 self.treeParent=self.treeParent.vraiParent
253 self.treeParent.childrenComplete.append(self)
256 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)) :
257 # Le dernier or ne sert que lorsqu'on est en train de creer une liste par les validator
258 QTreeWidgetItem.__init__(self,None,mesColonnes)
260 QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
263 self.setToolTip(0,self.item.get_fr())
264 self.setToolTip(1,self.item.get_fr())
265 repIcon=self.appliEficas.repIcon
267 self.setToolTip(0,QString(self.item.get_fr()))
268 self.setToolTip(1,QString(self.item.get_fr()))
269 repIcon=QString(self.appliEficas.repIcon)
271 monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
272 self.setIcon(0,monIcone)
275 self.build_children()
279 self.item.connect("valid",self.onValid,())
280 self.item.connect("supp" ,self.onSupp,())
281 self.item.connect("add" ,self.onAdd,())
286 if self.item.getObject().isBLOC() :
287 self.setExpanded(True)
293 def build_children(self,posInsertion=10000):
294 """ Construit la liste des enfants de self """
295 """ Se charge de remettre les noeuds Expanded dans le meme etat """
296 #print "*********** build_children ",self,self.item, self.item.nom
298 self.listeItemExpanded=[]
299 self.listeItemPlie=[]
301 for enfant in self.childrenComplete :
302 if enfant.plie : self.listeItemPlie.append(enfant.item)
303 else : self.listeItemExpanded.append(enfant.item)
305 for enfant in self.childrenComplete :
306 parent=enfant.treeParent
307 parent.removeChild(enfant)
312 self.childrenComplete = []
313 sublist = self.item._GetSubList()
316 for item in sublist :
319 if item in self.listeItemExpanded : itemExpand=True; ancien=True
320 if item in self.listeItemPlie : itemExpand=False; ancien=True
321 nouvelItem=item.itemNode(self,item,itemExpand,ancien)
322 self.children.append(nouvelItem)
324 #print "fin *********** build_children ",self,self.item, self.item.nom, self.children
327 def chercheNoeudCorrespondant(self,objSimp):
328 sublist = self.item._GetSubList()
329 for node in self.childrenComplete:
330 if node.item.object==objSimp : return node
334 def affichePanneau(self) :
335 #if self.editor.code == 'ASTER' and not(self.item.isactif()) :
336 # posera des pb si un code decide d appeler FIN un mot clef
337 # on resoudera a ce moment la
338 # pour l instant pas de poussiere sous le tapis
339 if not(self.item.isactif()) :
340 from monWidgetInactif import MonWidgetInactif
341 self.fenetre = MonWidgetInactif(self,self.editor)
344 while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent
345 if itemParent!=self :
346 itemParent.affichePanneau()
348 self.fenetre=self.getPanel()
349 self.editor.restoreSplitterSizes()
351 for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
352 widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
353 self.editor.widgetCentraleLayout.removeItem(widget)
354 # ceinture et bretelle
355 #print 'old fenetre = ',self.editor.fenetreCentraleAffichee
356 if self.editor.fenetreCentraleAffichee != None :
357 self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
358 self.editor.fenetreCentraleAffichee.setParent(None)
359 self.editor.fenetreCentraleAffichee.close()
360 self.editor.fenetreCentraleAffichee.deleteLater()
362 self.editor.widgetCentraleLayout.addWidget(self.fenetre)
363 #print "j ajoute ", self.fenetre, self.fenetre.node.item.nom
364 self.editor.fenetreCentraleAffichee=self.fenetre
365 self.tree.node_selected= self
367 if self.editor.first :
368 if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
369 self.tree.inhibeExpand=True
370 self.tree.expandItem(self)
371 self.tree.inhibeExpand=False
372 #print "fin de affichePanneau", self.item.nom
373 #print "______________________________"
376 def createPopUpMenu(self):
377 #implemente dans les noeuds derives si necessaire
382 Cette methode a pour but de commentariser la commande pointee par self
384 # On traite par une exception le cas ou l'utilisateur final cherche a désactiver
385 # (commentariser) un commentaire.
387 pos=self.treeParent.children.index(self)
388 commande_comment = self.item.get_objet_commentarise()
389 # On signale a l editeur du panel (le JDCDisplay) une modification
390 self.editor.init_modif()
391 self.treeParent.build_children()
392 self.treeParent.children[pos].select()
393 self.treeParent.children[pos].affichePanneau()
395 traceback.print_exc()
396 QMessageBox.critical( self.editor, "TOO BAD",str(e))
398 def unCommentIt(self):
400 Realise la decommentarisation de self
403 pos=self.treeParent.children.index(self)
404 commande,nom = self.item.uncomment()
405 self.editor.init_modif()
406 self.treeParent.build_children()
407 self.treeParent.children[pos].select()
408 self.treeParent.children[pos].affichePanneau()
410 QMessageBox.critical( self.editor, "Erreur !",str(e))
412 def addComment( self, after=True ):
414 Ajoute un commentaire a l'interieur du JDC :
416 self.editor.init_modif()
421 return self.append_brother( COMMENT, pos )
423 def addParameters( self, after=True ):
425 Ajoute un parametre a l'interieur du JDC :
427 self.editor.init_modif()
428 if after: pos = 'after'
430 child=self.append_brother( PARAMETERS, pos )
436 Rend le noeud courant (self) selectionne et deselectionne
439 #print "select pour", self.item.nom
440 for item in self.tree.selectedItems() :
442 self.tree.setCurrentItem( self )
444 #------------------------------------------------------------------
445 # Methodes de creation et destruction de noeuds
446 # Certaines de ces methodes peuvent etre appelees depuis l'externe
447 #------------------------------------------------------------------
448 def append_brother(self,name,pos='after',plier=False):
450 Permet d'ajouter un objet frere a l'objet associe au noeud self
451 par defaut on l'ajoute immediatement apres
454 self.editor.init_modif()
456 from InterfaceQT4 import compojdc
457 if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos) : return 0
459 if self.treeParent != self.vraiParent :
460 index = self.vraiParent.children.index(self)
461 if pos == 'before': index = index
462 elif pos == 'after': index = index +1
463 return self.vraiParent.append_child(name,pos=index,plier=plier)
465 index = self.treeParent.children.index(self)
466 if pos == 'before': index = index
467 elif pos == 'after': index = index +1
469 print unicode(pos), tr(" n'est pas un index valide pour append_brother")
471 return self.treeParent.append_child(name,pos=index,plier=plier)
473 def verifiePosition(self,name,pos,aLaRacine=False):
474 if name not in self.editor.Classement_Commandes_Ds_Arbre : return True
475 indexName=self.editor.Classement_Commandes_Ds_Arbre.index(name)
477 etapes=self.item.get_jdc().etapes
478 if etapes == [] : return True
480 if aLaRacine == False :indexOu=etapes.index(self.item.object)
483 if pos=="after" : indexOu = indexOu+1
484 for e in etapes[:indexOu] :
486 if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
487 indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
488 if indexEtape > indexName :
489 comment=tr('le mot clef ')+name+tr(' doit etre insere avant ')+nom
490 QMessageBox.information( None,tr('insertion impossible'),comment, )
492 for e in etapes[indexOu:] :
494 if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
495 indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
496 if indexEtape < indexName :
497 comment=tr('le mot clef ')+name+tr(' doit etre insere apres ')+nom
498 QMessageBox.information( None,tr('insertion impossible'),comment, )
502 def append_child(self,name,pos=None,plier=False):
504 Methode pour ajouter un objet fils a l'objet associe au noeud self.
505 On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
506 ou en position intermediaire.
507 Si pos vaut None, on le place a la position du catalogue.
509 #print "************** append_child ",self.item.GetLabelText(), plier
512 self.editor.init_modif()
516 index = len(self.children)
517 elif type(pos) == types.IntType :
520 elif type(pos) == types.InstanceType:
521 # pos est un item. Il faut inserer name apres pos
522 index = self.item.get_index(pos) +1
523 elif type(name) == types.InstanceType:
524 index = self.item.get_index_child(name.nom)
526 index = self.item.get_index_child(name)
528 # si on essaye d inserer a la racine
529 if (isinstance(self.treeParent,JDCTree) and index==0) :
530 verifiePosition=self.verifiePosition(name,'first',aLaRacine=True)
531 if not verifiePosition : return 0
533 self.tree.inhibeExpand=True
534 obj=self.item.additem(name,index) # emet le signal 'add'
539 child=self.children[index]
540 if plier == True : child.setPlie()
541 else : child.setDeplie()
543 child=self.children[index]
544 self.tree.inhibeExpand=False
545 #print " fin append child"
551 self.editor.init_modif()
552 index = self.treeParent.children.index(self) - 1
553 if index < 0 : index =0
554 ret=self.treeParent.item.deplaceEntite(self.item.getObject())
558 Methode externe pour la destruction de l'objet associe au noeud
560 self.editor.init_modif()
561 index = self.vraiParent.children.index(self) - 1
562 if index < 0 : index =0
564 if self.item.nom == "VARIABLE" :
567 ret,commentaire=self.vraiParent.item.suppitem(self.item)
569 self.editor.affiche_infos(commentaire,Qt.red)
571 self.editor.affiche_infos(commentaire)
572 self.treeParent.build_children()
573 if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
574 else: toselect=self.treeParent
575 if recalcule : jdc.recalcule_etat_correlation()
577 if self.treeParent.childrenComplete :
578 notdeleted=self.treeParent.childrenComplete[index+1]
582 from InterfaceQT4 import compojdc
583 # cas ou on detruit dans l arbre sans affichage
584 if isinstance(self.treeParent,compojdc.Node) :
585 toselect.affichePanneau()
587 if self.treeParent.fenetre== None : return
588 #print "J appelle reaffiche de browser apres delete"
589 self.treeParent.fenetre.reaffiche(toselect)
591 def deleteMultiple(self,liste=()):
593 Methode externe pour la destruction d une liste de noeud
595 from InterfaceQT4 import compojdc
596 self.editor.init_modif()
601 while not(isinstance(jdc,compojdc.Node)):
604 if not( isinstance(noeud.treeParent, compojdc.Node)): continue
605 if noeud.item.nom == "VARIABLE" : recalcule=1
606 if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
607 if index < 0 : index =0
609 # Cas ou on détruit dans une ETape
611 parentPosition=self.treeParent
612 while not(isinstance(parentPosition, compojdc.Node)):
613 index=parentPosition.treeParent.children.index(parentPosition)
614 parentPosition=parentPosition.treeParent
617 noeud.treeParent.item.suppitem(noeud.item)
620 if recalcule : jdc.recalcule_etat_correlation()
621 try : toselect=parentPosition.children[index]
622 except : toselect=jdc
624 toselect.affichePanneau()
626 # #------------------------------------------------------------------
629 #print "onValid pour ", self.item.nom
630 if self.JESUISOFF==1 : return
631 if hasattr(self,'fenetre') and self.fenetre:
633 self.fenetre.setValide()
635 # print "onValid pour ", self.item.nom, self,'pb'
638 if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isvalid():
639 self.item.jdc.recalcule_etat_correlation()
640 if hasattr(self.item,'forceRecalcul'):
641 self.forceRecalculChildren(self.item.forceRecalcul)
642 self.editor.init_modif()
644 self.update_node_valid()
645 self.update_node_label()
646 self.update_node_texte()
648 def onAdd(self,object):
649 if self.JESUISOFF==1 : return
650 #print "onAdd pour ", self.item.nom, object.nom
651 self.editor.init_modif()
653 # PN -- non necessaire si item=jdc
654 if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
656 def onSupp(self,object):
657 if self.JESUISOFF==1 : return
658 #print "onSup pour ", self.item.nom, object.nom
659 self.editor.init_modif()
661 # PN -- non necessaire si item=jdc
662 if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
666 def update_node_valid(self):
667 """Cette methode remet a jour la validite du noeud (icone)
670 if monEnvQT5 : repIcon=self.appliEficas.repIcon
671 else : repIcon=QString(self.appliEficas.repIcon)
672 monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
673 self.setIcon(0,monIcone)
676 def update_node_label(self):
677 """ Met a jour le label du noeud """
678 #print "NODE update_node_label", self.item.GetLabelText()
679 labeltext,fonte,couleur = self.item.GetLabelText()
681 #self.setText(0, labeltext)
684 def update_node_label_in_blue(self):
685 if hasattr(self.appliEficas,'noeudColore'):
687 self.appliEficas.noeudColore.setForeground(0,Qt.black)
689 self.appliEficas.noeudColore.setTextColor( 0,Qt.black)
690 self.appliEficas.noeudColore.update_node_label()
692 self.setForeground(0,Qt.blue)
694 self.setTextColor( 0,Qt.blue )
695 labeltext,fonte,couleur = self.item.GetLabelText()
696 self.setText(0, labeltext)
697 self.appliEficas.noeudColore=self
699 def update_plusieurs_node_label_in_blue(self,liste):
700 if hasattr(self.appliEficas,'listeNoeudsColores'):
701 for noeud in self.appliEficas.listeNoeudsColores:
702 noeud.setTextColor( 0,Qt.black)
703 noeud.update_node_label()
704 self.appliEficas.listeNoeudsColores=[]
706 noeud.setTextColor( 0,Qt.blue )
707 labeltext,fonte,couleur = noeud.item.GetLabelText()
708 noeud.setText(0, labeltext)
709 self.appliEficas.listeNoeudsColores.append(noeud)
711 def update_node_texte_in_black(self):
712 """ Met a jour les noms des SD et valeurs des mots-cles """
713 self.setTextColor( 1,Qt.black )
714 value = self.item.GetText()
715 self.setText(1, value)
717 def update_node_texte(self):
718 """ Met a jour les noms des SD et valeurs des mots-cles """
719 value = self.item.GetText()
720 self.setText(1, value)
723 def update_node_texte_in_blue(self):
724 self.setTextColor( 1,Qt.blue )
725 value = self.item.GetText()
726 self.setText(1, value)
728 def update_nodes(self):
729 #print 'NODE update_nodes', self.item.GetLabelText()
730 self.build_children()
732 def update_valid(self) :
733 """Cette methode a pour but de mettre a jour la validite du noeud
734 et de propager la demande de mise a jour a son parent
736 #print "NODE update_valid", self.item.GetLabelText()
737 self.update_node_valid()
739 self.treeParent.update_valid()
743 def update_texte(self):
744 """ Met a jour les noms des SD et valeurs des mots-cles """
745 #print "NODE update_texte", self.item.GetLabelText()
746 self.update_node_texte()
747 if self.isExpanded() :
748 for child in self.children:
749 if child.isHidden() == false : child.update_texte()
752 def forceRecalculChildren(self,niveau):
753 if self.state=='recalcule' :
756 self.state='recalcule'
757 if hasattr(self.item,'object'):
758 self.item.object.state="modified"
759 for child in self.children:
760 if niveau > 0 : child.forceRecalculChildren(niveau - 1)
764 def doPaste(self,node_selected,pos='after'):
766 Déclenche la copie de l'objet item avec pour cible
767 l'objet passé en argument : node_selected
769 #print 'je passe dans doPaste'
770 objet_a_copier = self.item.get_copie_objet()
771 child=node_selected.doPasteCommande(objet_a_copier,pos)
774 def doPasteCommande(self,objet_a_copier,pos='after'):
776 Réalise la copie de l'objet passé en argument qui est nécessairement
782 child = self.append_brother(objet_a_copier,pos)
787 def doPastePremier(self,objet_a_copier):
789 Réalise la copie de l'objet passé en argument (objet_a_copier)
791 objet = objet_a_copier.item.get_copie_objet()
792 child = self.append_child(objet,pos='first')
795 def plieToutEtReafficheSaufItem(self, itemADeplier):
796 #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
797 self.inhibeExpand=True
798 from InterfaceQT4 import compojdc
799 if (isinstance(self, compojdc.Node)) :
800 self.affichePanneau()
801 self.inhibeExpand=False
803 self.editor.deplier = False
804 for item in self.children :
805 # il ne faut pas plier les blocs
806 from InterfaceQT4 import compobloc
807 if (isinstance(item,compobloc.Node)) : continue
809 if item==itemADeplier :
810 itemADeplier.setDeplie()
811 self.affichePanneau()
812 self.inhibeExpand=False
814 def plieToutEtReaffiche(self):
815 from InterfaceQT4 import compojdc
816 if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return
817 self.inhibeExpand=True
818 self.editor.deplier = False
819 for item in self.children :
820 # il ne faut pas plier les blocs
821 from InterfaceQT4 import compobloc
822 if (isinstance(item,compobloc.Node)) : continue
824 self.affichePanneau()
826 def deplieToutEtReaffiche(self):
827 self.editor.deplier = True
828 for item in self.children :
830 self.affichePanneau()
833 #print "je mets inhibeExpand a true dans setPlie"
834 #print "je suis dans plieTout", self.item.get_nom()
836 if self.fenetre == self.editor.fenetreCentraleAffichee and isinstance(self.treeParent,compojdc.Node):
838 self.tree.inhibeExpand=True
839 self.tree.collapseItem(self)
840 self.setPlieChildren()
841 self.tree.inhibeExpand=False
842 #print "je mets inhibeExpand a false dans setPlie"
845 # on ne plie pas au niveau 1
847 # for item in self.children :
848 # item.appartientAUnNoeudPlie=False
850 def setPlieChildren(self):
851 #print "dans setPlieChildren pour", self.item.nom
853 for c in self.children :
855 #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0]
856 c.appartientAUnNoeudPlie=True
858 #print "dans setPlieChildren plie", c.item.nom
861 # Pour les blocs et les motcles list
862 # on affiche un niveau de plus
863 from InterfaceQT4 import compobloc
864 from InterfaceQT4 import compomclist
865 if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) :
866 niveauPere=self.treeParent
867 while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) :
868 niveauPere=niveauPere.treeParent
869 for c in self.children :
870 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
871 #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0], "mis a la valeur ", niveauPere.appartientAUnNoeudPlie
874 # on affiche un niveau de plus
875 #if isinstance(self,compomclist.Node) :
876 #if isinstance(self,compobloc.Node) :
877 # niveauPere=self.treeParent
878 # while (isinstance(niveauPere,compobloc.Node)):
879 # niveauPere=niveauPere.treeParent
880 # for c in self.children :
881 # c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
884 #print "dans setPlieChildren pour", self.item.nom
885 #print "je mets inhibeExpand a true dans setDeplie"
886 self.tree.inhibeExpand=True
888 self.tree.expandItem(self)
889 self.setDeplieChildren()
890 self.tree.inhibeExpand=False
891 #print "je mets inhibeExpand a false dans setDePlie"
893 def setDeplieChildren(self):
894 #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.GetLabelText()
895 for c in self.children :
896 c.setDeplieChildren()
897 #print "dans setDeplieChildren ", c.item.nom
898 c.appartientAUnNoeudPlie=False
902 def selectAvant(self):
903 i=self.item.jdc.etapes.index(self.item.object)
905 cherche=self.item.jdc.etapes[i-1]
907 cherche=self.item.jdc.etapes[-1]
909 for i in self.tree.racine.children :
910 if i.item.object== cherche :
914 node.affichePanneau()
917 def selectApres(self):
918 i=self.item.jdc.etapes.index(self.item.object)
920 cherche=self.item.jdc.etapes[i+1]
922 cherche=self.item.jdc.etapes[0]
924 for i in self.tree.racine.children :
925 if i.item.object== cherche :
929 node.affichePanneau()
932 def ouvreLesNoeudsDsLArbre(self):
934 print "ds ouvreLesNoeudsDsLArbre ", self.item.nom
935 self.inhibeExpand = True
936 for i in range(self.childCount()):
937 self.child(i).inhibeExpand=True
938 self.child(i).setExpanded(True)
939 self.child(i).ouvreLesNoeudsDsLArbre()
940 self.child(i).inhibeExpand=False
941 self.inhibeExpand = False