Salome HOME
Merge V9 dans Master
[tools/eficas.git] / InterfaceQT4 / monChoixCommande.py
1 # Copyright (C) 2007-2017   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,parent=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.simpleClic=self.editor.maConfiguration.simpleClic
55       self.jdc  = self.item.object.getJdcRoot()
56       debutTitre=self.editor.titre
57       self.listeWidget=[]
58       self.dicoCmd={}
59       if self.editor.fichier != None : 
60           nouveauTitre=debutTitre+" "+os.path.basename(self.editor.fichier)
61       else :
62           nouveauTitre=debutTitre
63       self.editor.appliEficas.setWindowTitle(nouveauTitre)
64
65
66       self.RBalpha.clicked.connect(self.afficheAlpha)
67       self.RBGroupe.clicked.connect(self.afficheGroupe)
68       self.RBOrdre.clicked.connect(self.afficheOrdre)
69       self.RBClear.clicked.connect(self.clearFiltre)
70       self.RBCasse.toggled.connect(self.ajouteRadioButtons)
71       self.LEFiltre.returnPressed.connect(self.ajouteRadioButtons)
72       self.LEFiltre.textChanged.connect(self.ajouteRadioButtons)
73
74       if self.node.tree.item.getRegles() == () :
75          self.RBRegle.close()
76          self.labelRegle.close()
77       else : 
78         self.RBRegle.clicked.connect(self.afficheRegle)
79
80       if self.editor.readercata.Ordre_Des_Commandes == None : self.RBOrdre.close()
81
82        
83       #self.editor.labelCommentaire.setText("")
84       if self.editor.widgetOptionnel!= None : 
85          self.editor.fermeOptionnel()
86          self.editor.widgetOptionnel=None
87       self.name=None
88
89       self.boolAlpha=0
90       self.boolGroupe=0
91       self.boolOrdre=0
92       if self.editor.maConfiguration.affiche=="alpha"  : 
93          self.boolAlpha==1;  
94          self.RBalpha.setChecked(True);
95          self.afficheAlpha()
96       elif self.editor.maConfiguration.affiche=="groupe" : 
97          self.boolGroupe==1; 
98          self.RBGroupe.setChecked(True); 
99          self.afficheGroupe()
100       elif self.editor.maConfiguration.affiche=="ordre"  : 
101          self.boolOrdre==1;  
102          self.RBOrdre.setChecked(True);  
103          self.afficheOrdre()
104       if self.editor.maConfiguration.closeFrameRechercheCommande == True : self.frameAffichage.close()
105
106       if self.editor.widgetTree != None : self.editor.restoreSplitterSizes(2) 
107       else: self.editor.restoreSplitterSizes(3)
108
109   def afficheRegle(self):
110       self.node.tree.appellebuildLBRegles()
111
112   def afficheAlpha(self):
113       self.boolAlpha=1
114       self.boolGroupe=0
115       self.boolOrdre=0
116       self.ajouteRadioButtons()
117
118   def afficheGroupe(self):
119       self.boolAlpha=0
120       self.boolGroupe=1
121       self.boolOrdre=0
122       self.ajouteRadioButtons()
123
124   def afficheOrdre(self):
125       self.boolAlpha=0
126       self.boolGroupe=0
127       self.boolOrdre=1
128       self.ajouteRadioButtons()
129
130   def insereNoeudApresClick(self,event):
131       #print self.editor.Classement_Commandes_Ds_Arbre
132       #if self.editor.Classement_Commandes_Ds_Arbre!= () : self.chercheOu()
133       #print ('dans insereNoeudApresClick')
134       nodeCourrant=self.node.tree.currentItem()
135       if nodeCourrant==None: nodeCourrant=self.node.tree.racine
136       if self.name != None :
137          plier=self.editor.maConfiguration.afficheCommandesPliees
138          if nodeCourrant==self.node : nouveau=self.node.appendChild(self.name,'first',plier)
139          else : nouveau=nodeCourrant.appendBrother(self.name,plier=plier)
140       else :
141          nouveau = 0
142       if nouveau == 0 : return # on n a pas insere le noeud
143       nouveau.setDeplie()
144       #if self.editor.afficheApresInsert==True : nouveau.plieToutEtReaffiche()
145       if self.editor.afficheApresInsert == True :
146            #if self.editor.affichePlie==True:  nouveau.plieToutEtReaffiche()
147            if self.editor.maConfiguration.afficheCommandesPliees ==True:  nouveau.plieToutEtReaffiche()
148            else : nouveau.deplieToutEtReaffiche()
149            nouveau.fenetre.donnePremier()
150            #nouveau.deplieToutEtReaffiche()
151       else :
152            self.node.setSelected(False)
153            nouveau.setSelected(True)
154            self.node.tree.setCurrentItem(nouveau)
155       if event != None : event.accept()
156       
157          
158
159   def creeListeCommande(self,filtre):
160       listeGroupes,dictGroupes=self.jdc.getGroups()
161       sensibleALaCasse=self.RBCasse.isChecked()
162       if "CACHE" in dictGroupes:
163          aExclure=dictGroupes["CACHE"]
164       else:
165          aExclure=()
166       listeACreer=[]
167       for l in self.jdc.getListeCmd():
168          if l not in aExclure : 
169             if sensibleALaCasse and (filtre != None and not filtre in l) : continue
170             if (not sensibleALaCasse) and filtre != None and (not filtre in l) and (not filtre.upper() in l) : continue
171             listeACreer.append(l)
172       return listeACreer
173
174   def ajouteRadioButtons(self):
175       if self.editor.maConfiguration.nombreDeBoutonParLigne != 0 :
176          self.ajoutePushButtons()
177          return
178       #print 'ds ajouteRadioButtons'
179       filtre=str(self.LEFiltre.text())
180       if filtre==str("") : filtre=None
181       if hasattr(self,'buttonGroup') :
182          for b in self.buttonGroup.buttons():
183              self.buttonGroup.removeButton(b)
184              b.setParent(None)
185              b.close()
186       else :
187          self.buttonGroup = QButtonGroup()
188       for w in self.listeWidget :
189          w.setParent(None)
190          w.close()
191       self.listeWidget=[]
192       if self.boolAlpha==1 :
193          liste=self.creeListeCommande(filtre)
194          for cmd in liste :
195            self.dicoCmd[tr(cmd)]=cmd
196            rbcmd=(QRadioButton(tr(cmd)))
197            self.buttonGroup.addButton(rbcmd)
198            self.commandesLayout.addWidget(rbcmd)
199            #if self.simpleClic :  rbcmd.mouseReleaseEvent=self.insereNoeudApresClick
200            #else : rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
201            #self.buttonGroup.buttonClicked.connect(self.rbClique) 
202            if not(self.simpleClic ):  rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
203          if self.simpleClic :  
204             self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere) 
205          else :
206             self.buttonGroup.buttonClicked.connect(self.rbClique) 
207       elif  self.boolGroupe==1 :
208          listeGroupes,dictGroupes=self.jdc.getGroups()
209          for grp in listeGroupes:
210            if grp == "CACHE" : continue
211            label=QLabel(self)
212            text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
213            label.setText(text)
214            self.listeWidget.append(label)
215            aAjouter=1
216            sensibleALaCasse=self.RBCasse.isChecked()
217            for cmd in  dictGroupes[grp]:
218               if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
219               if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
220               if aAjouter == 1 :
221                  self.commandesLayout.addWidget(label)
222                  aAjouter=0
223               self.dicoCmd[tr(cmd)]=cmd
224               rbcmd=(QRadioButton(tr(cmd)))
225               self.buttonGroup.addButton(rbcmd)
226               self.commandesLayout.addWidget(rbcmd)
227               if not(self.simpleClic ):  rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
228            if self.simpleClic :  
229              self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere) 
230            else :
231              self.buttonGroup.buttonClicked.connect(self.rbClique) 
232            label2=QLabel(self)
233            label2.setText(" ")
234            self.listeWidget.append(label2)
235            self.commandesLayout.addWidget(label2)
236       elif  self.boolOrdre==1 :
237          listeFiltre=self.creeListeCommande(filtre)
238          liste=[]
239          if self.editor.readercata.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
240          else : Ordre_Des_Commandes=self.editor.readercata.Ordre_Des_Commandes
241          for cmd in Ordre_Des_Commandes :
242             if cmd in listeFiltre :
243                  liste.append(cmd)
244          for cmd in liste :
245            self.dicoCmd[tr(cmd)]=cmd
246            rbcmd=(QRadioButton(tr(cmd)))
247            self.buttonGroup.addButton(rbcmd)
248            self.commandesLayout.addWidget(rbcmd)
249            if not(self.simpleClic ):  rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
250          if self.simpleClic :  
251             self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere) 
252          else :
253             self.buttonGroup.buttonClicked.connect(self.rbClique) 
254
255      
256
257   def ajoutePushButtons(self):
258       if hasattr(self,'buttonGroup') :
259          for b in self.buttonGroup.buttons():
260              self.buttonGroup.removeButton(b)
261              b.setParent(None)
262              b.close()
263       else :
264          self.buttonGroup = QButtonGroup()
265          self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere) 
266       for w in self.listeWidget :
267          w.setParent(None)
268          w.close()
269       self.listeWidget=[]
270
271       if not hasattr(self,'maGrilleBouton') :
272          #self.commandesLayout.close()
273          self.maGrilleBouton=QGridLayout()
274          self.maGrilleBouton.setSpacing(20)
275          self.verticalLayout.addLayout(self.maGrilleBouton)
276       col=-1
277       ligne = 0
278
279       if self.boolAlpha==1 :
280          liste=self.creeListeCommande(None)
281       elif  self.boolOrdre:
282          liste=self.creeListeCommande(None)
283          listeFiltre=self.creeListeCommande(None)
284          liste=[]
285          if self.editor.readercata.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
286          else : Ordre_Des_Commandes=self.editor.readercata.Ordre_Des_Commandes
287          for cmd in Ordre_Des_Commandes :
288             if cmd in listeFiltre :
289                  liste.append(cmd)
290       for cmd in liste :
291            col=col+1
292            if col == self.editor.maConfiguration.nombreDeBoutonParLigne :
293               col=0
294               ligne=ligne+1
295            self.dicoCmd[tr(cmd)]=cmd
296            rbcmd=QPushButton(tr(cmd))
297            rbcmd.setGeometry(QRect(40, 20, 211, 71))
298            rbcmd.setMaximumSize(QSize(250, 81))
299            rbcmd.setStyleSheet("background-color : rgb(66, 165, 238);\n"
300 "/*border-style : outset;*/\n"
301 "border-radius : 20px;\n"
302 "border-width : 30 px;\n"
303 "border-color : beige;\n"
304 "text-align : center")
305            #print ('self.editor.maConfiguration.dicoImages', self.editor.maConfiguration.dicoImages)
306            if cmd in self.editor.maConfiguration.dicoImages :
307               fichier=self.editor.maConfiguration.dicoImages[cmd]
308               icon = QIcon()
309               icon.addPixmap(QPixmap(fichier), QIcon.Normal, QIcon.Off)
310               rbcmd.setIcon(icon)
311               rbcmd.setIconSize(QSize(48, 48))
312
313            self.buttonGroup.addButton(rbcmd)
314            self.maGrilleBouton.addWidget(rbcmd,ligne,col)
315
316   def clearFiltre(self):
317       self.LEFiltre.setText("")
318       self.ajouteRadioButtons()
319
320   def rbCliqueEtInsere(self,id):
321       self.rbClique(id)
322       self.insereNoeudApresClick(None)
323
324   def rbClique(self,id):
325  
326       try : 
327         self.name=self.dicoCmd[id.text()]
328       except : 
329         try :
330           self.name=self.dicoCmd[str(id.text())]
331         except :
332           print ('pb d accent : contacter la maintenance')
333
334       definitionEtape=getattr(self.jdc.cata,self.name)
335       #commentaire=getattr(definitionEtape,self.jdc.lang)
336       try :
337         commentaire=getattr(definitionEtape,self.jdc.lang)
338       except :
339         try :
340            commentaire=getattr(definitionEtape,"ang")
341         except :
342            commentaire=""
343       self.editor.afficheCommentaire(commentaire)
344
345
346
347   def setValide(self):
348       #PNPN a priori pas d icone mais peut-etre a faire
349       pass