Salome HOME
:: dans le label
[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 __future__ import absolute_import
23 try :
24    from builtins import str
25 except : pass
26
27 from desChoixCommandes import Ui_ChoixCommandes
28 from PyQt5.QtWidgets import QWidget, QAction ,QButtonGroup, QRadioButton, QLabel , QPushButton, QSpacerItem, QSizePolicy, QGridLayout
29 from PyQt5.QtGui  import QIcon, QPixmap
30 from PyQt5.QtCore import QSize, QRect
31
32 from Extensions.i18n import tr
33 import os
34
35     
36 # Import des panels
37
38 class MonChoixCommande(Ui_ChoixCommandes,QWidget):
39   """
40   """
41   def __init__(self,node, jdc_item, editor):
42       QWidget.__init__(self,None)
43       self.setupUi(self)
44
45       self.repIcon=os.path.join( os.path.dirname(os.path.abspath(__file__)),'..','Editeur','icons')
46       iconeFile=os.path.join(self.repIcon,'lettreRblanc30.png')
47       icon = QIcon(iconeFile)
48       self.RBRegle.setIcon(icon)
49       self.RBRegle.setIconSize(QSize(21, 31))
50
51       self.item = jdc_item
52       self.node = node
53       self.editor = editor
54       self.jdc  = self.item.object.get_jdc_root()
55       debutTitre=self.editor.titre
56       self.listeWidget=[]
57       self.dicoCmd={}
58       if self.editor.fichier != None : 
59           nouveauTitre=debutTitre+" "+str(os.path.basename(self.editor.fichier))
60       else :
61           nouveauTitre=debutTitre
62       self.editor.appliEficas.setWindowTitle(nouveauTitre)
63
64
65       self.RBalpha.clicked.connect(self.afficheAlpha)
66       self.RBGroupe.clicked.connect(self.afficheGroupe)
67       self.RBOrdre.clicked.connect(self.afficheOrdre)
68       self.RBClear.clicked.connect(self.clearFiltre)
69       self.RBCasse.toggled.connect(self.ajouteRadioButtons)
70       self.LEFiltre.returnPressed.connect(self.ajouteRadioButtons)
71       self.LEFiltre.textChanged.connect(self.ajouteRadioButtons)
72
73       if self.node.tree.item.get_regles() == () :
74          self.RBRegle.close()
75          self.labelRegle.close()
76       else : 
77         self.RBRegle.clicked.connect(self.afficheRegle)
78
79       if self.editor.Ordre_Des_Commandes == None : self.RBOrdre.close()
80
81        
82       #self.editor.labelCommentaire.setText("")
83       if self.editor.widgetOptionnel!= None : 
84          self.editor.fermeOptionnel()
85          self.editor.widgetOptionnel=None
86       self.name=None
87
88       self.affiche_alpha=0
89       self.affiche_groupe=0
90       self.affiche_ordre=0
91       if self.editor.affiche=="alpha"  : 
92          self.affiche_alpha==1;  
93          self.RBalpha.setChecked(True);
94          self.afficheAlpha()
95       elif self.editor.affiche=="groupe" : 
96          self.affiche_groupe==1; 
97          self.RBGroupe.setChecked(True); 
98          self.afficheGroupe()
99       elif self.editor.affiche=="ordre"  : 
100          self.affiche_ordre==1;  
101          self.RBOrdre.setChecked(True);  
102          self.afficheOrdre()
103       if self.editor.closeFrameRechercheCommande == True : self.frameAffichage.close()
104
105       if self.editor.widgetTree != None : self.editor.restoreSplitterSizes(2) 
106       else: self.editor.restoreSplitterSizes(3)
107
108   def afficheRegle(self):
109       self.node.tree.AppelleBuildLBRegles()
110
111   def afficheAlpha(self):
112       self.affiche_alpha=1
113       self.affiche_groupe=0
114       self.affiche_ordre=0
115       self.ajouteRadioButtons()
116
117   def afficheGroupe(self):
118       self.affiche_alpha=0
119       self.affiche_groupe=1
120       self.affiche_ordre=0
121       self.ajouteRadioButtons()
122
123   def afficheOrdre(self):
124       self.affiche_alpha=0
125       self.affiche_groupe=0
126       self.affiche_ordre=1
127       self.ajouteRadioButtons()
128
129   def insereNoeudApresClick(self,event):
130       #print self.editor.Classement_Commandes_Ds_Arbre
131       #if self.editor.Classement_Commandes_Ds_Arbre!= () : self.chercheOu()
132       #print ('dans insereNoeudApresClick')
133       nodeCourrant=self.node.tree.currentItem()
134       if nodeCourrant==None: nodeCourrant=self.node.tree.racine
135       if self.name != None :
136          plier=self.editor.afficheCommandesPliees
137          if nodeCourrant==self.node : nouveau=self.node.append_child(self.name,'first',plier)
138          else : nouveau=nodeCourrant.append_brother(self.name,plier=plier)
139       else :
140          nouveau = 0
141       if nouveau == 0 : return # on n a pas insere le noeud
142       nouveau.setDeplie()
143       #if self.editor.afficheApresInsert==True : nouveau.plieToutEtReaffiche()
144       if self.editor.afficheApresInsert == True :
145            #if self.editor.affichePlie==True:  nouveau.plieToutEtReaffiche()
146            if self.editor.afficheCommandesPliees ==True:  nouveau.plieToutEtReaffiche()
147            else : nouveau.deplieToutEtReaffiche()
148            nouveau.fenetre.donnePremier()
149            #nouveau.deplieToutEtReaffiche()
150       else :
151            self.node.setSelected(False)
152            nouveau.setSelected(True)
153            self.node.tree.setCurrentItem(nouveau)
154       if event != None : event.accept()
155       
156          
157
158   def creeListeCommande(self,filtre):
159       listeGroupes,dictGroupes=self.jdc.get_groups()
160       sensibleALaCasse=self.RBCasse.isChecked()
161       if "CACHE" in dictGroupes:
162          aExclure=dictGroupes["CACHE"]
163       else:
164          aExclure=()
165       listeACreer=[]
166       for l in self.jdc.get_liste_cmd():
167          if l not in aExclure : 
168             if sensibleALaCasse and (filtre != None and not filtre in l) : continue
169             if (not sensibleALaCasse) and filtre != None and (not filtre in l) and (not filtre.upper() in l) : continue
170             listeACreer.append(l)
171       return listeACreer
172
173   def ajouteRadioButtons(self):
174       if self.editor.nombreDeBoutonParLigne != 0 :
175          self.ajoutePushButtons()
176          return
177       #print 'ds ajouteRadioButtons'
178       filtre=str(self.LEFiltre.text())
179       if filtre==str("") : filtre=None
180       if hasattr(self,'buttonGroup') :
181          for b in self.buttonGroup.buttons():
182              self.buttonGroup.removeButton(b)
183              b.setParent(None)
184              b.close()
185       else :
186          self.buttonGroup = QButtonGroup()
187       for w in self.listeWidget :
188          w.setParent(None)
189          w.close()
190       self.listeWidget=[]
191       if self.affiche_alpha==1 :
192          liste=self.creeListeCommande(filtre)
193          for cmd in liste :
194            self.dicoCmd[tr(cmd)]=cmd
195            rbcmd=(QRadioButton(tr(cmd)))
196            self.buttonGroup.addButton(rbcmd)
197            self.commandesLayout.addWidget(rbcmd)
198            if self.editor.simpleClic :  rbcmd.mouseReleaseEvent=self.insereNoeudApresClick
199            else : rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
200            self.buttonGroup.buttonClicked.connect(self.rbClique) 
201       elif  self.affiche_groupe==1 :
202          listeGroupes,dictGroupes=self.jdc.get_groups()
203          for grp in listeGroupes:
204            if grp == "CACHE" : continue
205            label=QLabel(self)
206            text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
207            label.setText(text)
208            self.listeWidget.append(label)
209            aAjouter=1
210            sensibleALaCasse=self.RBCasse.isChecked()
211            for cmd in  dictGroupes[grp]:
212               if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
213               if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
214               if aAjouter == 1 :
215                  self.commandesLayout.addWidget(label)
216                  aAjouter=0
217               self.dicoCmd[tr(cmd)]=cmd
218               rbcmd=(QRadioButton(tr(cmd)))
219               self.buttonGroup.addButton(rbcmd)
220               self.commandesLayout.addWidget(rbcmd)
221               if self.editor.simpleClic :  rbcmd.mouseReleaseEvent=self.insereNoeudApresClick
222               else : rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
223               self.buttonGroup.buttonClicked.connect(self.rbClique) 
224            label2=QLabel(self)
225            label2.setText(" ")
226            self.listeWidget.append(label2)
227            self.commandesLayout.addWidget(label2)
228       elif  self.affiche_ordre==1 :
229          listeFiltre=self.creeListeCommande(filtre)
230          liste=[]
231          if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
232          else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
233          for cmd in Ordre_Des_Commandes :
234             if cmd in listeFiltre :
235                  liste.append(cmd)
236          for cmd in liste :
237            self.dicoCmd[tr(cmd)]=cmd
238            rbcmd=(QRadioButton(tr(cmd)))
239            self.buttonGroup.addButton(rbcmd)
240            self.commandesLayout.addWidget(rbcmd)
241            if self.editor.simpleClic :  rbcmd.mouseReleaseEvent=self.insereNoeudApresClick
242            else : rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
243            self.buttonGroup.buttonClicked.connect(self.rbClique) 
244
245      
246   def ajoutePushButtons(self):
247       if hasattr(self,'buttonGroup') :
248          for b in self.buttonGroup.buttons():
249              self.buttonGroup.removeButton(b)
250              b.setParent(None)
251              b.close()
252       else :
253          self.buttonGroup = QButtonGroup()
254          self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere) 
255       for w in self.listeWidget :
256          w.setParent(None)
257          w.close()
258       self.listeWidget=[]
259
260       if not hasattr(self,'maGrilleBouton') :
261          #self.commandesLayout.close()
262          self.maGrilleBouton=QGridLayout()
263          self.maGrilleBouton.setSpacing(20)
264          self.verticalLayout.addLayout(self.maGrilleBouton)
265       col=-1
266       ligne = 0
267       if self.affiche_alpha==1 :
268          liste=self.creeListeCommande(None)
269          for cmd in liste :
270            col=col+1
271            if col == self.editor.nombreDeBoutonParLigne :
272               col=0
273               ligne=ligne+1
274            self.dicoCmd[tr(cmd)]=cmd
275            rbcmd=QPushButton(tr(cmd))
276            rbcmd.setGeometry(QRect(40, 20, 211, 71))
277            rbcmd.setMaximumSize(QSize(250, 81))
278            rbcmd.setStyleSheet("background-color : rgb(66, 165, 238);\n"
279 "/*border-style : outset;*/\n"
280 "border-radius : 20px;\n"
281 "border-width : 30 px;\n"
282 "border-color : beige;\n"
283 "text-align : center")
284            if cmd in self.editor.dicoImages :
285               fichier=self.editor.dicoImages[cmd]
286               icon = QIcon()
287               icon.addPixmap(QPixmap(fichier), QIcon.Normal, QIcon.Off)
288               rbcmd.setIcon(icon)
289               rbcmd.setIconSize(QSize(48, 48))
290
291            self.buttonGroup.addButton(rbcmd)
292            self.maGrilleBouton.addWidget(rbcmd,ligne,col)
293
294   def clearFiltre(self):
295       self.LEFiltre.setText("")
296       self.ajouteRadioButtons()
297
298   def rbCliqueEtInsere(self,id):
299       self.rbClique(id)
300       self.insereNoeudApresClick(None)
301
302   def rbClique(self,id):
303       self.name=self.dicoCmd[str(id.text())]
304       definitionEtape=getattr(self.jdc.cata[0],self.name)
305       commentaire=getattr(definitionEtape,self.jdc.lang)
306       try :
307         commentaire=getattr(definitionEtape,self.jdc.lang)
308       except :
309         try :
310            commentaire=getattr(definitionEtape,"ang")
311         except :
312            commentaire=""
313       self.editor.affiche_commentaire(commentaire)
314
315
316
317   def setValide(self):
318       #PNPN a priori pas d icone mais peut-etre a faire
319       pass