1 # Copyright (C) 2007-2013 EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 from PyQt4.QtGui import *
24 from PyQt4.QtCore import *
25 from Extensions.i18n import tr
26 from gereIcones import FacultatifOuOptionnel
32 class Groupe(QtGui.QWidget,FacultatifOuOptionnel):
35 def __init__(self,node,editor,parentQt,definition,obj,niveau,commande=None):
36 QtGui.QWidget.__init__(self,None)
38 self.node.fenetre=self
39 #print "groupe : ",self.node.item.nom," ",self.node.fenetre
40 #self.setFocusPolicy(Qt.StrongFocus)
45 self.definition=definition
46 self.parentQt=parentQt
47 self.maCommande=commande
49 self.appliEficas=self.editor.appliEficas
50 self.repIcon=self.appliEficas.repIcon
51 self.jdc=self.node.item.get_jdc()
52 self.setIconePoubelle()
53 self.setIconesGenerales()
56 self.setReglesEtAide()
58 self.listeMCAAjouter=[]
59 self.dictMCVenantDesBlocs={}
60 if hasattr(self,'RBDeplie') : self.connect(self.RBDeplie,SIGNAL("clicked()"), self.Deplie)
61 if hasattr(self,'RBPlie') : self.connect(self.RBPlie,SIGNAL("clicked()"), self.Plie)
62 self.setAcceptDrops(True)
66 for fenetre in self.listeFocus:
67 if fenetre==None : return
68 if fenetre.node.item.isvalid() == 0 :
69 fenetre.prendLeFocus=1
74 def afficheMots(self):
75 #print "ds afficheMots ",self.node.item.nom
76 for node in self.node.children:
77 #if node.item.nom == "Background" :print "afficheMots ",node," " ,node.item.nom, " ",node.plie ," ", node.appartientAUnNoeudPlie,node.getPanelGroupe
78 #if node.item.nom == "BackgroundError" :print "afficheMots ",node," " ,node.item.nom, " ",node.plie ," ", node.appartientAUnNoeudPlie,node.getPanelGroupe
79 # non return mais continue car il faut tenir compte des blocs
80 if node.appartientAUnNoeudPlie==True : continue
81 #print "je suis apres le if pour ",node.item.nom
82 widget=node.getPanelGroupe(self,self.maCommande)
83 #print "widget pour ", node.item.nom, widget
84 self.listeFocus.append(node.fenetre)
85 #print "fin pour " , self.node.item.nom
88 def calculOptionnel(self):
90 genea =self.obj.get_genealogie()
91 # Attention : les mots clefs listes (+sieurs fact )
92 # n ont pas toutes ces methodes
94 self.liste_mc=self.obj.get_liste_mc_ordonnee(genea,self.jdc.cata_ordonne_dico)
98 def afficheOptionnel(self):
99 liste=self.ajouteMCOptionnelDesBlocs()
100 #chercheOptionnel=self.parentQt
101 # Boucle necessaire pour les regroupements Adao
102 #while not( hasattr(chercheOptionnel,'monOptionnel')):
103 # chercheOptionnel=chercheOptionnel.parentQt
104 #self.monOptionnel=chercheOptionnel.monOptionnel
105 self.monOptionnel=self.editor.widgetOptionnel
106 self.monOptionnel.parentMC=self
107 self.monOptionnel.affiche(liste)
110 def ajouteMCOptionnelDesBlocs(self):
111 #print "Je passe dans ajouteMCOptionnelDesBlocs pour", self.node.item.nom
112 self.dictMCVenantDesBlocs={}
114 self.calculOptionnel()
116 for MC in self.liste_mc : self.dictMCVenantDesBlocs[MC]=self
117 while i < self.commandesLayout.count():
118 from monWidgetBloc import MonWidgetBloc
119 widget=self.commandesLayout.itemAt(i).widget()
121 if not(isinstance(widget,MonWidgetBloc)) : continue
122 widget.calculOptionnel()
123 listeW=widget.ajouteMCOptionnelDesBlocs()
124 for MC in widget.dictMCVenantDesBlocs.keys():
125 if MC in self.dictMCVenantDesBlocs.keys(): print "Pb Sur les MC"
126 else : self.dictMCVenantDesBlocs[MC]=widget.dictMCVenantDesBlocs[MC]
131 def reaffiche(self,nodeAVoir=None):
132 #print "dans reaffiche de groupe.py", nodeAVoir
133 self.parentQt.reaffiche(nodeAVoir)
135 def recalculeListeMC(self,listeMC):
136 #print "pas si peu utile"
137 #on ajoute et on enleve
139 for name in listeMC :
140 nodeAEnlever=self.node.append_child(name)
141 if nodeAEnlever.item.isMCList():
142 nodeAEnlever=nodeAEnlever.children[-1]
143 listeNode.append(nodeAEnlever)
144 self.afficheOptionnel()
145 self.monOptionnel.affiche(self.liste_mc)
146 if len(listeNode) == 0 : return
147 if len(listeNode) == 1 :
148 listeNode[0].delete()
149 self.editor.affiche_infos("")
151 for noeud in listeNode:
152 noeud.treeParent.item.suppitem(noeud.item)
153 noeud.treeParent.build_children()
154 self.editor.affiche_infos("")
156 def ajoutMC(self,texteListeNom):
157 listeNom=texteListeNom.split("+")[1:]
160 if nom not in self.dictMCVenantDesBlocs.keys():
161 #print "bizarre, bizarre"
162 self.editor.init_modif()
163 nouveau=self.node.append_child(nom)
165 self.editor.init_modif()
166 widget=self.dictMCVenantDesBlocs[nom]
167 nouveau=widget.node.append_child(nom)
168 if firstNode==None : firstNode=nouveau
169 if nouveau == None or nouveau == 0 :
170 self.editor.affiche_infos(str('insertion impossible a cet endroit pour '+nom),Qt.red)
171 self.reaffiche(firstNode)
177 self.reaffiche(self.node)
180 self.node.setDeplie()
181 self.reaffiche(self.node)
183 def traiteClicSurLabel(self,texte):
184 if self.editor.code != "CARMELCND" : self.afficheOptionnel()