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)
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 self.connect(self.RBalpha,SIGNAL("clicked()"),self.afficheAlpha)
75 self.connect(self.RBGroupe,SIGNAL("clicked()"),self.afficheGroupe)
76 self.connect(self.RBOrdre,SIGNAL("clicked()"),self.afficheOrdre)
77 self.connect(self.RBClear,SIGNAL("clicked()"),self.clearFiltre)
78 self.connect(self.RBCasse,SIGNAL("toggled(bool)"),self.ajouteRadioButtons)
79 self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.ajouteRadioButtons)
80 if self.node.tree.item.get_regles() == () :
82 self.labelRegle.close()
84 if monEnvQT5 : self.RBRegle.clicked.connect(self.afficheRegle)
85 else : self.connect(self.RBRegle,SIGNAL("clicked()"),self.afficheRegle)
87 if self.editor.Ordre_Des_Commandes == None : self.RBOrdre.close()
90 #self.editor.labelCommentaire.setText("")
91 if self.editor.widgetOptionnel!= None :
92 self.editor.fermeOptionnel()
93 self.editor.widgetOptionnel=None
99 if self.editor.affiche=="alpha" :
100 self.affiche_alpha==1;
101 self.RBalpha.setChecked(True);
103 elif self.editor.affiche=="groupe" :
104 self.affiche_groupe==1;
105 self.RBGroupe.setChecked(True);
107 elif self.editor.affiche=="ordre" :
108 self.affiche_ordre==1;
109 self.RBOrdre.setChecked(True);
111 if self.editor.closeFrameRechercheCommande == True : self.frameAffichage.close()
112 self.editor.restoreSplitterSizes(2)
114 def afficheRegle(self):
115 self.node.tree.AppelleBuildLBRegles()
117 def afficheAlpha(self):
119 self.affiche_groupe=0
121 self.ajouteRadioButtons()
123 def afficheGroupe(self):
125 self.affiche_groupe=1
127 self.ajouteRadioButtons()
129 def afficheOrdre(self):
131 self.affiche_groupe=0
133 self.ajouteRadioButtons()
135 def mouseDoubleClickEvent(self,event):
136 #print self.editor.Classement_Commandes_Ds_Arbre
137 if self.editor.Classement_Commandes_Ds_Arbre!= () : self.chercheOu()
138 nodeCourrant=self.node.tree.currentItem()
139 if nodeCourrant==None: nodeCourrant=self.node.tree.racine
140 if self.name != None :
141 plier=self.editor.afficheCommandesPliees
142 if nodeCourrant==self.node : nouveau=self.node.append_child(self.name,'first',plier)
143 else : nouveau=nodeCourrant.append_brother(self.name,plier=plier)
146 if nouveau == 0 : return # on n a pas insere le noeud
148 #if self.editor.afficheApresInsert==True : nouveau.plieToutEtReaffiche()
149 if self.editor.afficheApresInsert == True :
150 #if self.editor.affichePlie==True: nouveau.plieToutEtReaffiche()
151 if self.editor.afficheCommandesPliees ==True: nouveau.plieToutEtReaffiche()
152 else : nouveau.deplieToutEtReaffiche()
153 nouveau.fenetre.donnePremier()
154 #nouveau.deplieToutEtReaffiche()
156 self.node.setSelected(False)
157 nouveau.setSelected(True)
158 self.node.tree.setCurrentItem(nouveau)
162 if self.node.tree.racine.childrenComplete==[] : return None
164 for node in self.node.tree.racine.childrenComplete :
165 listeNoeud.append(node.item.object.nom)
167 indexStop=self.editor.Classement_Commandes_Ds_Arbre.index(self.name)
168 for commande in self.editor.Classement_Commandes_Ds_Arbre[:indexStop]:
169 if commande in listeNoeud: indexAvant=indexAvant+1
170 if indexAvant==-1 : self.node.tree.setCurrentItem(None)
172 nodeASelectionner=self.node.tree.racine.childrenComplete[indexAvant]
173 self.node.tree.setCurrentItem(nodeASelectionner)
176 def creeListeCommande(self,filtre):
177 listeGroupes,dictGroupes=self.jdc.get_groups()
178 sensibleALaCasse=self.RBCasse.isChecked()
179 if "CACHE" in dictGroupes.keys():
180 aExclure=dictGroupes["CACHE"]
184 for l in self.jdc.get_liste_cmd():
185 if l not in aExclure :
186 if sensibleALaCasse and (filtre != None and not filtre in l) : continue
187 if (not sensibleALaCasse) and filtre != None and (not filtre in l) and (not filtre.upper() in l) : continue
188 listeACreer.append(l)
191 def ajouteRadioButtons(self):
192 #print 'ds ajouteRadioButtons'
193 filtre=str(self.LEFiltre.text())
194 if filtre==str("") : filtre=None
195 if hasattr(self,'buttonGroup') :
196 for b in self.buttonGroup.buttons():
197 self.buttonGroup.removeButton(b)
201 self.buttonGroup = QButtonGroup()
202 for w in self.listeWidget :
206 if self.affiche_alpha==1 :
207 liste=self.creeListeCommande(filtre)
209 self.dicoCmd[tr(cmd)]=cmd
210 rbcmd=(QRadioButton(tr(cmd)))
211 self.buttonGroup.addButton(rbcmd)
212 self.commandesLayout.addWidget(rbcmd)
213 rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
215 self.buttonGroup.buttonClicked.connect(self.rbClique)
217 self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
218 elif self.affiche_groupe==1 :
219 listeGroupes,dictGroupes=self.jdc.get_groups()
220 for grp in listeGroupes:
221 if grp == "CACHE" : continue
224 text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
226 text=QString.fromUtf8('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
228 self.listeWidget.append(label)
230 sensibleALaCasse=self.RBCasse.isChecked()
231 for cmd in dictGroupes[grp]:
232 if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
233 if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
235 self.commandesLayout.addWidget(label)
237 self.dicoCmd[tr(cmd)]=cmd
238 rbcmd=(QRadioButton(tr(cmd)))
239 self.buttonGroup.addButton(rbcmd)
240 self.commandesLayout.addWidget(rbcmd)
241 rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
243 self.buttonGroup.buttonClicked.connect(self.rbClique)
245 self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
248 self.listeWidget.append(label2)
249 self.commandesLayout.addWidget(label2)
250 elif self.affiche_ordre==1 :
251 listeFiltre=self.creeListeCommande(filtre)
253 if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
254 else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
255 for cmd in Ordre_Des_Commandes :
256 if cmd in listeFiltre :
259 self.dicoCmd[tr(cmd)]=cmd
260 rbcmd=(QRadioButton(tr(cmd)))
261 self.buttonGroup.addButton(rbcmd)
262 self.commandesLayout.addWidget(rbcmd)
263 rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
265 self.buttonGroup.buttonClicked.connect(self.rbClique)
267 self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
271 def clearFiltre(self):
272 self.LEFiltre.setText("")
273 self.ajouteRadioButtons()
275 def rbClique(self,id):
276 self.name=self.dicoCmd[str(id.text())]
277 definitionEtape=getattr(self.jdc.cata[0],self.name)
278 commentaire=getattr(definitionEtape,self.jdc.lang)
280 commentaire=getattr(definitionEtape,self.jdc.lang)
283 commentaire=getattr(definitionEtape,"ang")
286 self.editor.affiche_commentaire(commentaire)
291 #PNPN a priori pas d icone mais peut-etre a faire