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 desChoixCommandes import Ui_ChoixCommandes
23 from determine import monEnvQT5
25 from PyQt5.QtWidgets import QWidget, QAction ,QButtonGroup, QRadioButton, QLabel
26 from PyQt5.QtGui import QIcon
27 from PyQt5.QtCore import QSize
29 from PyQt4.QtGui import *
30 from PyQt4.QtCore import *
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)
68 self.RBalpha.clicked.connect(self.afficheAlpha)
69 self.RBGroupe.clicked.connect(self.afficheGroupe)
70 self.RBOrdre.clicked.connect(self.afficheOrdre)
71 self.RBClear.clicked.connect(self.clearFiltre)
72 self.RBCasse.toggled.connect(self.ajouteRadioButtons)
73 self.LEFiltre.returnPressed.connect(self.ajouteRadioButtons)
74 self.LEFiltre.textChanged.connect(self.ajouteRadioButtons)
76 self.connect(self.RBalpha,SIGNAL("clicked()"),self.afficheAlpha)
77 self.connect(self.RBGroupe,SIGNAL("clicked()"),self.afficheGroupe)
78 self.connect(self.RBOrdre,SIGNAL("clicked()"),self.afficheOrdre)
79 self.connect(self.RBClear,SIGNAL("clicked()"),self.clearFiltre)
80 self.connect(self.RBCasse,SIGNAL("toggled(bool)"),self.ajouteRadioButtons)
81 self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.ajouteRadioButtons)
82 if self.node.tree.item.get_regles() == () :
84 self.labelRegle.close()
86 if monEnvQT5 : self.RBRegle.clicked.connect(self.afficheRegle)
87 else : self.connect(self.RBRegle,SIGNAL("clicked()"),self.afficheRegle)
89 if self.editor.Ordre_Des_Commandes == None : self.RBOrdre.close()
92 #self.editor.labelCommentaire.setText("")
93 if self.editor.widgetOptionnel!= None :
94 self.editor.fermeOptionnel()
95 self.editor.widgetOptionnel=None
101 if self.editor.affiche=="alpha" :
102 self.affiche_alpha==1;
103 self.RBalpha.setChecked(True);
105 elif self.editor.affiche=="groupe" :
106 self.affiche_groupe==1;
107 self.RBGroupe.setChecked(True);
109 elif self.editor.affiche=="ordre" :
110 self.affiche_ordre==1;
111 self.RBOrdre.setChecked(True);
113 if self.editor.closeFrameRechercheCommande == True : self.frameAffichage.close()
115 def afficheRegle(self):
116 self.node.tree.AppelleBuildLBRegles()
118 def afficheAlpha(self):
120 self.affiche_groupe=0
122 self.ajouteRadioButtons()
124 def afficheGroupe(self):
126 self.affiche_groupe=1
128 self.ajouteRadioButtons()
130 def afficheOrdre(self):
132 self.affiche_groupe=0
134 self.ajouteRadioButtons()
136 def mouseDoubleClickEvent(self,event):
137 nodeCourrant=self.node.tree.currentItem()
138 if nodeCourrant==None: nodeCourrant=self.node.tree.racine
139 if self.name != None :
140 plier=self.editor.afficheCommandesPliees
141 if nodeCourrant==self.node : nouveau=self.node.append_child(self.name,'first',plier)
142 else : nouveau=nodeCourrant.append_brother(self.name,plier=plier)
145 if nouveau == 0 : return # on n a pas insere le noeud
147 #if self.editor.afficheApresInsert==True : nouveau.plieToutEtReaffiche()
148 if self.editor.afficheApresInsert == True :
149 #if self.editor.affichePlie==True: nouveau.plieToutEtReaffiche()
150 if self.editor.afficheCommandesPliees ==True: nouveau.plieToutEtReaffiche()
151 else : nouveau.deplieToutEtReaffiche()
152 nouveau.fenetre.donnePremier()
153 #nouveau.deplieToutEtReaffiche()
155 self.node.setSelected(False)
156 nouveau.setSelected(True)
157 self.node.tree.setCurrentItem(nouveau)
161 def creeListeCommande(self,filtre):
162 listeGroupes,dictGroupes=self.jdc.get_groups()
163 sensibleALaCasse=self.RBCasse.isChecked()
164 if "CACHE" in dictGroupes.keys():
165 aExclure=dictGroupes["CACHE"]
169 for l in self.jdc.get_liste_cmd():
170 if l not in aExclure :
171 if sensibleALaCasse and (filtre != None and not filtre in l) : continue
172 if (not sensibleALaCasse) and filtre != None and (not filtre in l) and (not filtre.upper() in l) : continue
173 listeACreer.append(l)
176 def ajouteRadioButtons(self):
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 rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
200 self.buttonGroup.buttonClicked.connect(self.rbClique)
202 self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
203 elif self.affiche_groupe==1 :
204 listeGroupes,dictGroupes=self.jdc.get_groups()
205 for grp in listeGroupes:
206 if grp == "CACHE" : continue
209 text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
211 text=QString.fromUtf8('<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 rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
228 self.buttonGroup.buttonClicked.connect(self.rbClique)
230 self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),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 rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
250 self.buttonGroup.buttonClicked.connect(self.rbClique)
252 self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
256 def clearFiltre(self):
257 self.LEFiltre.setText("")
258 self.ajouteRadioButtons()
260 def rbClique(self,id):
261 self.name=self.dicoCmd[str(id.text())]
262 definitionEtape=getattr(self.jdc.cata[0],self.name)
263 commentaire=getattr(definitionEtape,self.jdc.lang)
265 commentaire=getattr(definitionEtape,self.jdc.lang)
268 commentaire=getattr(definitionEtape,"ang")
271 self.editor.affiche_commentaire(commentaire)
276 #PNPN a priori pas d icone mais peut-etre a faire