Salome HOME
chgt Copyrigth
[tools/eficas.git] / InterfaceQT4 / monChoixCommande.py
1 # Copyright (C) 2007-2021   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.closeFrameRechercheCommandeSurPageDesCommandes == 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: aExclure=list(dictGroupes["CACHE"])
163       else: aExclure=()
164       listeACreer=[]
165       listeEtapesDejaPresentes=[]
166       if self.editor.maConfiguration.rendVisiblesLesCaches :
167          for e in self.jdc.etapes:
168             listeEtapesDejaPresentes.append(e.nom)
169          for c in aExclure :
170              if c not in listeEtapesDejaPresentes : aExclure.remove(c)
171       for l in self.jdc.getListeCmd():
172          if l not in aExclure : 
173             if sensibleALaCasse and (filtre != None and not filtre in l) : continue
174             if (not sensibleALaCasse) and filtre != None and (not filtre in l) and (not filtre.upper() in l) : continue
175             listeACreer.append(l)
176       return listeACreer
177
178   def ajouteRadioButtons(self):
179       if self.editor.maConfiguration.nombreDeBoutonParLigne != 0 :
180          self.ajoutePushButtons()
181          return
182       #print 'ds ajouteRadioButtons'
183       filtre=str(self.LEFiltre.text())
184       if filtre==str("") : filtre=None
185       if hasattr(self,'buttonGroup') :
186          for b in self.buttonGroup.buttons():
187              self.buttonGroup.removeButton(b)
188              b.setParent(None)
189              b.close()
190       else :
191          self.buttonGroup = QButtonGroup()
192       for w in self.listeWidget :
193          w.setParent(None)
194          w.close()
195       self.listeWidget=[]
196       if self.boolAlpha==1 :
197          liste=self.creeListeCommande(filtre)
198          for cmd in liste :
199            self.dicoCmd[tr(cmd)]=cmd
200            rbcmd=(QRadioButton(tr(cmd)))
201            self.buttonGroup.addButton(rbcmd)
202            self.commandesLayout.addWidget(rbcmd)
203            #if self.simpleClic :  rbcmd.mouseReleaseEvent=self.insereNoeudApresClick
204            #else : rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
205            #self.buttonGroup.buttonClicked.connect(self.rbClique) 
206            if not(self.simpleClic ):  rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
207          if self.simpleClic :  
208             self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere) 
209          else :
210             self.buttonGroup.buttonClicked.connect(self.rbClique) 
211       elif  self.boolGroupe==1 :
212          listeGroupes,dictGroupes=self.jdc.getGroups()
213          for grp in listeGroupes:
214            if grp == "CACHE" : continue
215            label=QLabel(self)
216            text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
217            label.setText(text)
218            self.listeWidget.append(label)
219            aAjouter=1
220            sensibleALaCasse=self.RBCasse.isChecked()
221            for cmd in  dictGroupes[grp]:
222               if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
223               if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
224               if aAjouter == 1 :
225                  self.commandesLayout.addWidget(label)
226                  aAjouter=0
227               self.dicoCmd[tr(cmd)]=cmd
228               rbcmd=(QRadioButton(tr(cmd)))
229               self.buttonGroup.addButton(rbcmd)
230               self.commandesLayout.addWidget(rbcmd)
231               if not(self.simpleClic ):  rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
232            if self.simpleClic :  
233              self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere) 
234            else :
235              self.buttonGroup.buttonClicked.connect(self.rbClique) 
236            label2=QLabel(self)
237            label2.setText(" ")
238            self.listeWidget.append(label2)
239            self.commandesLayout.addWidget(label2)
240       elif  self.boolOrdre==1 :
241          listeFiltre=self.creeListeCommande(filtre)
242          liste=[]
243          if self.editor.readercata.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
244          else : Ordre_Des_Commandes=self.editor.readercata.Ordre_Des_Commandes
245          for cmd in Ordre_Des_Commandes :
246             if cmd in listeFiltre :
247                  liste.append(cmd)
248          for cmd in liste :
249            self.dicoCmd[tr(cmd)]=cmd
250            rbcmd=(QRadioButton(tr(cmd)))
251            self.buttonGroup.addButton(rbcmd)
252            self.commandesLayout.addWidget(rbcmd)
253            if not(self.simpleClic ):  rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
254          if self.simpleClic :  
255             self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere) 
256          else :
257             self.buttonGroup.buttonClicked.connect(self.rbClique) 
258
259      
260
261   def ajoutePushButtons(self):
262       if hasattr(self,'buttonGroup') :
263          for b in self.buttonGroup.buttons():
264              self.buttonGroup.removeButton(b)
265              b.setParent(None)
266              b.close()
267       else :
268          self.buttonGroup = QButtonGroup()
269          self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere) 
270       for w in self.listeWidget :
271          w.setParent(None)
272          w.close()
273       self.listeWidget=[]
274
275       if not hasattr(self,'maGrilleBouton') :
276          #self.commandesLayout.close()
277          self.maGrilleBouton=QGridLayout()
278          self.maGrilleBouton.setSpacing(20)
279          self.verticalLayout.addLayout(self.maGrilleBouton)
280       col=-1
281       ligne = 0
282
283       if self.boolAlpha==1 :
284          liste=self.creeListeCommande(None)
285       elif  self.boolOrdre:
286          liste=self.creeListeCommande(None)
287          listeFiltre=self.creeListeCommande(None)
288          liste=[]
289          if self.editor.readercata.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
290          else : Ordre_Des_Commandes=self.editor.readercata.Ordre_Des_Commandes
291          for cmd in Ordre_Des_Commandes :
292             if cmd in listeFiltre :
293                  liste.append(cmd)
294       for cmd in liste :
295            col=col+1
296            if col == self.editor.maConfiguration.nombreDeBoutonParLigne :
297               col=0
298               ligne=ligne+1
299            self.dicoCmd[tr(cmd)]=cmd
300            rbcmd=QPushButton(tr(cmd))
301            rbcmd.setGeometry(QRect(40, 20, 211, 71))
302            rbcmd.setMaximumSize(QSize(250, 81))
303            rbcmd.setStyleSheet("background-color : rgb(66, 165, 238);\n"
304 "/*border-style : outset;*/\n"
305 "border-radius : 20px;\n"
306 "border-width : 30 px;\n"
307 "border-color : beige;\n"
308 "text-align : center")
309            #print ('self.editor.maConfiguration.dicoImages', self.editor.maConfiguration.dicoImages)
310            if cmd in self.editor.maConfiguration.dicoImages :
311               fichier=self.editor.maConfiguration.dicoImages[cmd]
312               icon = QIcon()
313               icon.addPixmap(QPixmap(fichier), QIcon.Normal, QIcon.Off)
314               rbcmd.setIcon(icon)
315               rbcmd.setIconSize(QSize(48, 48))
316
317            self.buttonGroup.addButton(rbcmd)
318            self.maGrilleBouton.addWidget(rbcmd,ligne,col)
319
320   def clearFiltre(self):
321       self.LEFiltre.setText("")
322       self.ajouteRadioButtons()
323
324   def rbCliqueEtInsere(self,id):
325       self.rbClique(id)
326       self.insereNoeudApresClick(None)
327
328   def rbClique(self,id):
329  
330       try : 
331         self.name=self.dicoCmd[id.text()]
332       except : 
333         try :
334           self.name=self.dicoCmd[str(id.text())]
335         except :
336           print ('pb d accent : contacter la maintenance')
337
338       definitionEtape=getattr(self.jdc.cata,self.name)
339       #commentaire=getattr(definitionEtape,self.jdc.lang)
340       try :
341         commentaire=getattr(definitionEtape,self.jdc.lang)
342       except :
343         try :
344            commentaire=getattr(definitionEtape,"ang")
345         except :
346            commentaire=""
347       self.editor.afficheCommentaire(commentaire)
348
349
350
351   def setValide(self):
352       #PNPN a priori pas d icone mais peut-etre a faire
353       pass