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()
55 self.setReglesEtAide()
57 self.listeMCAAjouter=[]
58 self.dictMCVenantDesBlocs={}
59 if hasattr(self,'RBDeplie') : self.connect(self.RBDeplie,SIGNAL("clicked()"), self.Deplie)
60 if hasattr(self,'RBPlie') : self.connect(self.RBPlie,SIGNAL("clicked()"), self.Plie)
61 self.setAcceptDrops(True)
65 for fenetre in self.listeFocus:
66 if fenetre==None : return
67 if fenetre.node.item.isvalid() == 0 :
68 fenetre.prendLeFocus=1
74 def afficheMots(self):
75 for node in self.node.children:
76 if hasattr(self.node,'appartientAUnNoeudPlie') and self.node.appartientAUnNoeudPlie==True : return
77 #print "getPanel ds afficheMots " ,node.item.nom, node.getPanelGroupe
78 widget=node.getPanelGroupe(self,self.maCommande)
79 self.listeFocus.append(node.fenetre)
82 def calculOptionnel(self):
84 genea =self.obj.get_genealogie()
85 # Attention : les mots clefs listes (+sieurs fact )
86 # n ont pas toutes ces methodes
88 self.liste_mc=self.obj.get_liste_mc_ordonnee(genea,self.jdc.cata_ordonne_dico)
92 def afficheOptionnel(self):
93 liste=self.ajouteMCOptionnelDesBlocs()
94 #chercheOptionnel=self.parentQt
95 # Boucle necessaire pour les regroupements Adao
96 #while not( hasattr(chercheOptionnel,'monOptionnel')):
97 # chercheOptionnel=chercheOptionnel.parentQt
98 #self.monOptionnel=chercheOptionnel.monOptionnel
99 self.monOptionnel=self.editor.widgetOptionnel
100 self.monOptionnel.parentMC=self
101 self.monOptionnel.affiche(liste)
104 def ajouteMCOptionnelDesBlocs(self):
105 #print "Je passe dans ajouteMCOptionnelDesBlocs pour", self.node.item.nom
106 self.dictMCVenantDesBlocs={}
108 self.calculOptionnel()
110 for MC in self.liste_mc : self.dictMCVenantDesBlocs[MC]=self
111 while i < self.commandesLayout.count():
112 from monWidgetBloc import MonWidgetBloc
113 widget=self.commandesLayout.itemAt(i).widget()
115 if not(isinstance(widget,MonWidgetBloc)) : continue
116 widget.calculOptionnel()
117 listeW=widget.ajouteMCOptionnelDesBlocs()
118 for MC in widget.dictMCVenantDesBlocs.keys():
119 if MC in self.dictMCVenantDesBlocs.keys(): print "Pb Sur les MC"
120 else : self.dictMCVenantDesBlocs[MC]=widget.dictMCVenantDesBlocs[MC]
125 def reaffiche(self,nodeAVoir=None):
126 print "dans reaffiche de groupe.py", nodeAVoir
127 self.parentQt.reaffiche(nodeAVoir)
129 def recalculeListeMC(self,listeMC):
130 #print "pas si peu utile"
131 #on ajoute et on enleve
133 for name in listeMC :
134 nodeAEnlever=self.node.append_child(name)
135 if nodeAEnlever.item.isMCList():
136 nodeAEnlever=nodeAEnlever.children[-1]
137 listeNode.append(nodeAEnlever)
138 self.afficheOptionnel()
139 self.monOptionnel.affiche(self.liste_mc)
140 if len(listeNode) == 0 : return
141 if len(listeNode) == 1 :
142 listeNode[0].delete()
143 self.editor.affiche_infos("")
145 for noeud in listeNode:
146 noeud.treeParent.item.suppitem(noeud.item)
147 noeud.treeParent.build_children()
148 self.editor.affiche_infos("")
150 def ajoutMC(self,texteListeNom):
151 listeNom=texteListeNom.split("+")[1:]
154 if nom not in self.dictMCVenantDesBlocs.keys():
155 print "bizarre, bizarre"
156 self.editor.init_modif()
157 nouveau=self.node.append_child(nom)
159 self.editor.init_modif()
160 widget=self.dictMCVenantDesBlocs[nom]
161 nouveau=widget.node.append_child(nom)
162 if firstNode==None : firstNode=nouveau
163 if nouveau == None or nouveau == 0 :
164 self.editor.affiche_infos(str('insertion impossible a cet endroit pour '+nom),Qt.red)
166 print firstNode.fenetre
167 self.reaffiche(firstNode)
171 # self.node.setPlie()
175 self.reaffiche(self.node)
178 self.node.setDeplie()
179 self.reaffiche(self.node)