Salome HOME
pour traduction des mots-clefs
[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
40       self.repIcon=os.path.join( os.path.dirname(os.path.abspath(__file__)),'..','Editeur','icons')
41       iconeFile=os.path.join(self.repIcon,'lettreRblanc30.png')
42       icon = QIcon(iconeFile)
43       self.RBRegle.setIcon(icon)
44       self.RBRegle.setIconSize(QtCore.QSize(21, 31))
45
46       self.item = jdc_item
47       self.node = node
48       self.editor = editor
49       self.jdc  = self.item.object.get_jdc_root()
50       debutTitre=self.editor.titre
51       self.listeWidget=[]
52       self.dicoCmd={}
53       if self.editor.fichier != None : 
54           nouveauTitre=debutTitre+" "+str(os.path.basename(self.editor.fichier))
55       else :
56           nouveauTitre=debutTitre
57       self.editor.appliEficas.setWindowTitle(nouveauTitre)
58
59       #print self.node.tree
60
61       self.connect(self.RBalpha,SIGNAL("clicked()"),self.afficheAlpha)
62       self.connect(self.RBGroupe,SIGNAL("clicked()"),self.afficheGroupe)
63       self.connect(self.RBOrdre,SIGNAL("clicked()"),self.afficheOrdre)
64       self.connect(self.RBClear,SIGNAL("clicked()"),self.clearFiltre)
65       self.connect(self.RBCasse,SIGNAL("toggled(bool)"),self.ajouteRadioButtons)
66       if self.node.tree.item.get_regles() == () :
67          self.RBRegle.close()
68          self.labelRegle.close()
69       else : self.connect(self.RBRegle,SIGNAL("clicked()"),self.afficheRegle)
70
71       if self.editor.Ordre_Des_Commandes == None : self.RBOrdre.close()
72
73        
74       self.editor.labelCommentaire.setText("")
75       if self.editor.widgetOptionnel!= None : 
76          self.editor.widgetOptionnel.close()
77          self.editor.widgetOptionnel=None
78       self.name=None
79       self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.ajouteRadioButtons)
80
81       self.affiche_alpha=0
82       self.affiche_groupe=0
83       self.affiche_ordre=0
84       if self.editor.affiche=="alpha"  : 
85          self.affiche_alpha==1;  
86          self.RBalpha.setChecked(True);
87          self.afficheAlpha()
88       elif self.editor.affiche=="groupe" : 
89          self.affiche_groupe==1; 
90          self.RBGroupe.setChecked(True); 
91          self.afficheGroupe()
92       elif self.editor.affiche=="ordre"  : 
93          self.affiche_ordre==1;  
94          self.RBOrdre.setChecked(True);  
95          self.afficheOrdre()
96       if self.editor.code == "Adao" : self.frameAffichage.close()
97
98   def afficheRegle(self):
99       self.node.tree.AppelleBuildLBRegles()
100
101   def afficheAlpha(self):
102       self.affiche_alpha=1
103       self.affiche_groupe=0
104       self.affiche_ordre=0
105       self.ajouteRadioButtons()
106
107   def afficheGroupe(self):
108       self.affiche_alpha=0
109       self.affiche_groupe=1
110       self.affiche_ordre=0
111       self.ajouteRadioButtons()
112
113   def afficheOrdre(self):
114       self.affiche_alpha=0
115       self.affiche_groupe=0
116       self.affiche_ordre=1
117       self.ajouteRadioButtons()
118
119   def mouseDoubleClickEvent(self,event):
120       nodeCourrant=self.node.tree.currentItem()
121       if nodeCourrant==None: nodeCourrant=self.node.tree.racine
122       if self.name != None :
123          plier=self.editor.afficheCommandesPliees
124          if nodeCourrant==self.node : nouveau=self.node.append_child(self.name,'first',plier)
125          else : nouveau=nodeCourrant.append_brother(self.name,plier=plier)
126       else :
127          nouveau = 0
128       if nouveau == 0 : return # on n a pas insere le noeud
129       nouveau.setDeplie()
130       #if self.editor.afficheApresInsert==True : nouveau.plieToutEtReaffiche()
131       if self.editor.afficheApresInsert == True :
132            #if self.editor.affichePlie==True:  nouveau.plieToutEtReaffiche()
133            if self.editor.afficheCommandesPliees ==True:  nouveau.plieToutEtReaffiche()
134            else : nouveau.deplieToutEtReaffiche()
135            nouveau.fenetre.donnePremier()
136            #nouveau.deplieToutEtReaffiche()
137       else :
138            self.node.setSelected(False)
139            nouveau.setSelected(True)
140            self.node.tree.setCurrentItem(nouveau)
141       event.accept()
142       
143
144   def creeListeCommande(self,filtre):
145       listeGroupes,dictGroupes=self.jdc.get_groups()
146       sensibleALaCasse=self.RBCasse.isChecked()
147       if "CACHE" in dictGroupes.keys():
148          aExclure=dictGroupes["CACHE"]
149       else:
150          aExclure=()
151       listeACreer=[]
152       for l in self.jdc.get_liste_cmd():
153          if l not in aExclure : 
154             if sensibleALaCasse and (filtre != None and not filtre in l) : continue
155             if (not sensibleALaCasse) and filtre != None and (not filtre in l) and (not filtre.upper() in l) : continue
156             listeACreer.append(l)
157       return listeACreer
158
159   def ajouteRadioButtons(self):
160       filtre=str(self.LEFiltre.text())
161       if filtre==str("") : filtre=None
162       if hasattr(self,'buttonGroup') :
163          for b in self.buttonGroup.buttons():
164              self.buttonGroup.removeButton(b)
165              b.close()
166       else :
167          self.buttonGroup = QButtonGroup()
168       for w in self.listeWidget :
169          w.close()
170       self.listeWidget=[]
171       if self.affiche_alpha==1 :
172          liste=self.creeListeCommande(filtre)
173          for cmd in liste :
174            self.dicoCmd[tr(cmd)]=cmd
175            rbcmd=(QRadioButton(tr(cmd)))
176            self.buttonGroup.addButton(rbcmd)
177            self.commandesLayout.addWidget(rbcmd)
178            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
179            self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
180       elif  self.affiche_groupe==1 :
181          listeGroupes,dictGroupes=self.jdc.get_groups()
182          for grp in listeGroupes:
183            if grp == "CACHE" : continue
184            label=QLabel(self)
185            text=QString.fromUtf8('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
186            label.setText(text)
187            self.listeWidget.append(label)
188            aAjouter=1
189            sensibleALaCasse=self.RBCasse.isChecked()
190            for cmd in  dictGroupes[grp]:
191               if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
192               if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
193               if aAjouter == 1 :
194                  self.commandesLayout.addWidget(label)
195                  aAjouter=0
196               self.dicoCmd[tr(cmd)]=cmd
197               rbcmd=(QRadioButton(tr(cmd)))
198               self.buttonGroup.addButton(rbcmd)
199               self.commandesLayout.addWidget(rbcmd)
200               rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
201               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
202            label2=QLabel(self)
203            label2.setText(" ")
204            self.listeWidget.append(label2)
205            self.commandesLayout.addWidget(label2)
206       elif  self.affiche_ordre==1 :
207          listeFiltre=self.creeListeCommande(filtre)
208          liste=[]
209          if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
210          else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
211          for cmd in Ordre_Des_Commandes :
212             if cmd in listeFiltre :
213                  liste.append(cmd)
214          for cmd in liste :
215            self.dicoCmd[tr(cmd)]=cmd
216            rbcmd=(QRadioButton(tr(cmd)))
217            self.buttonGroup.addButton(rbcmd)
218            self.commandesLayout.addWidget(rbcmd)
219            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
220            self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
221
222      
223
224   def clearFiltre(self):
225       self.LEFiltre.setText("")
226       self.ajouteRadioButtons()
227
228   def rbClique(self,id):
229       self.name=self.dicoCmd[str(id.text().toLatin1())]
230       definitionEtape=getattr(self.jdc.cata[0],self.name)
231       commentaire=getattr(definitionEtape,self.jdc.lang)
232       try :
233         commentaire=getattr(definitionEtape,self.jdc.lang)
234       except :
235         try :
236            commentaire=getattr(definitionEtape,"ang")
237         except :
238            commentaire=""
239       self.editor.labelCommentaire.setText(commentaire)
240
241
242
243   def setValide(self):
244       #PNPN a priori pas d icone mais peut-etre a faire
245       pass