Salome HOME
except et print
[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
65       if monEnvQT5 :
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)
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.fermeOptionnel()
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.closeFrameRechercheCommande == True : self.frameAffichage.close()
112       self.editor.restoreSplitterSizes(2) 
113
114   def afficheRegle(self):
115       self.node.tree.AppelleBuildLBRegles()
116
117   def afficheAlpha(self):
118       self.affiche_alpha=1
119       self.affiche_groupe=0
120       self.affiche_ordre=0
121       self.ajouteRadioButtons()
122
123   def afficheGroupe(self):
124       self.affiche_alpha=0
125       self.affiche_groupe=1
126       self.affiche_ordre=0
127       self.ajouteRadioButtons()
128
129   def afficheOrdre(self):
130       self.affiche_alpha=0
131       self.affiche_groupe=0
132       self.affiche_ordre=1
133       self.ajouteRadioButtons()
134
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)
144       else :
145          nouveau = 0
146       if nouveau == 0 : return # on n a pas insere le noeud
147       nouveau.setDeplie()
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()
155       else :
156            self.node.setSelected(False)
157            nouveau.setSelected(True)
158            self.node.tree.setCurrentItem(nouveau)
159       event.accept()
160       
161          
162
163   def creeListeCommande(self,filtre):
164       listeGroupes,dictGroupes=self.jdc.get_groups()
165       sensibleALaCasse=self.RBCasse.isChecked()
166       if "CACHE" in dictGroupes.keys():
167          aExclure=dictGroupes["CACHE"]
168       else:
169          aExclure=()
170       listeACreer=[]
171       for l in self.jdc.get_liste_cmd():
172          if l not in aExclure : 
173             if sensibleALaCasse and (filtre != None and not filtre in l) : continue
174             if (not sensibleALaCasse) and filtre != None and (not filtre in l) and (not filtre.upper() in l) : continue
175             listeACreer.append(l)
176       return listeACreer
177
178   def ajouteRadioButtons(self):
179       #print 'ds ajouteRadioButtons'
180       filtre=str(self.LEFiltre.text())
181       if filtre==str("") : filtre=None
182       if hasattr(self,'buttonGroup') :
183          for b in self.buttonGroup.buttons():
184              self.buttonGroup.removeButton(b)
185              b.setParent(None)
186              b.close()
187       else :
188          self.buttonGroup = QButtonGroup()
189       for w in self.listeWidget :
190          w.setParent(None)
191          w.close()
192       self.listeWidget=[]
193       if self.affiche_alpha==1 :
194          liste=self.creeListeCommande(filtre)
195          for cmd in liste :
196            self.dicoCmd[tr(cmd)]=cmd
197            rbcmd=(QRadioButton(tr(cmd)))
198            self.buttonGroup.addButton(rbcmd)
199            self.commandesLayout.addWidget(rbcmd)
200            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
201            if monEnvQT5:
202               self.buttonGroup.buttonClicked.connect(self.rbClique) 
203            else :
204               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
205       elif  self.affiche_groupe==1 :
206          listeGroupes,dictGroupes=self.jdc.get_groups()
207          for grp in listeGroupes:
208            if grp == "CACHE" : continue
209            label=QLabel(self)
210            if monEnvQT5 :
211               text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
212            else :
213               text=QString.fromUtf8('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
214            label.setText(text)
215            self.listeWidget.append(label)
216            aAjouter=1
217            sensibleALaCasse=self.RBCasse.isChecked()
218            for cmd in  dictGroupes[grp]:
219               if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
220               if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
221               if aAjouter == 1 :
222                  self.commandesLayout.addWidget(label)
223                  aAjouter=0
224               self.dicoCmd[tr(cmd)]=cmd
225               rbcmd=(QRadioButton(tr(cmd)))
226               self.buttonGroup.addButton(rbcmd)
227               self.commandesLayout.addWidget(rbcmd)
228               rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
229               if monEnvQT5:
230                  self.buttonGroup.buttonClicked.connect(self.rbClique) 
231               else :
232                   self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
233            label2=QLabel(self)
234            label2.setText(" ")
235            self.listeWidget.append(label2)
236            self.commandesLayout.addWidget(label2)
237       elif  self.affiche_ordre==1 :
238          listeFiltre=self.creeListeCommande(filtre)
239          liste=[]
240          if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
241          else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
242          for cmd in Ordre_Des_Commandes :
243             if cmd in listeFiltre :
244                  liste.append(cmd)
245          for cmd in liste :
246            self.dicoCmd[tr(cmd)]=cmd
247            rbcmd=(QRadioButton(tr(cmd)))
248            self.buttonGroup.addButton(rbcmd)
249            self.commandesLayout.addWidget(rbcmd)
250            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
251            if monEnvQT5:
252               self.buttonGroup.buttonClicked.connect(self.rbClique) 
253            else :
254               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
255
256      
257
258   def clearFiltre(self):
259       self.LEFiltre.setText("")
260       self.ajouteRadioButtons()
261
262   def rbClique(self,id):
263       self.name=self.dicoCmd[str(id.text())]
264       definitionEtape=getattr(self.jdc.cata[0],self.name)
265       commentaire=getattr(definitionEtape,self.jdc.lang)
266       try :
267         commentaire=getattr(definitionEtape,self.jdc.lang)
268       except :
269         try :
270            commentaire=getattr(definitionEtape,"ang")
271         except :
272            commentaire=""
273       self.editor.affiche_commentaire(commentaire)
274
275
276
277   def setValide(self):
278       #PNPN a priori pas d icone mais peut-etre a faire
279       pass