Salome HOME
bfa9ce9d3f39e9c1f0e2b937bb50175a0cdc1acb
[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.setPoubelle()
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              break
72       
73
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)
80
81        
82   def calculOptionnel(self):
83         self.liste_mc=[]
84         genea =self.obj.get_genealogie()
85         # Attention : les mots clefs listes (+sieurs fact )
86         # n ont pas toutes ces methodes
87         try :
88            self.liste_mc=self.obj.get_liste_mc_ordonnee(genea,self.jdc.cata_ordonne_dico)
89         except :
90            return
91         
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)
102            
103
104   def ajouteMCOptionnelDesBlocs(self):
105       #print "Je passe dans ajouteMCOptionnelDesBlocs pour", self.node.item.nom
106       self.dictMCVenantDesBlocs={}
107       i=0
108       self.calculOptionnel()
109       liste=self.liste_mc
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()
114           i=i+1
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]
121           liste=liste+listeW
122       return liste
123
124
125   def reaffiche(self,nodeAVoir=None):
126       print "dans reaffiche de groupe.py", nodeAVoir
127       self.parentQt.reaffiche(nodeAVoir)
128
129   def recalculeListeMC(self,listeMC):
130       #print "pas si peu utile"
131       #on ajoute et on enleve
132       listeNode=[]
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("")
144          return
145       for noeud in listeNode:
146           noeud.treeParent.item.suppitem(noeud.item)
147       noeud.treeParent.build_children()
148       self.editor.affiche_infos("")
149
150   def ajoutMC(self,texteListeNom):
151       listeNom=texteListeNom.split("+")[1:]
152       firstNode=None
153       for nom in listeNom:
154         if nom not in self.dictMCVenantDesBlocs.keys():
155            print "bizarre, bizarre"
156            self.editor.init_modif()
157            nouveau=self.node.append_child(nom)
158         else :
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)
165       print firstNode
166       print firstNode.fenetre
167       self.reaffiche(firstNode)
168
169
170   #def PlieTout(self):
171   #    self.node.setPlie()
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