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)
67 self.RBalpha.clicked.connect(self.afficheAlpha)
68 self.RBGroupe.clicked.connect(self.afficheGroupe)
69 self.RBOrdre.clicked.connect(self.afficheOrdre)
70 self.RBClear.clicked.connect(self.clearFiltre)
71 self.RBCasse.toggled.connect(self.ajouteRadioButtons)
72 self.LEFiltre.returnPressed.connect(self.ajouteRadioButtons)
73 self.LEFiltre.textChanged.connect(self.ajouteRadioButtons)
75 self.connect(self.RBalpha,SIGNAL("clicked()"),self.afficheAlpha)
76 self.connect(self.RBGroupe,SIGNAL("clicked()"),self.afficheGroupe)
77 self.connect(self.RBOrdre,SIGNAL("clicked()"),self.afficheOrdre)
78 self.connect(self.RBClear,SIGNAL("clicked()"),self.clearFiltre)
79 self.connect(self.RBCasse,SIGNAL("toggled(bool)"),self.ajouteRadioButtons)
80 self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.ajouteRadioButtons)
81 if self.node.tree.item.get_regles() == () :
83 self.labelRegle.close()
85 if monEnvQT5 : self.RBRegle.clicked.connect(self.afficheRegle)
86 else : self.connect(self.RBRegle,SIGNAL("clicked()"),self.afficheRegle)
88 if self.editor.Ordre_Des_Commandes == None : self.RBOrdre.close()
91 #self.editor.labelCommentaire.setText("")
92 if self.editor.widgetOptionnel!= None :
93 self.editor.fermeOptionnel()
94 self.editor.widgetOptionnel=None
100 if self.editor.affiche=="alpha" :
101 self.affiche_alpha==1;
102 self.RBalpha.setChecked(True);
104 elif self.editor.affiche=="groupe" :
105 self.affiche_groupe==1;
106 self.RBGroupe.setChecked(True);
108 elif self.editor.affiche=="ordre" :
109 self.affiche_ordre==1;
110 self.RBOrdre.setChecked(True);
112 if self.editor.code == "Adao" : self.frameAffichage.close()
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 nodeCourrant=self.node.tree.currentItem()
137 if nodeCourrant==None: nodeCourrant=self.node.tree.racine
138 if self.name != None :
139 plier=self.editor.afficheCommandesPliees
140 if nodeCourrant==self.node : nouveau=self.node.append_child(self.name,'first',plier)
141 else : nouveau=nodeCourrant.append_brother(self.name,plier=plier)
144 if nouveau == 0 : return # on n a pas insere le noeud
146 #if self.editor.afficheApresInsert==True : nouveau.plieToutEtReaffiche()
147 if self.editor.afficheApresInsert == True :
148 #if self.editor.affichePlie==True: nouveau.plieToutEtReaffiche()
149 if self.editor.afficheCommandesPliees ==True: nouveau.plieToutEtReaffiche()
150 else : nouveau.deplieToutEtReaffiche()
151 nouveau.fenetre.donnePremier()
152 #nouveau.deplieToutEtReaffiche()
154 self.node.setSelected(False)
155 nouveau.setSelected(True)
156 self.node.tree.setCurrentItem(nouveau)
160 def creeListeCommande(self,filtre):
161 listeGroupes,dictGroupes=self.jdc.get_groups()
162 sensibleALaCasse=self.RBCasse.isChecked()
163 if "CACHE" in dictGroupes.keys():
164 aExclure=dictGroupes["CACHE"]
168 for l in self.jdc.get_liste_cmd():
169 if l not in aExclure :
170 if sensibleALaCasse and (filtre != None and not filtre in l) : continue
171 if (not sensibleALaCasse) and filtre != None and (not filtre in l) and (not filtre.upper() in l) : continue
172 listeACreer.append(l)
175 def ajouteRadioButtons(self):
176 filtre=str(self.LEFiltre.text())
177 if filtre==str("") : filtre=None
178 if hasattr(self,'buttonGroup') :
179 for b in self.buttonGroup.buttons():
180 self.buttonGroup.removeButton(b)
183 self.buttonGroup = QButtonGroup()
184 for w in self.listeWidget :
187 if self.affiche_alpha==1 :
188 liste=self.creeListeCommande(filtre)
190 self.dicoCmd[tr(cmd)]=cmd
191 rbcmd=(QRadioButton(tr(cmd)))
192 self.buttonGroup.addButton(rbcmd)
193 self.commandesLayout.addWidget(rbcmd)
194 rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
196 self.buttonGroup.buttonClicked.connect(self.rbClique)
198 self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
199 elif self.affiche_groupe==1 :
200 listeGroupes,dictGroupes=self.jdc.get_groups()
201 for grp in listeGroupes:
202 if grp == "CACHE" : continue
205 text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
207 text=QString.fromUtf8('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
209 self.listeWidget.append(label)
211 sensibleALaCasse=self.RBCasse.isChecked()
212 for cmd in dictGroupes[grp]:
213 if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
214 if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
216 self.commandesLayout.addWidget(label)
218 self.dicoCmd[tr(cmd)]=cmd
219 rbcmd=(QRadioButton(tr(cmd)))
220 self.buttonGroup.addButton(rbcmd)
221 self.commandesLayout.addWidget(rbcmd)
222 rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
224 self.buttonGroup.buttonClicked.connect(self.rbClique)
226 self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
229 self.listeWidget.append(label2)
230 self.commandesLayout.addWidget(label2)
231 elif self.affiche_ordre==1 :
232 listeFiltre=self.creeListeCommande(filtre)
234 if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
235 else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
236 for cmd in Ordre_Des_Commandes :
237 if cmd in listeFiltre :
240 self.dicoCmd[tr(cmd)]=cmd
241 rbcmd=(QRadioButton(tr(cmd)))
242 self.buttonGroup.addButton(rbcmd)
243 self.commandesLayout.addWidget(rbcmd)
244 rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
246 self.buttonGroup.buttonClicked.connect(self.rbClique)
248 self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
252 def clearFiltre(self):
253 self.LEFiltre.setText("")
254 self.ajouteRadioButtons()
256 def rbClique(self,id):
257 self.name=self.dicoCmd[str(id.text())]
258 definitionEtape=getattr(self.jdc.cata[0],self.name)
259 commentaire=getattr(definitionEtape,self.jdc.lang)
261 commentaire=getattr(definitionEtape,self.jdc.lang)
264 commentaire=getattr(definitionEtape,"ang")
267 self.editor.affiche_commentaire(commentaire)
272 #PNPN a priori pas d icone mais peut-etre a faire