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):
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
48 self.appliEficas=self.editor.appliEficas
49 self.repIcon=self.appliEficas.repIcon
50 self.jdc=self.node.item.get_jdc()
53 self.setReglesEtAide()
55 self.listeMCAAjouter=[]
56 self.dictMCVenantDesBlocs={}
57 if hasattr(self,'RBDeplie') : self.connect(self.RBDeplie,SIGNAL("clicked()"), self.Deplie)
58 if hasattr(self,'RBPlie') : self.connect(self.RBPlie,SIGNAL("clicked()"), self.Plie)
59 self.setAcceptDrops(True)
63 for fenetre in self.listeFocus:
64 if fenetre==None : return
65 if fenetre.node.item.isvalid() == 0 :
66 fenetre.prendLeFocus=1
72 def afficheMots(self):
73 for node in self.node.children:
74 #if node in self.node.listeMCVenantDesBlocs : continue
75 # print "pas ", node.item.nom
77 if hasattr(self.node,'appartientAUnNoeudPlie') and self.node.appartientAUnNoeudPlie==True : return
78 else : widget=node.getPanelGroupe(self)
81 self.listeFocus.append(node.fenetre)
82 #print "fin afficheMots pou " ,self.node.item.nom
85 def calculOptionnel(self):
87 genea =self.obj.get_genealogie()
88 # Attention : les mots clefs listes (+sieurs fact )
89 # n ont pas toutes ces methodes
91 self.liste_mc=self.obj.get_liste_mc_ordonnee(genea,self.jdc.cata_ordonne_dico)
95 def afficheOptionnel(self):
96 liste=self.ajouteMCOptionnelDesBlocs()
97 #chercheOptionnel=self.parentQt
98 # Boucle necessaire pour les regroupements Adao
99 #while not( hasattr(chercheOptionnel,'monOptionnel')):
100 # chercheOptionnel=chercheOptionnel.parentQt
101 #self.monOptionnel=chercheOptionnel.monOptionnel
102 self.monOptionnel=self.editor.widgetOptionnel
103 self.monOptionnel.parentMC=self
104 self.monOptionnel.affiche(liste)
107 def ajouteMCOptionnelDesBlocs(self):
108 #print "Je passe dans ajouteMCOptionnelDesBlocs pour", self.node.item.nom
109 self.dictMCVenantDesBlocs={}
111 self.calculOptionnel()
113 for MC in self.liste_mc : self.dictMCVenantDesBlocs[MC]=self
114 while i < self.commandesLayout.count():
115 from monWidgetBloc import MonWidgetBloc
116 widget=self.commandesLayout.itemAt(i).widget()
118 if not(isinstance(widget,MonWidgetBloc)) : continue
119 widget.calculOptionnel()
120 listeW=widget.ajouteMCOptionnelDesBlocs()
121 for MC in widget.dictMCVenantDesBlocs.keys():
122 if MC in self.dictMCVenantDesBlocs.keys(): print "Pb Sur les MC"
123 else : self.dictMCVenantDesBlocs[MC]=widget.dictMCVenantDesBlocs[MC]
128 def reaffiche(self,nodeAVoir=None):
129 print "dans reaffiche ________________________", nodeAVoir
130 self.parentQt.reaffiche(nodeAVoir)
132 def recalculeListeMC(self,listeMC):
133 #print "pas si peu utile"
134 #on ajoute et on enleve
136 for name in listeMC :
137 nodeAEnlever=self.node.append_child(name)
138 if nodeAEnlever.item.isMCList():
139 nodeAEnlever=nodeAEnlever.children[-1]
140 listeNode.append(nodeAEnlever)
141 self.afficheOptionnel()
142 self.monOptionnel.affiche(self.liste_mc)
143 if len(listeNode) == 0 : return
144 if len(listeNode) == 1 :
145 listeNode[0].delete()
146 self.editor.affiche_infos("")
148 for noeud in listeNode:
149 noeud.treeParent.item.suppitem(noeud.item)
150 noeud.treeParent.build_children()
151 self.editor.affiche_infos("")
153 def ajoutMC(self,texteListeNom):
154 listeNom=texteListeNom.split("+")[1:]
157 if nom not in self.dictMCVenantDesBlocs.keys():
158 print "bizarre, bizarre"
159 self.editor.init_modif()
160 nouveau=self.node.append_child(nom)
162 self.editor.init_modif()
163 widget=self.dictMCVenantDesBlocs[nom]
164 nouveau=widget.node.append_child(nom)
165 if firstNode==None : firstNode=nouveau
166 if nouveau == None or nouveau == 0 :
167 self.editor.affiche_infos(str('insertion impossible a cet endroit pour '+nom),Qt.red)
168 self.reaffiche(firstNode)
177 self.node.setDeplie()