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 node in self.node.listeMCVenantDesBlocs : continue
77 # print "pas ", node.item.nom
79 if hasattr(self.node,'appartientAUnNoeudPlie') and self.node.appartientAUnNoeudPlie==True : return
80 widget=node.getPanelGroupe(self,self.maCommande)
83 self.listeFocus.append(node.fenetre)
84 #print "fin afficheMots pou " ,self.node.item.nom
87 def calculOptionnel(self):
89 genea =self.obj.get_genealogie()
90 # Attention : les mots clefs listes (+sieurs fact )
91 # n ont pas toutes ces methodes
93 self.liste_mc=self.obj.get_liste_mc_ordonnee(genea,self.jdc.cata_ordonne_dico)
97 def afficheOptionnel(self):
98 liste=self.ajouteMCOptionnelDesBlocs()
99 #chercheOptionnel=self.parentQt
100 # Boucle necessaire pour les regroupements Adao
101 #while not( hasattr(chercheOptionnel,'monOptionnel')):
102 # chercheOptionnel=chercheOptionnel.parentQt
103 #self.monOptionnel=chercheOptionnel.monOptionnel
104 self.monOptionnel=self.editor.widgetOptionnel
105 self.monOptionnel.parentMC=self
106 self.monOptionnel.affiche(liste)
109 def ajouteMCOptionnelDesBlocs(self):
110 #print "Je passe dans ajouteMCOptionnelDesBlocs pour", self.node.item.nom
111 self.dictMCVenantDesBlocs={}
113 self.calculOptionnel()
115 for MC in self.liste_mc : self.dictMCVenantDesBlocs[MC]=self
116 while i < self.commandesLayout.count():
117 from monWidgetBloc import MonWidgetBloc
118 widget=self.commandesLayout.itemAt(i).widget()
120 if not(isinstance(widget,MonWidgetBloc)) : continue
121 widget.calculOptionnel()
122 listeW=widget.ajouteMCOptionnelDesBlocs()
123 for MC in widget.dictMCVenantDesBlocs.keys():
124 if MC in self.dictMCVenantDesBlocs.keys(): print "Pb Sur les MC"
125 else : self.dictMCVenantDesBlocs[MC]=widget.dictMCVenantDesBlocs[MC]
130 def reaffiche(self,nodeAVoir=None):
131 #print "dans reaffiche ________________________", nodeAVoir
132 self.parentQt.reaffiche(nodeAVoir)
134 def recalculeListeMC(self,listeMC):
135 #print "pas si peu utile"
136 #on ajoute et on enleve
138 for name in listeMC :
139 nodeAEnlever=self.node.append_child(name)
140 if nodeAEnlever.item.isMCList():
141 nodeAEnlever=nodeAEnlever.children[-1]
142 listeNode.append(nodeAEnlever)
143 self.afficheOptionnel()
144 self.monOptionnel.affiche(self.liste_mc)
145 if len(listeNode) == 0 : return
146 if len(listeNode) == 1 :
147 listeNode[0].delete()
148 self.editor.affiche_infos("")
150 for noeud in listeNode:
151 noeud.treeParent.item.suppitem(noeud.item)
152 noeud.treeParent.build_children()
153 self.editor.affiche_infos("")
155 def ajoutMC(self,texteListeNom):
156 listeNom=texteListeNom.split("+")[1:]
159 if nom not in self.dictMCVenantDesBlocs.keys():
160 print "bizarre, bizarre"
161 self.editor.init_modif()
162 nouveau=self.node.append_child(nom)
164 self.editor.init_modif()
165 widget=self.dictMCVenantDesBlocs[nom]
166 nouveau=widget.node.append_child(nom)
167 if firstNode==None : firstNode=nouveau
168 if nouveau == None or nouveau == 0 :
169 self.editor.affiche_infos(str('insertion impossible a cet endroit pour '+nom),Qt.red)
170 self.reaffiche(firstNode)
179 self.node.setDeplie()