Salome HOME
onItem=Deplie
[tools/eficas.git] / InterfaceQT4 / monChoixCommande.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 desChoixCommandes import Ui_ChoixCommandes
23 from PyQt4  import *
24 from PyQt4.QtCore import *
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27 from Extensions.i18n import tr
28 import os
29
30     
31 # Import des panels
32
33 class MonChoixCommande(Ui_ChoixCommandes,QtGui.QWidget):
34   """
35   """
36   def __init__(self,node, jdc_item, editor):
37       QtGui.QWidget.__init__(self,None)
38       self.setupUi(self)
39       #self.labelIcone.setText('<img src="/local00/home/A96028/Install_EficasV1/KarineEficas/InterfaceQT4/loopOff.png">');
40
41       self.item = jdc_item
42       self.node = node
43       self.editor = editor
44       self.jdc  = self.item.object.get_jdc_root()
45       debutTitre=self.editor.titre
46       self.listeWidget=[]
47       if self.editor.fichier != None : 
48           nouveauTitre=debutTitre+" "+str(os.path.basename(self.editor.fichier))
49       else :
50           nouveauTitre=debutTitre
51       self.editor.appliEficas.setWindowTitle(nouveauTitre)
52
53       #print self.node.tree
54
55       self.connect(self.RBalpha,SIGNAL("clicked()"),self.afficheAlpha)
56       self.connect(self.RBGroupe,SIGNAL("clicked()"),self.afficheGroupe)
57       self.connect(self.RBOrdre,SIGNAL("clicked()"),self.afficheOrdre)
58       if self.node.tree.item.get_regles() == () :
59          self.RBRegle.close()
60          self.labelRegle.close()
61       else : self.connect(self.RBRegle,SIGNAL("clicked()"),self.afficheRegle)
62
63       if self.editor.Ordre_Des_Commandes == None : self.RBOrdre.close()
64
65        
66       self.editor.labelCommentaire.setText("")
67       if self.editor.widgetOptionnel!= None : 
68          self.editor.widgetOptionnel.close()
69          self.editor.widgetOptionnel=None
70       self.name=None
71       self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.AjouteRadioButton)
72
73       self.affiche_alpha=0
74       self.affiche_groupe=0
75       self.affiche_ordre=0
76       if self.editor.affiche=="alpha"  : 
77          self.affiche_alpha==1;  
78          self.RBalpha.setChecked(True);
79          self.afficheAlpha()
80       elif self.editor.affiche=="groupe" : 
81          self.affiche_groupe==1; 
82          self.RBGroupe.setChecked(True); 
83          self.afficheGroupe()
84       elif self.editor.affiche=="ordre"  : 
85          self.affiche_ordre==1;  
86          self.RBOrdre.setChecked(True);  
87          self.afficheOrdre()
88       if self.editor.code == "Adao" : self.frameAffichage.close()
89
90   def afficheRegle(self):
91       self.node.tree.AppelleBuildLBRegles()
92
93   def afficheAlpha(self):
94       self.affiche_alpha=1
95       self.affiche_groupe=0
96       self.affiche_ordre=0
97       self.AjouteRadioButton()
98
99   def afficheGroupe(self):
100       self.affiche_alpha=0
101       self.affiche_groupe=1
102       self.affiche_ordre=0
103       self.AjouteRadioButton()
104
105   def afficheOrdre(self):
106       self.affiche_alpha=0
107       self.affiche_groupe=0
108       self.affiche_ordre=1
109       self.AjouteRadioButton()
110
111   def mouseDoubleClickEvent(self,event):
112       nodeCourrant=self.node.tree.currentItem()
113       if nodeCourrant==None: nodeCourrant=self.node.tree.racine
114       if self.name != None :
115          plier=self.editor.afficheCommandesPliees
116          if nodeCourrant==self.node : nouveau=self.node.append_child(self.name,'first',plier)
117          else : nouveau=nodeCourrant.append_brother(self.name,plier=plier)
118       else :
119          nouveau = 0
120       if nouveau == 0 : return # on n a pas insere le noeud
121       nouveau.setDeplie()
122       #if self.editor.afficheApresInsert==True : nouveau.plieToutEtReaffiche()
123       if self.editor.afficheApresInsert == True :
124            #if self.editor.affichePlie==True:  nouveau.plieToutEtReaffiche()
125            if self.editor.afficheCommandesPliees ==True:  nouveau.plieToutEtReaffiche()
126            else : nouveau.deplieToutEtReaffiche()
127            nouveau.fenetre.donnePremier()
128            #nouveau.deplieToutEtReaffiche()
129       else :
130            self.node.setSelected(False)
131            nouveau.setSelected(True)
132            self.node.tree.setCurrentItem(nouveau)
133       event.accept()
134       
135
136   def CreeListeCommande(self,filtre):
137       listeGroupes,dictGroupes=self.jdc.get_groups()
138       if "CACHE" in dictGroupes.keys():
139          aExclure=dictGroupes["CACHE"]
140       else:
141          aExclure=()
142       listeACreer=[]
143       for l in self.jdc.get_liste_cmd():
144          if l not in aExclure : 
145             if filtre != None and not filtre in l : continue
146             listeACreer.append(l)
147       return listeACreer
148
149   def AjouteRadioButton(self):
150       filtre=str(self.LEFiltre.text())
151       if filtre==str("") : filtre=None
152       if hasattr(self,'buttonGroup') :
153          for b in self.buttonGroup.buttons():
154              self.buttonGroup.removeButton(b)
155              b.close()
156       else :
157          self.buttonGroup = QButtonGroup()
158       for w in self.listeWidget :
159          w.close()
160       self.listeWidget=[]
161       if self.affiche_alpha==1 :
162          liste=self.CreeListeCommande(filtre)
163          for cmd in liste :
164            rbcmd=(QRadioButton(tr(cmd)))
165            self.buttonGroup.addButton(rbcmd)
166            self.commandesLayout.addWidget(rbcmd)
167            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
168            self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
169       elif  self.affiche_groupe==1 :
170          listeGroupes,dictGroupes=self.jdc.get_groups()
171          for grp in listeGroupes:
172            if grp == "CACHE" : continue
173            label=QLabel(self)
174            text=QString.fromUtf8('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
175            label.setText(text)
176            self.listeWidget.append(label)
177            aAjouter=1
178            for cmd in  dictGroupes[grp]:
179               if filtre != None and not filtre in cmd : continue
180               if aAjouter == 1 :
181                  self.commandesLayout.addWidget(label)
182                  aAjouter=0
183               rbcmd=(QRadioButton(tr(cmd)))
184               self.buttonGroup.addButton(rbcmd)
185               self.commandesLayout.addWidget(rbcmd)
186               rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
187               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
188            label2=QLabel(self)
189            label2.setText(" ")
190            self.listeWidget.append(label2)
191            self.commandesLayout.addWidget(label2)
192       elif  self.affiche_ordre==1 :
193          listeFiltre=self.CreeListeCommande(filtre)
194          liste=[]
195          if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
196          else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
197          for cmd in Ordre_Des_Commandes :
198             if cmd in listeFiltre :
199                  liste.append(cmd)
200          for cmd in liste :
201            rbcmd=(QRadioButton(tr(cmd)))
202            self.buttonGroup.addButton(rbcmd)
203            self.commandesLayout.addWidget(rbcmd)
204            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
205            self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
206
207      
208   def LEfiltreReturnPressed(self):
209       self.AjouteRadioButton(filtre)
210
211
212   def rbClique(self,id):
213       self.name=str(id.text().toLatin1())
214       definitionEtape=getattr(self.jdc.cata[0],self.name)
215       commentaire=getattr(definitionEtape,self.jdc.lang)
216       try :
217         commentaire=getattr(definitionEtape,self.jdc.lang)
218       except :
219         try :
220            commentaire=getattr(definitionEtape,"ang")
221         except :
222            commentaire=""
223       self.editor.labelCommentaire.setText(commentaire)
224
225
226
227   def setValide(self):
228       #PNPN a priori pas d icone mais peut-etre a faire
229       pass