Salome HOME
59cb201eaf8baacb7e88de105572759ddc8f8610
[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 PyQt4  import *
24 from PyQt4.QtCore import *
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27 from Extensions.i18n import tr
28 import os
29
30     
31 # Import des panels
32
33 class MonChoixCommande(Ui_ChoixCommandes,QtGui.QWidget):
34   """
35   """
36   def __init__(self,node, jdc_item, editor):
37       QtGui.QWidget.__init__(self,None)
38       self.setupUi(self)
39       #self.labelIcone.setText('<img src="/local00/home/A96028/Install_EficasV1/KarineEficas/InterfaceQT4/loopOff.png">');
40
41       self.item = jdc_item
42       self.node = node
43       self.editor = editor
44       self.jdc  = self.item.object.get_jdc_root()
45       debutTitre=self.editor.titre
46       self.listeWidget=[]
47       if self.editor.fichier != None : 
48           nouveauTitre=debutTitre+" "+str(os.path.basename(self.editor.fichier))
49       else :
50           nouveauTitre=debutTitre
51       self.editor.appliEficas.setWindowTitle(nouveauTitre)
52
53       #print self.node.tree
54
55       self.connect(self.RBalpha,SIGNAL("clicked()"),self.afficheAlpha)
56       self.connect(self.RBGroupe,SIGNAL("clicked()"),self.afficheGroupe)
57       self.connect(self.RBOrdre,SIGNAL("clicked()"),self.afficheOrdre)
58       self.connect(self.RBClear,SIGNAL("clicked()"),self.clearFiltre)
59       self.connect(self.RBCasse,SIGNAL("toggled(bool)"),self.ajouteRadioButtons)
60       if self.node.tree.item.get_regles() == () :
61          self.RBRegle.close()
62          self.labelRegle.close()
63       else : self.connect(self.RBRegle,SIGNAL("clicked()"),self.afficheRegle)
64
65       if self.editor.Ordre_Des_Commandes == None : self.RBOrdre.close()
66
67        
68       self.editor.labelCommentaire.setText("")
69       if self.editor.widgetOptionnel!= None : 
70          self.editor.widgetOptionnel.close()
71          self.editor.widgetOptionnel=None
72       self.name=None
73       self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.ajouteRadioButtons)
74
75       self.affiche_alpha=0
76       self.affiche_groupe=0
77       self.affiche_ordre=0
78       if self.editor.affiche=="alpha"  : 
79          self.affiche_alpha==1;  
80          self.RBalpha.setChecked(True);
81          self.afficheAlpha()
82       elif self.editor.affiche=="groupe" : 
83          self.affiche_groupe==1; 
84          self.RBGroupe.setChecked(True); 
85          self.afficheGroupe()
86       elif self.editor.affiche=="ordre"  : 
87          self.affiche_ordre==1;  
88          self.RBOrdre.setChecked(True);  
89          self.afficheOrdre()
90       if self.editor.code == "Adao" : self.frameAffichage.close()
91
92   def afficheRegle(self):
93       self.node.tree.AppelleBuildLBRegles()
94
95   def afficheAlpha(self):
96       self.affiche_alpha=1
97       self.affiche_groupe=0
98       self.affiche_ordre=0
99       self.ajouteRadioButtons()
100
101   def afficheGroupe(self):
102       self.affiche_alpha=0
103       self.affiche_groupe=1
104       self.affiche_ordre=0
105       self.ajouteRadioButtons()
106
107   def afficheOrdre(self):
108       self.affiche_alpha=0
109       self.affiche_groupe=0
110       self.affiche_ordre=1
111       self.ajouteRadioButtons()
112
113   def mouseDoubleClickEvent(self,event):
114       nodeCourrant=self.node.tree.currentItem()
115       if nodeCourrant==None: nodeCourrant=self.node.tree.racine
116       if self.name != None :
117          plier=self.editor.afficheCommandesPliees
118          if nodeCourrant==self.node : nouveau=self.node.append_child(self.name,'first',plier)
119          else : nouveau=nodeCourrant.append_brother(self.name,plier=plier)
120       else :
121          nouveau = 0
122       if nouveau == 0 : return # on n a pas insere le noeud
123       nouveau.setDeplie()
124       #if self.editor.afficheApresInsert==True : nouveau.plieToutEtReaffiche()
125       if self.editor.afficheApresInsert == True :
126            #if self.editor.affichePlie==True:  nouveau.plieToutEtReaffiche()
127            if self.editor.afficheCommandesPliees ==True:  nouveau.plieToutEtReaffiche()
128            else : nouveau.deplieToutEtReaffiche()
129            nouveau.fenetre.donnePremier()
130            #nouveau.deplieToutEtReaffiche()
131       else :
132            self.node.setSelected(False)
133            nouveau.setSelected(True)
134            self.node.tree.setCurrentItem(nouveau)
135       event.accept()
136       
137
138   def creeListeCommande(self,filtre):
139       listeGroupes,dictGroupes=self.jdc.get_groups()
140       sensibleALaCasse=self.RBCasse.isChecked()
141       if "CACHE" in dictGroupes.keys():
142          aExclure=dictGroupes["CACHE"]
143       else:
144          aExclure=()
145       listeACreer=[]
146       for l in self.jdc.get_liste_cmd():
147          if l not in aExclure : 
148             if sensibleALaCasse and (filtre != None and not filtre in l) : continue
149             if (not sensibleALaCasse) and filtre != None and (not filtre in l) and (not filtre.upper() in l) : continue
150             listeACreer.append(l)
151       return listeACreer
152
153   def ajouteRadioButtons(self):
154       filtre=str(self.LEFiltre.text())
155       if filtre==str("") : filtre=None
156       if hasattr(self,'buttonGroup') :
157          for b in self.buttonGroup.buttons():
158              self.buttonGroup.removeButton(b)
159              b.close()
160       else :
161          self.buttonGroup = QButtonGroup()
162       for w in self.listeWidget :
163          w.close()
164       self.listeWidget=[]
165       if self.affiche_alpha==1 :
166          liste=self.creeListeCommande(filtre)
167          for cmd in liste :
168            rbcmd=(QRadioButton(tr(cmd)))
169            self.buttonGroup.addButton(rbcmd)
170            self.commandesLayout.addWidget(rbcmd)
171            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
172            self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
173       elif  self.affiche_groupe==1 :
174          listeGroupes,dictGroupes=self.jdc.get_groups()
175          for grp in listeGroupes:
176            if grp == "CACHE" : continue
177            label=QLabel(self)
178            text=QString.fromUtf8('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
179            label.setText(text)
180            self.listeWidget.append(label)
181            aAjouter=1
182            sensibleALaCasse=self.RBCasse.isChecked()
183            for cmd in  dictGroupes[grp]:
184               if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
185               if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
186               if aAjouter == 1 :
187                  self.commandesLayout.addWidget(label)
188                  aAjouter=0
189               rbcmd=(QRadioButton(tr(cmd)))
190               self.buttonGroup.addButton(rbcmd)
191               self.commandesLayout.addWidget(rbcmd)
192               rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
193               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
194            label2=QLabel(self)
195            label2.setText(" ")
196            self.listeWidget.append(label2)
197            self.commandesLayout.addWidget(label2)
198       elif  self.affiche_ordre==1 :
199          listeFiltre=self.creeListeCommande(filtre)
200          liste=[]
201          if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
202          else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
203          for cmd in Ordre_Des_Commandes :
204             if cmd in listeFiltre :
205                  liste.append(cmd)
206          for cmd in liste :
207            rbcmd=(QRadioButton(tr(cmd)))
208            self.buttonGroup.addButton(rbcmd)
209            self.commandesLayout.addWidget(rbcmd)
210            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
211            self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
212
213      
214
215   def clearFiltre(self):
216       self.LEFiltre.setText("")
217       self.ajouteRadioButtons()
218
219   def rbClique(self,id):
220       self.name=str(id.text().toLatin1())
221       definitionEtape=getattr(self.jdc.cata[0],self.name)
222       commentaire=getattr(definitionEtape,self.jdc.lang)
223       try :
224         commentaire=getattr(definitionEtape,self.jdc.lang)
225       except :
226         try :
227            commentaire=getattr(definitionEtape,"ang")
228         except :
229            commentaire=""
230       self.editor.labelCommentaire.setText(commentaire)
231
232
233
234   def setValide(self):
235       #PNPN a priori pas d icone mais peut-etre a faire
236       pass