1 # Copyright (C) 2007-2017 EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 from __future__ import absolute_import
24 from builtins import str
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
32 from Extensions.i18n import tr
38 class MonChoixCommande(Ui_ChoixCommandes,QWidget):
41 def __init__(self,node, jdc_item, editor):
42 QWidget.__init__(self,parent=None)
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))
54 self.simpleClic=self.editor.maConfiguration.simpleClic
55 self.jdc = self.item.object.getJdcRoot()
56 debutTitre=self.editor.titre
59 if self.editor.fichier != None :
60 nouveauTitre=debutTitre+" "+os.path.basename(self.editor.fichier)
62 nouveauTitre=debutTitre
63 self.editor.appliEficas.setWindowTitle(nouveauTitre)
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)
74 if self.node.tree.item.getRegles() == () :
76 self.labelRegle.close()
78 self.RBRegle.clicked.connect(self.afficheRegle)
80 if self.editor.readercata.Ordre_Des_Commandes == None : self.RBOrdre.close()
83 #self.editor.labelCommentaire.setText("")
84 if self.editor.widgetOptionnel!= None :
85 self.editor.fermeOptionnel()
86 self.editor.widgetOptionnel=None
92 if self.editor.maConfiguration.affiche=="alpha" :
94 self.RBalpha.setChecked(True);
96 elif self.editor.maConfiguration.affiche=="groupe" :
98 self.RBGroupe.setChecked(True);
100 elif self.editor.maConfiguration.affiche=="ordre" :
102 self.RBOrdre.setChecked(True);
104 if self.editor.maConfiguration.closeFrameRechercheCommande == True : self.frameAffichage.close()
106 if self.editor.widgetTree != None : self.editor.restoreSplitterSizes(2)
107 else: self.editor.restoreSplitterSizes(3)
109 def afficheRegle(self):
110 self.node.tree.appellebuildLBRegles()
112 def afficheAlpha(self):
116 self.ajouteRadioButtons()
118 def afficheGroupe(self):
122 self.ajouteRadioButtons()
124 def afficheOrdre(self):
128 self.ajouteRadioButtons()
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)
142 if nouveau == 0 : return # on n a pas insere le noeud
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()
152 self.node.setSelected(False)
153 nouveau.setSelected(True)
154 self.node.tree.setCurrentItem(nouveau)
155 if event != None : event.accept()
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"])
165 listeEtapesDejaPresentes=[]
166 if self.editor.maConfiguration.rendVisiblesLesCaches :
167 for e in self.jdc.etapes:
168 listeEtapesDejaPresentes.append(e.nom)
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)
178 def ajouteRadioButtons(self):
179 if self.editor.maConfiguration.nombreDeBoutonParLigne != 0 :
180 self.ajoutePushButtons()
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)
191 self.buttonGroup = QButtonGroup()
192 for w in self.listeWidget :
196 if self.boolAlpha==1 :
197 liste=self.creeListeCommande(filtre)
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
208 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
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
216 text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
218 self.listeWidget.append(label)
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
225 self.commandesLayout.addWidget(label)
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
233 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
235 self.buttonGroup.buttonClicked.connect(self.rbClique)
238 self.listeWidget.append(label2)
239 self.commandesLayout.addWidget(label2)
240 elif self.boolOrdre==1 :
241 listeFiltre=self.creeListeCommande(filtre)
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 :
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
255 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
257 self.buttonGroup.buttonClicked.connect(self.rbClique)
261 def ajoutePushButtons(self):
262 if hasattr(self,'buttonGroup') :
263 for b in self.buttonGroup.buttons():
264 self.buttonGroup.removeButton(b)
268 self.buttonGroup = QButtonGroup()
269 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
270 for w in self.listeWidget :
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)
283 if self.boolAlpha==1 :
284 liste=self.creeListeCommande(None)
286 liste=self.creeListeCommande(None)
287 listeFiltre=self.creeListeCommande(None)
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 :
296 if col == self.editor.maConfiguration.nombreDeBoutonParLigne :
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]
313 icon.addPixmap(QPixmap(fichier), QIcon.Normal, QIcon.Off)
315 rbcmd.setIconSize(QSize(48, 48))
317 self.buttonGroup.addButton(rbcmd)
318 self.maGrilleBouton.addWidget(rbcmd,ligne,col)
320 def clearFiltre(self):
321 self.LEFiltre.setText("")
322 self.ajouteRadioButtons()
324 def rbCliqueEtInsere(self,id):
326 self.insereNoeudApresClick(None)
328 def rbClique(self,id):
331 self.name=self.dicoCmd[id.text()]
334 self.name=self.dicoCmd[str(id.text())]
336 print ('pb d accent : contacter la maintenance')
338 definitionEtape=getattr(self.jdc.cata,self.name)
339 #commentaire=getattr(definitionEtape,self.jdc.lang)
341 commentaire=getattr(definitionEtape,self.jdc.lang)
344 commentaire=getattr(definitionEtape,"ang")
347 self.editor.afficheCommentaire(commentaire)
352 #PNPN a priori pas d icone mais peut-etre a faire