1 # Copyright (C) 2007-2013 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,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.jdc = self.item.object.get_jdc_root()
55 debutTitre=self.editor.titre
58 if self.editor.fichier != None :
59 nouveauTitre=debutTitre+" "+os.path.basename(self.editor.fichier)
61 nouveauTitre=debutTitre
62 self.editor.appliEficas.setWindowTitle(nouveauTitre)
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)
73 if self.node.tree.item.get_regles() == () :
75 self.labelRegle.close()
77 self.RBRegle.clicked.connect(self.afficheRegle)
79 if self.editor.Ordre_Des_Commandes == None : self.RBOrdre.close()
82 #self.editor.labelCommentaire.setText("")
83 if self.editor.widgetOptionnel!= None :
84 self.editor.fermeOptionnel()
85 self.editor.widgetOptionnel=None
91 if self.editor.affiche=="alpha" :
92 self.affiche_alpha==1;
93 self.RBalpha.setChecked(True);
95 elif self.editor.affiche=="groupe" :
96 self.affiche_groupe==1;
97 self.RBGroupe.setChecked(True);
99 elif self.editor.affiche=="ordre" :
100 self.affiche_ordre==1;
101 self.RBOrdre.setChecked(True);
103 if self.editor.closeFrameRechercheCommande == True : self.frameAffichage.close()
105 if self.editor.widgetTree != None : self.editor.restoreSplitterSizes(2)
106 else: self.editor.restoreSplitterSizes(3)
108 def afficheRegle(self):
109 self.node.tree.AppelleBuildLBRegles()
111 def afficheAlpha(self):
113 self.affiche_groupe=0
115 self.ajouteRadioButtons()
117 def afficheGroupe(self):
119 self.affiche_groupe=1
121 self.ajouteRadioButtons()
123 def afficheOrdre(self):
125 self.affiche_groupe=0
127 self.ajouteRadioButtons()
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.appendBrother(self.name,plier=plier)
141 if nouveau == 0 : return # on n a pas insere le noeud
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()
151 self.node.setSelected(False)
152 nouveau.setSelected(True)
153 self.node.tree.setCurrentItem(nouveau)
154 if event != None : event.accept()
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"]
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)
173 def ajouteRadioButtons(self):
174 if self.editor.nombreDeBoutonParLigne != 0 :
175 self.ajoutePushButtons()
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)
186 self.buttonGroup = QButtonGroup()
187 for w in self.listeWidget :
191 if self.affiche_alpha==1 :
192 liste=self.creeListeCommande(filtre)
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 if not(self.editor.simpleClic ): rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
202 if self.editor.simpleClic :
203 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
205 self.buttonGroup.buttonClicked.connect(self.rbClique)
206 elif self.affiche_groupe==1 :
207 listeGroupes,dictGroupes=self.jdc.get_groups()
208 for grp in listeGroupes:
209 if grp == "CACHE" : continue
211 text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
213 self.listeWidget.append(label)
215 sensibleALaCasse=self.RBCasse.isChecked()
216 for cmd in dictGroupes[grp]:
217 if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
218 if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
220 self.commandesLayout.addWidget(label)
222 self.dicoCmd[tr(cmd)]=cmd
223 rbcmd=(QRadioButton(tr(cmd)))
224 self.buttonGroup.addButton(rbcmd)
225 self.commandesLayout.addWidget(rbcmd)
226 if not(self.editor.simpleClic ): rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
227 if self.editor.simpleClic :
228 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
230 self.buttonGroup.buttonClicked.connect(self.rbClique)
233 self.listeWidget.append(label2)
234 self.commandesLayout.addWidget(label2)
235 elif self.affiche_ordre==1 :
236 listeFiltre=self.creeListeCommande(filtre)
238 if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
239 else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
240 for cmd in Ordre_Des_Commandes :
241 if cmd in listeFiltre :
244 self.dicoCmd[tr(cmd)]=cmd
245 rbcmd=(QRadioButton(tr(cmd)))
246 self.buttonGroup.addButton(rbcmd)
247 self.commandesLayout.addWidget(rbcmd)
248 if not(self.editor.simpleClic ): rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
249 if self.editor.simpleClic :
250 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
252 self.buttonGroup.buttonClicked.connect(self.rbClique)
256 def ajoutePushButtons(self):
257 if hasattr(self,'buttonGroup') :
258 for b in self.buttonGroup.buttons():
259 self.buttonGroup.removeButton(b)
263 self.buttonGroup = QButtonGroup()
264 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
265 for w in self.listeWidget :
270 if not hasattr(self,'maGrilleBouton') :
271 #self.commandesLayout.close()
272 self.maGrilleBouton=QGridLayout()
273 self.maGrilleBouton.setSpacing(20)
274 self.verticalLayout.addLayout(self.maGrilleBouton)
278 if self.affiche_alpha==1 :
279 liste=self.creeListeCommande(None)
280 elif self.affiche_ordre:
281 liste=self.creeListeCommande(None)
282 listeFiltre=self.creeListeCommande(None)
284 if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
285 else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
286 for cmd in Ordre_Des_Commandes :
287 if cmd in listeFiltre :
291 if col == self.editor.nombreDeBoutonParLigne :
294 self.dicoCmd[tr(cmd)]=cmd
295 rbcmd=QPushButton(tr(cmd))
296 rbcmd.setGeometry(QRect(40, 20, 211, 71))
297 rbcmd.setMaximumSize(QSize(250, 81))
298 rbcmd.setStyleSheet("background-color : rgb(66, 165, 238);\n"
299 "/*border-style : outset;*/\n"
300 "border-radius : 20px;\n"
301 "border-width : 30 px;\n"
302 "border-color : beige;\n"
303 "text-align : center")
304 if cmd in self.editor.dicoImages :
305 fichier=self.editor.dicoImages[cmd]
307 icon.addPixmap(QPixmap(fichier), QIcon.Normal, QIcon.Off)
309 rbcmd.setIconSize(QSize(48, 48))
311 self.buttonGroup.addButton(rbcmd)
312 self.maGrilleBouton.addWidget(rbcmd,ligne,col)
314 def clearFiltre(self):
315 self.LEFiltre.setText("")
316 self.ajouteRadioButtons()
318 def rbCliqueEtInsere(self,id):
320 self.insereNoeudApresClick(None)
322 def rbClique(self,id):
323 self.name=self.dicoCmd[str(id.text())]
324 definitionEtape=getattr(self.jdc.cata[0],self.name)
325 #commentaire=getattr(definitionEtape,self.jdc.lang)
327 commentaire=getattr(definitionEtape,self.jdc.lang)
330 commentaire=getattr(definitionEtape,"ang")
333 self.editor.affiche_commentaire(commentaire)
338 #PNPN a priori pas d icone mais peut-etre a faire