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:
163 aExclure=dictGroupes["CACHE"]
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)
174 def ajouteRadioButtons(self):
175 if self.editor.maConfiguration.nombreDeBoutonParLigne != 0 :
176 self.ajoutePushButtons()
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)
187 self.buttonGroup = QButtonGroup()
188 for w in self.listeWidget :
192 if self.boolAlpha==1 :
193 liste=self.creeListeCommande(filtre)
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
204 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
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
212 text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
214 self.listeWidget.append(label)
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
221 self.commandesLayout.addWidget(label)
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
229 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
231 self.buttonGroup.buttonClicked.connect(self.rbClique)
234 self.listeWidget.append(label2)
235 self.commandesLayout.addWidget(label2)
236 elif self.boolOrdre==1 :
237 listeFiltre=self.creeListeCommande(filtre)
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 :
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
251 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
253 self.buttonGroup.buttonClicked.connect(self.rbClique)
257 def ajoutePushButtons(self):
258 if hasattr(self,'buttonGroup') :
259 for b in self.buttonGroup.buttons():
260 self.buttonGroup.removeButton(b)
264 self.buttonGroup = QButtonGroup()
265 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
266 for w in self.listeWidget :
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)
279 if self.boolAlpha==1 :
280 liste=self.creeListeCommande(None)
282 liste=self.creeListeCommande(None)
283 listeFiltre=self.creeListeCommande(None)
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 :
292 if col == self.editor.maConfiguration.nombreDeBoutonParLigne :
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]
309 icon.addPixmap(QPixmap(fichier), QIcon.Normal, QIcon.Off)
311 rbcmd.setIconSize(QSize(48, 48))
313 self.buttonGroup.addButton(rbcmd)
314 self.maGrilleBouton.addWidget(rbcmd,ligne,col)
316 def clearFiltre(self):
317 self.LEFiltre.setText("")
318 self.ajouteRadioButtons()
320 def rbCliqueEtInsere(self,id):
322 self.insereNoeudApresClick(None)
324 def rbClique(self,id):
327 self.name=self.dicoCmd[id.text()]
330 self.name=self.dicoCmd[str(id.text())]
332 print ('pb d accent : contacter la maintenance')
334 definitionEtape=getattr(self.jdc.cata,self.name)
335 #commentaire=getattr(definitionEtape,self.jdc.lang)
337 commentaire=getattr(definitionEtape,self.jdc.lang)
340 commentaire=getattr(definitionEtape,"ang")
343 self.editor.afficheCommentaire(commentaire)
348 #PNPN a priori pas d icone mais peut-etre a faire