Salome HOME
carmel n a pas de mot clef optionnel
[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.setRun()
54       self.setValide()
55       self.setReglesEtAide()
56       self.afficheMots()
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)
62       #self.donneFocus()
63      
64   def donneFocus(self):
65       for fenetre in self.listeFocus:
66           if fenetre==None : return
67           if fenetre.node.item.isvalid() == 0 :
68              fenetre.prendLeFocus=1
69              fenetre.hide()
70              fenetre.show()
71       
72
73   def afficheMots(self):
74       #print "ds afficheMots ",self.node.item.nom
75       for node in self.node.children:
76            #print "afficheMots ",node," " ,node.item.nom, " ",node.plie ," ", node.appartientAUnNoeudPlie
77            # non return mais  continue car il faut tenir compte des blocs
78            if node.appartientAUnNoeudPlie==True : continue
79            #print "je suis apres le if pour ",node.item.nom
80            widget=node.getPanelGroupe(self,self.maCommande)
81            #print "widget pour ", node.item.nom, widget
82            self.listeFocus.append(node.fenetre)
83       #print "fin pour " , self.node.item.nom
84
85        
86   def calculOptionnel(self):
87         self.liste_mc=[]
88         genea =self.obj.get_genealogie()
89         # Attention : les mots clefs listes (+sieurs fact )
90         # n ont pas toutes ces methodes
91         try :
92            self.liste_mc=self.obj.get_liste_mc_ordonnee(genea,self.jdc.cata_ordonne_dico)
93         except :
94            return
95         
96   def afficheOptionnel(self):
97         liste=self.ajouteMCOptionnelDesBlocs()
98         #chercheOptionnel=self.parentQt
99         # Boucle necessaire pour les regroupements Adao
100         #while not( hasattr(chercheOptionnel,'monOptionnel')):
101         #    chercheOptionnel=chercheOptionnel.parentQt
102         #self.monOptionnel=chercheOptionnel.monOptionnel
103         self.monOptionnel=self.editor.widgetOptionnel
104         self.monOptionnel.parentMC=self
105         self.monOptionnel.affiche(liste)
106            
107
108   def ajouteMCOptionnelDesBlocs(self):
109       #print "Je passe dans ajouteMCOptionnelDesBlocs pour", self.node.item.nom
110       self.dictMCVenantDesBlocs={}
111       i=0
112       self.calculOptionnel()
113       liste=self.liste_mc
114       for MC in self.liste_mc : self.dictMCVenantDesBlocs[MC]=self
115       while i < self.commandesLayout.count():
116           from monWidgetBloc import MonWidgetBloc
117           widget=self.commandesLayout.itemAt(i).widget()
118           i=i+1
119           if not(isinstance(widget,MonWidgetBloc)) : continue
120           widget.calculOptionnel()
121           listeW=widget.ajouteMCOptionnelDesBlocs() 
122           for MC in widget.dictMCVenantDesBlocs.keys():
123               if MC in self.dictMCVenantDesBlocs.keys(): print "Pb Sur les MC" 
124               else : self.dictMCVenantDesBlocs[MC]=widget.dictMCVenantDesBlocs[MC]
125           liste=liste+listeW
126       return liste
127
128
129   def reaffiche(self,nodeAVoir=None):
130       #print "dans reaffiche de groupe.py", nodeAVoir
131       self.parentQt.reaffiche(nodeAVoir)
132
133   def recalculeListeMC(self,listeMC):
134       #print "pas si peu utile"
135       #on ajoute et on enleve
136       listeNode=[]
137       for name in listeMC :
138           nodeAEnlever=self.node.append_child(name)
139           if nodeAEnlever.item.isMCList(): 
140              nodeAEnlever=nodeAEnlever.children[-1]
141           listeNode.append(nodeAEnlever)
142       self.afficheOptionnel()
143       self.monOptionnel.affiche(self.liste_mc)
144       if len(listeNode) == 0 : return
145       if len(listeNode) == 1 : 
146          listeNode[0].delete()
147          self.editor.affiche_infos("")
148          return
149       for noeud in listeNode:
150           noeud.treeParent.item.suppitem(noeud.item)
151       noeud.treeParent.build_children()
152       self.editor.affiche_infos("")
153
154   def ajoutMC(self,texteListeNom):
155       listeNom=texteListeNom.split("+")[1:]
156       firstNode=None
157       for nom in listeNom:
158         if nom not in self.dictMCVenantDesBlocs.keys():
159            #print "bizarre, bizarre"
160            self.editor.init_modif()
161            nouveau=self.node.append_child(nom)
162         else :
163            self.editor.init_modif()
164            widget=self.dictMCVenantDesBlocs[nom]
165            nouveau=widget.node.append_child(nom)
166         if firstNode==None : firstNode=nouveau 
167         if nouveau == None or nouveau == 0  : 
168            self.editor.affiche_infos(str('insertion impossible a cet endroit pour '+nom),Qt.red)
169       self.reaffiche(firstNode)
170
171
172
173   def Plie(self):
174       self.node.setPlie()
175       self.reaffiche(self.node) 
176
177   def Deplie(self):
178       self.node.setDeplie()
179       self.reaffiche(self.node) 
180
181   def traiteClicSurLabel(self,texte):
182       if self.editor.code != "CARMELCND" : self.afficheOptionnel()
183