Salome HOME
mse a jour du 07/03/2016 pour sauvegarde
[tools/eficas.git] / InterfaceQT4 / monChoixCommande.py
1 # Copyright (C) 2007-2013   EDF R&D
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 # Modules Python
20 # Modules Eficas
21
22 from desChoixCommandes import Ui_ChoixCommandes
23 from determine import monEnvQT5
24 if monEnvQT5 :
25    from PyQt5.QtWidgets import QWidget, QAction ,QButtonGroup, QRadioButton, QLabel
26    from PyQt5.QtGui  import QIcon
27    from PyQt5.QtCore import QSize
28 else :
29    from PyQt4.QtGui  import *
30    from PyQt4.QtCore import *
31
32 from Extensions.i18n import tr
33 import os
34
35     
36 # Import des panels
37
38 class MonChoixCommande(Ui_ChoixCommandes,QWidget):
39   """
40   """
41   def __init__(self,node, jdc_item, editor):
42       QWidget.__init__(self,None)
43       self.setupUi(self)
44
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))
50
51       self.item = jdc_item
52       self.node = node
53       self.editor = editor
54       self.jdc  = self.item.object.get_jdc_root()
55       debutTitre=self.editor.titre
56       self.listeWidget=[]
57       self.dicoCmd={}
58       if self.editor.fichier != None : 
59           nouveauTitre=debutTitre+" "+str(os.path.basename(self.editor.fichier))
60       else :
61           nouveauTitre=debutTitre
62       self.editor.appliEficas.setWindowTitle(nouveauTitre)
63
64       #print self.node.tree
65
66       if monEnvQT5 :
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       else :
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() == () :
81          self.RBRegle.close()
82          self.labelRegle.close()
83       else : 
84         if monEnvQT5 : self.RBRegle.clicked.connect(self.afficheRegle)
85         else         : self.connect(self.RBRegle,SIGNAL("clicked()"),self.afficheRegle)
86
87       if self.editor.Ordre_Des_Commandes == None : self.RBOrdre.close()
88
89        
90       #self.editor.labelCommentaire.setText("")
91       if self.editor.widgetOptionnel!= None : 
92          self.editor.widgetOptionnel.close()
93          self.editor.widgetOptionnel=None
94       self.name=None
95
96       self.affiche_alpha=0
97       self.affiche_groupe=0
98       self.affiche_ordre=0
99       if self.editor.affiche=="alpha"  : 
100          self.affiche_alpha==1;  
101          self.RBalpha.setChecked(True);
102          self.afficheAlpha()
103       elif self.editor.affiche=="groupe" : 
104          self.affiche_groupe==1; 
105          self.RBGroupe.setChecked(True); 
106          self.afficheGroupe()
107       elif self.editor.affiche=="ordre"  : 
108          self.affiche_ordre==1;  
109          self.RBOrdre.setChecked(True);  
110          self.afficheOrdre()
111       if self.editor.code == "Adao" : self.frameAffichage.close()
112
113   def afficheRegle(self):
114       self.node.tree.AppelleBuildLBRegles()
115
116   def afficheAlpha(self):
117       self.affiche_alpha=1
118       self.affiche_groupe=0
119       self.affiche_ordre=0
120       self.ajouteRadioButtons()
121
122   def afficheGroupe(self):
123       self.affiche_alpha=0
124       self.affiche_groupe=1
125       self.affiche_ordre=0
126       self.ajouteRadioButtons()
127
128   def afficheOrdre(self):
129       self.affiche_alpha=0
130       self.affiche_groupe=0
131       self.affiche_ordre=1
132       self.ajouteRadioButtons()
133
134   def mouseDoubleClickEvent(self,event):
135       nodeCourrant=self.node.tree.currentItem()
136       if nodeCourrant==None: nodeCourrant=self.node.tree.racine
137       if self.name != None :
138          plier=self.editor.afficheCommandesPliees
139          if nodeCourrant==self.node : nouveau=self.node.append_child(self.name,'first',plier)
140          else : nouveau=nodeCourrant.append_brother(self.name,plier=plier)
141       else :
142          nouveau = 0
143       if nouveau == 0 : return # on n a pas insere le noeud
144       nouveau.setDeplie()
145       #if self.editor.afficheApresInsert==True : nouveau.plieToutEtReaffiche()
146       if self.editor.afficheApresInsert == True :
147            #if self.editor.affichePlie==True:  nouveau.plieToutEtReaffiche()
148            if self.editor.afficheCommandesPliees ==True:  nouveau.plieToutEtReaffiche()
149            else : nouveau.deplieToutEtReaffiche()
150            nouveau.fenetre.donnePremier()
151            #nouveau.deplieToutEtReaffiche()
152       else :
153            self.node.setSelected(False)
154            nouveau.setSelected(True)
155            self.node.tree.setCurrentItem(nouveau)
156       event.accept()
157       
158
159   def creeListeCommande(self,filtre):
160       listeGroupes,dictGroupes=self.jdc.get_groups()
161       sensibleALaCasse=self.RBCasse.isChecked()
162       if "CACHE" in dictGroupes.keys():
163          aExclure=dictGroupes["CACHE"]
164       else:
165          aExclure=()
166       listeACreer=[]
167       for l in self.jdc.get_liste_cmd():
168          if l not in aExclure : 
169             if sensibleALaCasse and (filtre != None and not filtre in l) : continue
170             if (not sensibleALaCasse) and filtre != None and (not filtre in l) and (not filtre.upper() in l) : continue
171             listeACreer.append(l)
172       return listeACreer
173
174   def ajouteRadioButtons(self):
175       filtre=str(self.LEFiltre.text())
176       if filtre==str("") : filtre=None
177       if hasattr(self,'buttonGroup') :
178          for b in self.buttonGroup.buttons():
179              self.buttonGroup.removeButton(b)
180              b.close()
181       else :
182          self.buttonGroup = QButtonGroup()
183       for w in self.listeWidget :
184          w.close()
185       self.listeWidget=[]
186       if self.affiche_alpha==1 :
187          liste=self.creeListeCommande(filtre)
188          for cmd in liste :
189            self.dicoCmd[tr(cmd)]=cmd
190            rbcmd=(QRadioButton(tr(cmd)))
191            self.buttonGroup.addButton(rbcmd)
192            self.commandesLayout.addWidget(rbcmd)
193            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
194            if monEnvQT5:
195               self.buttonGroup.buttonClicked.connect(self.rbClique) 
196            else :
197               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
198       elif  self.affiche_groupe==1 :
199          listeGroupes,dictGroupes=self.jdc.get_groups()
200          for grp in listeGroupes:
201            if grp == "CACHE" : continue
202            label=QLabel(self)
203            if monEnvQT5 :
204               text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
205            else :
206               text=QString.fromUtf8('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
207            label.setText(text)
208            self.listeWidget.append(label)
209            aAjouter=1
210            sensibleALaCasse=self.RBCasse.isChecked()
211            for cmd in  dictGroupes[grp]:
212               if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
213               if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
214               if aAjouter == 1 :
215                  self.commandesLayout.addWidget(label)
216                  aAjouter=0
217               self.dicoCmd[tr(cmd)]=cmd
218               rbcmd=(QRadioButton(tr(cmd)))
219               self.buttonGroup.addButton(rbcmd)
220               self.commandesLayout.addWidget(rbcmd)
221               rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
222               if monEnvQT5:
223                  self.buttonGroup.buttonClicked.connect(self.rbClique) 
224               else :
225                   self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
226            label2=QLabel(self)
227            label2.setText(" ")
228            self.listeWidget.append(label2)
229            self.commandesLayout.addWidget(label2)
230       elif  self.affiche_ordre==1 :
231          listeFiltre=self.creeListeCommande(filtre)
232          liste=[]
233          if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
234          else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
235          for cmd in Ordre_Des_Commandes :
236             if cmd in listeFiltre :
237                  liste.append(cmd)
238          for cmd in liste :
239            self.dicoCmd[tr(cmd)]=cmd
240            rbcmd=(QRadioButton(tr(cmd)))
241            self.buttonGroup.addButton(rbcmd)
242            self.commandesLayout.addWidget(rbcmd)
243            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
244            if monEnvQT5:
245               self.buttonGroup.buttonClicked.connect(self.rbClique) 
246            else :
247               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
248
249      
250
251   def clearFiltre(self):
252       self.LEFiltre.setText("")
253       self.ajouteRadioButtons()
254
255   def rbClique(self,id):
256       self.name=self.dicoCmd[str(id.text())]
257       definitionEtape=getattr(self.jdc.cata[0],self.name)
258       commentaire=getattr(definitionEtape,self.jdc.lang)
259       try :
260         commentaire=getattr(definitionEtape,self.jdc.lang)
261       except :
262         try :
263            commentaire=getattr(definitionEtape,"ang")
264         except :
265            commentaire=""
266       self.editor.affiche_commentaire(commentaire)
267
268
269
270   def setValide(self):
271       #PNPN a priori pas d icone mais peut-etre a faire
272       pass