Salome HOME
ae530c3cf1624c5e47b637d3b683e7c005094c54
[tools/eficas.git] / InterfaceQT4 / browser.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import string,re
22 import types,sys,os
23 import traceback
24 import typeNode
25 import pdb
26 from PyQt4 import *
27 from PyQt4.QtGui  import *
28 from PyQt4.QtCore import *
29 from Extensions.i18n import tr
30 from monChoixCommande import MonChoixCommande
31
32 class JDCTree( QTreeWidget ):
33     def __init__( self, jdc_item, QWParent):        
34         #if hasattr(QWParent,'widgetTree') : 
35         self.editor        = QWParent
36         self.plie=False
37         if self.editor.widgetTree !=None  :
38            QTreeWidget.__init__(self, self.editor.widgetTree ) 
39            self.editor.verticalLayout_2.addWidget(self)
40            if self.editor.enteteQTree=='complet':
41                  self.headerItem().setText(0,  "Commande   ")
42                  self.headerItem().setText(1, "Concept/Valeur")
43            else :
44                  self.headerItem().setText(0,  "Commande   ")
45            self.setColumnWidth(0,200)
46            self.setExpandsOnDoubleClick(False)
47            self.setSelectionMode(3)
48         else :
49            QTreeWidget.__init__(self, None ) 
50         self.item          = jdc_item
51         self.tree          = self        
52         self.appliEficas   = self.editor.appliEficas
53         self.childrenComplete=[]
54         self.childrenIssusDesBlocs=[]
55         self.racine=self.item.itemNode(self,self.item)
56  
57         self.itemCourrant=None
58
59         self.connect(self, SIGNAL("itemClicked ( QTreeWidgetItem * ,int) "), self.handleOnItem)
60         self.connect(self, SIGNAL("itemCollapsed ( QTreeWidgetItem *) "), self.handleCollapsedItem)
61         self.connect(self, SIGNAL("itemExpanded ( QTreeWidgetItem *) "), self.handleExpandedItem)
62
63         #PNPNPN verifier dans quel cas on se trouve : affiche l arbre ou la commande
64         self.node_selected=self.racine
65         self.inhibeExpand=True
66         self.expandItem(self.racine)
67         self.inhibeExpand=False
68         #print "self.editor.afficheCommandesPliees", self.editor.afficheCommandesPliees
69         if self.racine.children !=[] :  
70
71             
72            if self.editor.afficheCommandesPliees : self.racine.children[0].plieToutEtReaffiche()
73            else : self.racine.children[0].deplieToutEtReaffiche()
74         
75
76            self.racine.children[0].fenetre.donnePremier()
77         else : self.racine.affichePanneau()
78         #PNPNPN
79         #pdb.set_trace()
80
81     def contextMenuEvent(self,event) :
82         #print "contextMenuEvent"
83         coord=event.globalPos()
84         item= self.currentItem()
85         self.handleContextMenu(item,coord)
86
87     def handleContextMenu(self,item,coord):
88         """
89         Private slot to show the context menu of the listview.
90         
91         @param itm the selected listview item (QListWidgetItem)
92         @param coord the position of the mouse pointer (QPoint)
93         Attention : existeMenu permet de savoir si un menu est associe a cet item
94         """
95         #print "handleContextMenu"
96         if item == None : return
97         if item.existeMenu == 0 : return
98         if item.menu == None:
99            item.createPopUpMenu()
100         if item.menu != None:
101            if item.item.get_nom() == "DISTRIBUTION" and item.item.isvalid() :
102               item.Graphe.setEnabled(1)
103            item.menu.exec_(coord)            
104             
105
106     def handleCollapsedItem(self,item):
107         #print "dans CollapsedItem", self.inhibeExpand  
108         if self.inhibeExpand == True : return
109         # On traite le cas de l item non selectionne
110         itemParent=item
111         while not (hasattr (itemParent,'getPanel2')) : 
112            itemParent=itemParent.treeParent 
113         if self.tree.node_selected != itemParent : 
114              item.setExpanded(False)
115              return
116
117         itemParent=item
118         item.setPlie()
119         item.plieToutEtReaffiche()
120
121     def handleExpandedItem(self,item):
122         #print "dans ExpandItem", self.inhibeExpand  
123         if self.inhibeExpand == True : return
124         #print "apres if"
125         itemParent=item
126         while not (hasattr (itemParent,'getPanel2')) : 
127            if itemParent.plie==True : itemParent.setDeplie()
128            itemParent=itemParent.treeParent 
129         #print "apres if"
130         if self.tree.node_selected != itemParent : 
131              item.setExpanded(True)
132              #print "je suis la"
133              return
134         item.deplieToutEtReaffiche()
135
136     def handleOnItem(self,item,int):
137         #if (len(self.selectedIndexes())!=2): return
138         #print "je passe dans handleOnItem"
139         self.inhibeExpand == True 
140         self.itemCourrant=item
141         itemParent=item
142         #print self.itemCourrant
143         while not (hasattr (itemParent,'getPanel2')) : 
144            if itemParent.plie==True : itemParent.setDeplie()
145            itemParent=itemParent.treeParent 
146         #print itemParent
147         #print itemParent.fenetre
148         #print self.editor.afficheCommandesPliees
149         if itemParent.fenetre != self.editor.fenetreCentraleAffichee : 
150             #print self.editor.afficheCommandesPliees
151             if self.editor.afficheCommandesPliees : itemParent.plieToutEtReaffiche()
152             else :                                  itemParent.affichePanneau()
153         if itemParent!=item and item.fenetre != None: item.fenetre.rendVisible()
154         #try :
155         if 1:
156            fr = item.item.get_fr()
157            if self.editor: self.editor.labelCommentaire.setText(unicode(fr))
158         #except:
159         else :
160             pass
161         self.inhibeExpand == False 
162         #print "je mets inhibeExpand a false handleOnItem"
163
164
165     def choisitPremier(self,name):
166         self.editor.layoutJDCCHOIX.removeWidget(self.racine.fenetre)
167         self.racine.fenetre.close()
168         new_node=self.racine.append_brother(name,'after')
169  
170 # type de noeud
171 COMMENT     = "COMMENTAIRE"
172 PARAMETERS  = "PARAMETRE"
173  
174 class JDCNode(QTreeWidgetItem):
175     def __init__( self, treeParent, item):
176         #print "creation d'un noeud : ", item, " ",item.nom,"", treeParent, self
177         self.a=0
178         self.item        = item
179         self.vraiParent  = treeParent
180         self.treeParent  = treeParent
181         self.tree        = self.treeParent.tree
182         self.editor      = self.treeParent.editor
183         self.appliEficas = treeParent.appliEficas
184         self.treeParent.childrenIssusDesBlocs=[]
185         self.childrenComplete=[]
186                         
187         from InterfaceQT4 import compocomm
188         from InterfaceQT4 import compoparam
189         if   (isinstance(self.item,compocomm.COMMTreeItem)) : name=tr("Commentaire")
190         elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=self.appliEficas.trUtf8(str(item.GetLabelText()[0]))
191         else:   name  = self.appliEficas.trUtf8(str(tr( item.nom))+" :")
192         value = self.appliEficas.trUtf8(str( item.GetText() ) )
193
194         mesColonnes=QStringList()
195         if self.editor.enteteQTree=='complet': mesColonnes <<  name << value
196         else : mesColonnes <<  name
197
198         if self.treeParent.plie==True :
199             self.plie        = True
200             self.appartientAUnNoeudPlie=True
201         else :
202             self.plie        = False
203             self.appartientAUnNoeudPlie = False
204         #print "self.plie", self.plie
205         #print "self.appartientAUnNoeudPlie", self.appartientAUnNoeudPlie
206         #print self.treeParent
207
208         ajoutAuParentduNoeud=0
209         from InterfaceQT4 import compobloc
210         from InterfaceQT4 import compomclist
211         while (isinstance(self.treeParent,compobloc.Node) or ( isinstance(self.treeParent,compomclist.Node) and self.treeParent.item.isMCList())) : 
212         #while (isinstance(self.treeParent,compobloc.Node)) :
213               self.treeParent=self.treeParent.treeParent
214               ajoutAuParentduNoeud=1
215         if ajoutAuParentduNoeud :
216            treeParent.childrenComplete.append(self)
217            self.treeParent.childrenIssusDesBlocs.append(self)
218         while (isinstance(self.treeParent,compobloc.Node)) : self.treeParent=self.treeParent.treeParent
219
220         #if isinstance(self,compobloc.Node) : 
221         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
222            QTreeWidgetItem.__init__(self,None,mesColonnes)
223         else :
224            QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
225            self.treeParent.childrenComplete.append(self)
226
227         self.setToolTip(0,QString(self.item.get_fr()))
228         self.setToolTip(1,QString(self.item.get_fr()))
229
230         repIcon=QString(self.appliEficas.repIcon)
231         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
232         self.setIcon(0,monIcone)
233
234         self.children = []
235         self.build_children()
236         self.menu=None
237         self.existeMenu=1
238
239         self.item.connect("valid",self.onValid,())
240         self.item.connect("supp" ,self.onSupp,())
241         self.item.connect("add"  ,self.onAdd,())
242         self.state=""
243         self.fenetre=None
244         try :
245           if self.item.getObject().isBLOC() : 
246                 self.setExpanded(True) 
247                 self.plie=False
248         except :
249           pass
250
251
252     def build_children(self,posInsertion=10000):
253         """ Construit la liste des enfants de self """
254         """ Se charge de remettre les noeuds Expanded dans le meme etat """
255         #print "*********** build_children ",self.item, self.item.GetLabelText()
256         
257         listeExpanded=[]
258         for item in self.childrenComplete :
259             #print dir(item)
260             #if item.isExpanded():
261             #   if self.childrenComplete.index(item) < posInsertion :
262             #      listeExpanded.append(self.childrenComplete.index(item))
263             #      print dir(item.item )
264             #   else :
265             #      listeExpanded.append( self.childrenComplete.index(item) +1)
266             self.detruit_les_noeuds_issus_de_blocs(item)
267             parent=item.treeParent
268             parent.removeChild(item)
269
270         #print listeExpanded
271         self.children = []
272         self.childrenComplete = []
273         sublist = self.item._GetSubList()
274         ind=0
275         for item in sublist :
276             nouvelItem=item.itemNode(self,item)
277             self.children.append(nouvelItem)
278             #print "         J ajoute ", nouvelItem ,nouvelItem.item.GetLabelText(),"dans" ,self.item.GetLabelText()
279             #print item
280             #if ind in listeExpanded : nouvelItem.setExpanded(1)
281  
282             #if ind in listeExpanded : print "plie=0"
283             #else                   : print "plie=1"
284             #if ind in listeExpanded : nouvelItem.plie=0
285             #else                   : nouvelItem.plie=1
286             #ind=ind+1
287
288         #print "*********** fin build_children ",self.item, self.item.GetLabelText()
289         
290     def chercheNoeudCorrespondant(self,objSimp):
291         sublist = self.item._GetSubList()
292         for node in self.childrenComplete:
293             if node.item.object==objSimp : return node
294         return None
295
296     def affichePanneau(self) :
297         print "dans affichePanneau appel getPanel2", self.item.GetLabelText()
298         if self.item.isactif(): 
299            itemParent=self
300            print self
301            print self.getPanel2
302            while not (hasattr (itemParent,'getPanel2')) : 
303                 itemParent=itemParent.treeParent 
304            if itemParent!=self : 
305               itemParent.affichePanneau()
306               return
307            print self.getPanel2
308            self.fenetre=self.getPanel2()
309         else:
310             from monInactifPanel import PanelInactif
311             self.fenetre = PanelInactif(self,self.editor)
312          
313         self.editor.widgetCentraleLayout.addWidget(self.fenetre)
314         #print "widgetCentraleLayout = ", self.editor.widgetCentraleLayout
315         #print "nouvelle fenetre ", self.fenetre, " associee a ", self
316
317         self.editor.anciennefenetre=self.editor.fenetreCentraleAffichee
318         #print "ancienne fenetre ", self.editor.anciennefenetre
319         self.editor.fenetreCentraleAffichee=self.fenetre
320         self.tree.node_selected= self
321
322         if self.editor.anciennefenetre != None : 
323            a=self.editor.anciennefenetre.close()
324            #print "je ferme ", self.editor.anciennefenetre
325
326         if self.editor.widgetTree !=None  : index=1
327         else : index=0
328
329         if self.editor.first :
330            self.editor.splitter.setSizes((400,1400,400))
331            if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
332         self.tree.inhibeExpand=True
333         self.tree.expandItem(self)
334         self.select()
335         self.tree.inhibeExpand=False
336         #print "fin de affichePanneau"
337         #print "______________________________"
338           
339
340     def createPopUpMenu(self):
341         #implemente dans les noeuds derives si necessaire
342         self.existeMenu = 0
343
344     def commentIt(self):
345         """
346         Cette methode a pour but de commentariser la commande pointee par self
347         """
348         # On traite par une exception le cas ou l'utilisateur final cherche a désactiver
349         # (commentariser) un commentaire.
350         try :
351             pos=self.treeParent.children.index(self)
352             commande_comment = self.item.get_objet_commentarise()
353             # On signale a l editeur du panel (le JDCDisplay) une modification
354             self.editor.init_modif()
355             self.treeParent.build_children()
356             self.treeParent.children[pos].select()
357             self.treeParent.children[pos].affichePanneau()
358         except Exception,e:
359             traceback.print_exc()
360             QMessageBox.critical( self.editor, "TOO BAD",str(e))
361         
362     def unCommentIt(self):
363         """
364         Realise la decommentarisation de self
365         """
366         try :
367             pos=self.treeParent.children.index(self)
368             commande,nom = self.item.uncomment()
369             self.editor.init_modif()
370             self.treeParent.build_children()
371             self.treeParent.children[pos].select()
372             self.treeParent.children[pos].affichePanneau()
373         except Exception,e:
374             QMessageBox.critical( self.editor, "Erreur !",str(e))
375         
376     def addComment( self, after=True ):
377         """
378         Ajoute un commentaire a l'interieur du JDC :
379         """
380         self.editor.init_modif()
381         if after:
382             pos = 'after'
383         else:
384             pos = 'before'
385         return self.append_brother( COMMENT, pos )
386                 
387     def addParameters( self, after=True ):
388         """
389         Ajoute un parametre a l'interieur du JDC :
390         """
391         self.editor.init_modif()
392         if after: pos = 'after'
393         else: pos = 'before'
394         child=self.append_brother( PARAMETERS, pos )
395         return  child
396     
397     
398     def select( self ):
399         """
400         Rend le noeud courant (self) selectionne et deselectionne
401         tous les autres
402         """        
403         #print "je suis sur select"
404         for item in self.tree.selectedItems() :
405             item.setSelected(0)
406         self.setSelected( True )    
407         #self.setExpanded( True )    
408         self.tree.setCurrentItem( self )    
409         self.tree.node_selected= self
410                                
411     #------------------------------------------------------------------
412     # Methodes de creation et destruction de noeuds
413     # Certaines de ces methodes peuvent etre appelees depuis l'externe
414     #------------------------------------------------------------------
415     def append_brother(self,name,pos='after',plier=False):
416         """
417         Permet d'ajouter un objet frere a l'objet associe au noeud self
418         par defaut on l'ajoute immediatement apres 
419         Methode externe
420         """
421         self.editor.init_modif()
422
423         verifiePosition=self.verifiePosition(name,pos)
424         if not verifiePosition : return 0
425         
426         index = self.treeParent.children.index(self)
427         if   pos == 'before': index = index
428         elif pos == 'after': index = index +1
429         else:
430             print unicode(pos), tr("  n'est pas un index valide pour append_brother")
431             return 0
432         return self.treeParent.append_child(name,pos=index,plier=plier)
433
434     def verifiePosition(self,name,pos):
435         from InterfaceQT4 import compojdc
436         if not (isinstance(self.treeParent, compojdc.Node)) : return True
437         if name not in self.editor.Classement_Commandes_Ds_Arbre : return True
438         indexName=self.editor.Classement_Commandes_Ds_Arbre.index(name)
439
440         etapes=self.item.jdc.etapes
441         if etapes == [] : return True
442
443         indexOu=etapes.index(self.item.object)
444         if pos=="after" : indexOu = indexOu+1
445         print self.editor.Classement_Commandes_Ds_Arbre
446         print indexOu
447         print indexName
448         print name
449         print etapes
450         for e in etapes[:indexOu] :
451             nom=e.nom
452             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
453             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
454             if indexEtape > indexName :
455                comment=tr('le mot clef ')+name+tr(' doit etre insere avant ')+nom
456                QMessageBox.information( None,tr('insertion impossible'),comment, )
457                return False
458         for e in etapes[indexOu:] :
459             nom=e.nom
460             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
461             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
462             if indexEtape < indexName :
463                comment=tr('le mot clef ')+name+tr(' doit etre insere apres ')+nom
464                QMessageBox.information( None,tr('insertion impossible'),comment, )
465                return False
466         return True
467
468     def append_child(self,name,pos=None,plier=False):
469         """
470            Methode pour ajouter un objet fils a l'objet associe au noeud self.
471            On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
472            ou en position intermediaire.
473            Si pos vaut None, on le place a la position du catalogue.
474         """
475         #print "************** append_child ",self.item.GetLabelText(), plier
476         self.editor.init_modif()
477         if pos == 'first':
478             index = 0
479         elif pos == 'last':
480             index = len(self.children)
481         elif type(pos) == types.IntType :
482             # position fixee
483             index = pos
484         elif type(pos) == types.InstanceType:
485             # pos est un item. Il faut inserer name apres pos
486             index = self.item.get_index(pos) +1
487         elif type(name) == types.InstanceType:
488             index = self.item.get_index_child(name.nom)
489         else:
490             index = self.item.get_index_child(name)
491         self.tree.inhibeExpand=True
492         obj=self.item.additem(name,index) #CS_pbruno emet le signal 'add'
493         if obj is None:obj=0
494         if obj == 0:return 0
495         #try :
496         #  old_obj = self.item.object.get_child(name.nom,restreint = 'oui')
497         #  child=old_obj[-1]
498         #  if plier : child.plieToutEtReaffiche()
499         #  else     : child.affichePanneau() 
500         #  print "dans le 1er Try"
501         #else :
502         #except:
503           # Souci pour gerer les copies des AFFE d'une commande à l autre
504         #  try :
505         #     child=self.children[index]
506         #     if plier == True : child.setPlie()
507         #     else             : child.setDeplie() 
508         #     print "dans le 2nd Try"
509         #  except :
510         #     child=self.children[index]
511         #     print "dans le except"
512         try :
513         #if 1:
514            child=self.children[index]
515            if plier == True : child.setPlie()
516            else             : child.setDeplie() 
517         except :
518            child=self.children[index]
519            #print "dans le except"
520         self.tree.inhibeExpand=False
521         return child
522
523     def deplace(self):
524         self.editor.init_modif()
525         index = self.treeParent.children.index(self) - 1 
526         if index < 0 : index =0
527         ret=self.treeParent.item.deplaceEntite(self.item.getObject())
528
529     def delete(self):
530         """ 
531             Methode externe pour la destruction de l'objet associe au noeud
532         """
533         self.editor.init_modif()
534         index = self.vraiParent.children.index(self) - 1 
535         if index < 0 : index =0
536         recalcule=0
537         if self.item.nom == "VARIABLE" :
538            recalcule=1
539            jdc=self.item.jdc
540         ret=self.vraiParent.item.suppitem(self.item)
541         self.treeParent.build_children()
542         if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
543         else: toselect=self.treeParent
544         if recalcule : jdc.recalcule_etat_correlation()
545         from InterfaceQT4 import compojdc
546         # cas ou on detruit dans l arbre sans affichage
547         if isinstance(self.treeParent,compojdc.Node) : 
548            toselect.affichePanneau()
549         else :
550            if self.treeParent.fenetre== None : return
551            #print "J appelle reaffiche de browser apres delete"
552            self.treeParent.fenetre.reaffiche(toselect)
553
554     def deleteMultiple(self,liste=()):
555         """ 
556             Methode externe pour la destruction d une liste de noeud
557         """
558         from InterfaceQT4 import compojdc 
559         self.editor.init_modif()
560         index=9999
561         recalcule=0
562         jdc=self.treeParent
563         parentPosition=jdc
564         while not(isinstance(jdc,compojdc.Node)):
565               jdc=jdc.treeParent
566         for noeud in liste :
567             if not( isinstance(noeud.treeParent, compojdc.Node)): continue
568             if noeud.item.nom == "VARIABLE" : recalcule=1
569             if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
570         if index < 0 : index =0
571
572         # Cas ou on détruit dans une ETape
573         if index == 9999 : 
574               parentPosition=self.treeParent
575               while not(isinstance(parentPosition, compojdc.Node)):
576                  index=parentPosition.treeParent.children.index(parentPosition)
577                  parentPosition=parentPosition.treeParent
578
579         for noeud in liste:
580             noeud.treeParent.item.suppitem(noeud.item)
581
582         jdc.build_children()
583         if recalcule : jdc.recalcule_etat_correlation()
584         try    : toselect=parentPosition.children[index]
585         except : toselect=jdc
586         toselect.select()
587         toselect.affichePanneau()
588 #        
589 #    #------------------------------------------------------------------
590     def onValid(self):        
591
592         #print "onValid pour ", self.item.nom
593         if hasattr(self,'fenetre') and self.fenetre: 
594            self.fenetre.setValide()
595         if self.item.nom == "VARIABLE" and self.item.isvalid():
596            self.item.jdc.recalcule_etat_correlation()
597         if hasattr(self.item,'forceRecalcul'):
598            self.forceRecalculChildren(self.item.forceRecalcul)
599         self.editor.init_modif()
600         
601         self.update_node_valid()
602         self.update_node_label()
603         self.update_node_texte()
604
605     def onAdd(self,object):
606         #print "onAdd pour ", self.item.nom
607         self.editor.init_modif()
608         self.update_nodes()
609         #print "dans onAdd" ,self.item 
610         # PN -- non necessaire si item=jdc
611         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
612  
613     def onSupp(self,object):
614         #print "onSupp pour ", self.item.nom
615         self.editor.init_modif()
616         self.update_nodes()
617         # PN -- non necessaire si item=jdc
618         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
619          
620     def detruit_les_noeuds_issus_de_blocs(self,bloc):
621         from InterfaceQT4 import compobloc
622         if (isinstance(bloc,compobloc.Node)) :
623            for node in bloc.childrenComplete :
624                self.detruit_les_noeuds_issus_de_blocs(node)
625                parent=node.treeParent
626                #print "je detruit " , node.item.GetLabelText()
627                parent.removeChild(node)
628
629     def update_node_valid(self):
630         """Cette methode remet a jour la validite du noeud (icone)
631            Elle appelle isvalid
632         """
633         repIcon=QString(self.appliEficas.repIcon)
634         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
635         self.setIcon(0,monIcone)
636
637
638     def update_node_label(self):
639         """ Met a jour le label du noeud """
640         #print "NODE update_node_label", self.item.GetLabelText()
641         labeltext,fonte,couleur = self.item.GetLabelText()
642         # PNPN a reflechir
643         #self.setText(0, labeltext)        
644     
645     
646     def update_node_label_in_blue(self):
647         if hasattr(self.appliEficas,'noeudColore'):
648            self.appliEficas.noeudColore.setTextColor( 0,Qt.black)
649            self.appliEficas.noeudColore.update_node_label()
650         self.setTextColor( 0,Qt.blue )
651         labeltext,fonte,couleur = self.item.GetLabelText()
652         self.setText(0, labeltext)        
653         self.appliEficas.noeudColore=self
654
655     def update_plusieurs_node_label_in_blue(self,liste):
656         if hasattr(self.appliEficas,'listeNoeudsColores'):
657            for noeud in self.appliEficas.listeNoeudsColores:
658                noeud.setTextColor( 0,Qt.black)
659                noeud.update_node_label()
660         self.appliEficas.listeNoeudsColores=[]
661         for noeud in liste :
662             noeud.setTextColor( 0,Qt.blue )
663             labeltext,fonte,couleur = noeud.item.GetLabelText()
664             noeud.setText(0, labeltext)        
665             self.appliEficas.listeNoeudsColores.append(noeud)
666
667     def update_node_texte_in_black(self):
668         """ Met a jour les noms des SD et valeurs des mots-cles """
669         self.setTextColor( 1,Qt.black )
670         value = self.item.GetText()
671         self.setText(1, value)
672
673     def update_node_texte(self):
674         """ Met a jour les noms des SD et valeurs des mots-cles """
675         value = self.item.GetText()
676         self.setText(1, value)
677
678     def update_node_texte_in_blue(self):
679         self.setTextColor( 1,Qt.blue )
680         value = self.item.GetText()
681         self.setText(1, value)
682
683     def update_nodes(self):
684         #print 'NODE update_nodes', self.item.GetLabelText()
685         self.build_children()
686
687     def update_valid(self) :
688         """Cette methode a pour but de mettre a jour la validite du noeud
689            et de propager la demande de mise a jour a son parent
690         """
691         #print "NODE update_valid", self.item.GetLabelText()
692         self.update_node_valid()
693         try :
694           self.treeParent.update_valid()
695         except:
696           pass
697             
698     def update_texte(self):
699         """ Met a jour les noms des SD et valeurs des mots-cles """
700         #print "NODE update_texte", self.item.GetLabelText()
701         self.update_node_texte()
702         if self.isExpanded() :
703             for child in self.children:
704                 if child.isHidden() == false : child.update_texte()
705
706
707     def forceRecalculChildren(self,niveau):
708         if self.state=='recalcule' : 
709            self.state=""
710            return
711         self.state='recalcule'
712         if hasattr(self.item,'object'):
713            self.item.object.state="modified"
714         for child in self.children:
715            if niveau > 0 : child.forceRecalculChildren(niveau - 1)
716               
717         
718
719     def doPaste(self,node_selected,pos='after'):
720         """
721             Déclenche la copie de l'objet item avec pour cible
722             l'objet passé en argument : node_selected
723         """
724         #print 'je passe dans doPaste'
725         objet_a_copier = self.item.get_copie_objet()
726         child=node_selected.doPasteCommande(objet_a_copier,pos)
727         return child
728
729     def doPasteCommande(self,objet_a_copier,pos='after'):
730         """
731           Réalise la copie de l'objet passé en argument qui est nécessairement
732           une commande
733         """
734         child=None
735         try :
736           child = self.append_brother(objet_a_copier,pos)
737         except :
738            pass
739         return child
740
741     def doPastePremier(self,objet_a_copier):
742         """
743            Réalise la copie de l'objet passé en argument (objet_a_copier)
744         """
745         objet = objet_a_copier.item.get_copie_objet()
746         child = self.append_child(objet,pos='first')
747         return child
748
749
750     def plieToutEtReaffiche(self):
751         print "je suis dans plieToutEtReaffiche", self.item.get_nom()
752         self.editor.deplier = False
753         for item in self.children :
754             item.setPlie()
755         self.affichePanneau()
756
757     def deplieToutEtReaffiche(self):
758         self.editor.deplier = True
759         for item in self.children :
760             item.setDeplie()
761         self.affichePanneau()
762
763     def setPlie(self):
764         #print "je mets inhibeExpand a true dans setPlie"
765         #print "je suis dans plieTout", self.item.get_nom()
766         import compojdc
767         if self.fenetre == self.editor.fenetreCentraleAffichee  and isinstance(self.treeParent,compojdc.Node): 
768            return
769         self.tree.inhibeExpand=True
770         self.tree.collapseItem(self)
771         self.setPlieChildren()
772         self.tree.inhibeExpand=False
773         #print "je mets inhibeExpand a false dans setPlie"
774
775
776         # on ne plie pas au niveau 1
777         #   self.plie=False
778         #   for item in self.children :
779         #       item.appartientAUnNoeudPlie=False
780
781     def setPlieChildren(self):
782         self.plie=True
783         for c in self.children :
784             c.setPlieChildren()
785             #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0]
786             c.appartientAUnNoeudPlie=True
787             c.plie=True
788             c.setExpanded(False)
789
790         # Pour les blocs et les motcles list
791         # on affiche un niveau de plus
792         from InterfaceQT4 import compobloc
793         from InterfaceQT4 import compomclist
794         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
795             niveauPere=self.treeParent
796             while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) : 
797                niveauPere=niveauPere.treeParent
798             for c in self.children :
799                 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
800                 c.setExpanded(False)
801
802         # on affiche un niveau de plus
803         #if isinstance(self,compomclist.Node)  : 
804         #if isinstance(self,compobloc.Node)  : 
805         #    niveauPere=self.treeParent
806         #    while (isinstance(niveauPere,compobloc.Node)):
807         #       niveauPere=niveauPere.treeParent
808         #    for c in self.children :
809         #        c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
810
811     def setDeplie(self):
812         #print "je mets inhibeExpand a true dans setDeplie"
813         self.tree.inhibeExpand=True
814         self.plie=False
815         self.tree.expandItem(self)
816         self.setDeplieChildren()
817         self.tree.inhibeExpand=False
818         #print "je mets inhibeExpand a false dans setDePlie"
819
820     def setDeplieChildren(self):
821         #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.GetLabelText()
822         for c in self.children :
823             c.setDeplieChildren()
824             #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", c.item.GetLabelText()
825             c.appartientAUnNoeudPlie=False
826             c.setExpanded(True)
827             c.plie=False
828        
829     def selectAvant(self):
830         i=self.item.jdc.etapes.index(self.item.object)
831         try :
832            cherche=self.item.jdc.etapes[i-1]
833         except :
834            cherche=self.item.jdc.etapes[-1]
835         node=None
836         for i in self.tree.racine.children :
837             if i.item.object== cherche  : 
838                node=i
839                break
840         if node : node.affichePanneau()
841
842     def selectApres(self):
843         i=self.item.jdc.etapes.index(self.item.object)
844         try :
845            cherche=self.item.jdc.etapes[i+1]
846         except :
847            cherche=self.item.jdc.etapes[0]
848         node=None
849         for i in self.tree.racine.children :
850             if i.item.object== cherche  : 
851                node=i
852                break
853         if node : node.affichePanneau()