]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/groupe.py
Salome HOME
c1eb58ca4e9b0f6415da6d0b574a8228ff8dc00f
[tools/eficas.git] / InterfaceQT4 / groupe.py
1 # Copyright (C) 2007-2013   EDF R&D
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 # Modules Python
20 # Modules Eficas
21
22 from PyQt4  import *
23 from PyQt4.QtGui import *
24 from PyQt4.QtCore import *
25 from Extensions.i18n import tr
26 from gereIcones import FacultatifOuOptionnel
27 import Accas 
28
29     
30 # Import des panels
31
32 class Groupe(QtGui.QWidget,FacultatifOuOptionnel):
33   """
34   """
35   def __init__(self,node,editor,parentQt,definition,obj,niveau,commande=None):
36       QtGui.QWidget.__init__(self,None)
37       self.node=node
38       self.node.fenetre=self
39       #print "groupe : ",self.node.item.nom," ",self.node.fenetre
40       #self.setFocusPolicy(Qt.StrongFocus)
41       self.setupUi(self)
42       self.editor=editor
43       self.obj=obj
44       self.niveau=niveau
45       self.definition=definition
46       self.parentQt=parentQt
47       self.maCommande=commande
48       self.listeFocus=[]
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()
54       self.setRun()
55       self.setValide()
56       self.setReglesEtAide()
57       self.afficheMots()
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)
63       #self.donneFocus()
64      
65   def donneFocus(self):
66       for fenetre in self.listeFocus:
67           if fenetre==None : return
68           if fenetre.node.item.isvalid() == 0 :
69              fenetre.prendLeFocus=1
70              fenetre.hide()
71              fenetre.show()
72       
73
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
86
87        
88   def calculOptionnel(self):
89         self.liste_mc=[]
90         genea =self.obj.get_genealogie()
91         # Attention : les mots clefs listes (+sieurs fact )
92         # n ont pas toutes ces methodes
93         try :
94            self.liste_mc=self.obj.get_liste_mc_ordonnee(genea,self.jdc.cata_ordonne_dico)
95         except :
96            return
97         
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)
108            
109
110   def ajouteMCOptionnelDesBlocs(self):
111       #print "Je passe dans ajouteMCOptionnelDesBlocs pour", self.node.item.nom
112       self.dictMCVenantDesBlocs={}
113       i=0
114       self.calculOptionnel()
115       liste=self.liste_mc
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()
120           i=i+1
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]
127           liste=liste+listeW
128       return liste
129
130
131   def reaffiche(self,nodeAVoir=None):
132       #print "dans reaffiche de groupe.py", nodeAVoir
133       self.parentQt.reaffiche(nodeAVoir)
134
135   def recalculeListeMC(self,listeMC):
136       #print "pas si peu utile"
137       #on ajoute et on enleve
138       listeNode=[]
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("")
150          return
151       for noeud in listeNode:
152           noeud.treeParent.item.suppitem(noeud.item)
153       noeud.treeParent.build_children()
154       self.editor.affiche_infos("")
155
156   def ajoutMC(self,texteListeNom):
157       listeNom=texteListeNom.split("+")[1:]
158       firstNode=None
159       for nom in listeNom:
160         if nom not in self.dictMCVenantDesBlocs.keys():
161            #print "bizarre, bizarre"
162            self.editor.init_modif()
163            nouveau=self.node.append_child(nom)
164         else :
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)
172       if firstNode!=None and firstNode.item!=None :
173         firstNode.select()
174
175
176   def Plie(self):
177       self.node.setPlie()
178       self.reaffiche(self.node) 
179
180   def Deplie(self):
181       self.node.setDeplie()
182       self.reaffiche(self.node) 
183
184   def traiteClicSurLabel(self,texte):
185       if self.editor.code != "CARMELCND" : self.afficheOptionnel()
186