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+" "+str(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.append_brother(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 rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
198 self.commandesLayout.addWidget(rbcmd)
199 self.buttonGroup.buttonClicked.connect(self.rbClique)
200 elif self.affiche_groupe==1 :
201 listeGroupes,dictGroupes=self.jdc.get_groups()
202 for grp in listeGroupes:
203 if grp == "CACHE" : continue
205 text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
207 self.listeWidget.append(label)
209 sensibleALaCasse=self.RBCasse.isChecked()
210 for cmd in dictGroupes[grp]:
211 if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
212 if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
214 self.commandesLayout.addWidget(label)
216 self.dicoCmd[tr(cmd)]=cmd
217 rbcmd=(QRadioButton(tr(cmd)))
218 self.buttonGroup.addButton(rbcmd)
219 self.commandesLayout.addWidget(rbcmd)
220 rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
221 self.buttonGroup.buttonClicked.connect(self.rbClique)
224 self.listeWidget.append(label2)
225 self.commandesLayout.addWidget(label2)
226 elif self.affiche_ordre==1 :
227 listeFiltre=self.creeListeCommande(filtre)
229 if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
230 else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
231 for cmd in Ordre_Des_Commandes :
232 if cmd in listeFiltre :
235 self.dicoCmd[tr(cmd)]=cmd
236 rbcmd=(QRadioButton(tr(cmd)))
237 self.buttonGroup.addButton(rbcmd)
238 self.commandesLayout.addWidget(rbcmd)
239 rbcmd.mouseDoubleClickEvent=self.insereNoeudApresClick
240 self.buttonGroup.buttonClicked.connect(self.rbClique)
243 def ajoutePushButtons(self):
244 if hasattr(self,'buttonGroup') :
245 for b in self.buttonGroup.buttons():
246 self.buttonGroup.removeButton(b)
250 self.buttonGroup = QButtonGroup()
251 self.buttonGroup.buttonClicked.connect(self.rbCliqueEtInsere)
252 for w in self.listeWidget :
257 if not hasattr(self,'maGrilleBouton') :
258 #self.commandesLayout.close()
259 self.maGrilleBouton=QGridLayout()
260 self.maGrilleBouton.setSpacing(20)
261 self.verticalLayout.addLayout(self.maGrilleBouton)
264 if self.affiche_alpha==1 :
265 liste=self.creeListeCommande(None)
268 if col == self.editor.nombreDeBoutonParLigne :
271 self.dicoCmd[tr(cmd)]=cmd
272 rbcmd=QPushButton(tr(cmd))
273 rbcmd.setGeometry(QRect(40, 20, 211, 71))
274 rbcmd.setMaximumSize(QSize(250, 81))
275 rbcmd.setStyleSheet("background-color : rgb(168, 227, 142);\n"
276 "/*border-style : outset;*/\n"
277 "border-radius : 20px;\n"
278 "border-width : 30 px;\n"
279 "border-color : beige;\n"
282 icon.addPixmap(QPixmap("../monCode/images/essaiAster.png"), QIcon.Normal, QIcon.Off)
284 rbcmd.setIconSize(QSize(48, 48))
286 self.buttonGroup.addButton(rbcmd)
287 self.maGrilleBouton.addWidget(rbcmd,ligne,col)
289 def clearFiltre(self):
290 self.LEFiltre.setText("")
291 self.ajouteRadioButtons()
293 def rbCliqueEtInsere(self,id):
295 self.insereNoeudApresClick(None)
297 def rbClique(self,id):
298 #print ('ds rbClique')
299 self.name=self.dicoCmd[str(id.text())]
300 definitionEtape=getattr(self.jdc.cata[0],self.name)
301 commentaire=getattr(definitionEtape,self.jdc.lang)
303 commentaire=getattr(definitionEtape,self.jdc.lang)
306 commentaire=getattr(definitionEtape,"ang")
309 self.editor.affiche_commentaire(commentaire)
314 #PNPN a priori pas d icone mais peut-etre a faire