Salome HOME
3a2977626b6132678e8937ce4e065b704939e943
[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       if self.node.tree.item.get_regles() == () :
59          self.RBRegle.close()
60          self.labelRegle.close()
61       else : self.connect(self.RBRegle,SIGNAL("clicked()"),self.afficheRegle)
62
63       if self.editor.Ordre_Des_Commandes == None : self.RBOrdre.close()
64
65        
66       self.editor.labelCommentaire.setText("")
67       if self.editor.widgetOptionnel!= None : self.editor.widgetOptionnel.close()
68       self.name=None
69       self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.AjouteRadioButton)
70
71       self.affiche_alpha=0
72       self.affiche_groupe=0
73       self.affiche_ordre=0
74       if self.editor.affiche=="alpha"  : 
75          self.affiche_alpha==1;  
76          self.RBalpha.setChecked(True);
77          self.afficheAlpha()
78       elif self.editor.affiche=="groupe" : 
79          self.affiche_groupe==1; 
80          self.RBGroupe.setChecked(True); 
81          self.afficheGroupe()
82       elif self.editor.affiche=="ordre"  : 
83          self.affiche_ordre==1;  
84          self.RBOrdre.setChecked(True);  
85          self.afficheOrdre()
86       if self.editor.code == "Adao" : self.frameAffichage.close()
87
88   def afficheRegle(self):
89       self.node.tree.AppelleBuildLBRegles()
90
91   def afficheAlpha(self):
92       self.affiche_alpha=1
93       self.affiche_groupe=0
94       self.affiche_ordre=0
95       self.AjouteRadioButton()
96
97   def afficheGroupe(self):
98       self.affiche_alpha=0
99       self.affiche_groupe=1
100       self.affiche_ordre=0
101       self.AjouteRadioButton()
102
103   def afficheOrdre(self):
104       self.affiche_alpha=0
105       self.affiche_groupe=0
106       self.affiche_ordre=1
107       self.AjouteRadioButton()
108
109   def mouseDoubleClickEvent(self,event):
110       nodeCourrant=self.node.tree.currentItem()
111       if nodeCourrant==None: nodeCourrant=self.node.tree.racine
112       if self.name != None :
113          plier=self.editor.afficheCommandesPliees
114          if nodeCourrant==self.node : nouveau=self.node.append_child(self.name,'first',plier)
115          else : nouveau=nodeCourrant.append_brother(self.name,plier=plier)
116       if nouveau == 0 : return # on n a pas insere le noeud
117       nouveau.setDeplie()
118       #if self.editor.afficheApresInsert==True : nouveau.plieToutEtReaffiche()
119       if self.editor.afficheApresInsert == True :
120            #if self.editor.affichePlie==True:  nouveau.plieToutEtReaffiche()
121            if self.editor.afficheCommandesPliees ==True:  nouveau.plieToutEtReaffiche()
122            else : nouveau.deplieToutEtReaffiche()
123            nouveau.fenetre.donnePremier()
124            #nouveau.deplieToutEtReaffiche()
125       else :
126            self.node.setSelected(False)
127            nouveau.setSelected(True)
128            self.node.tree.setCurrentItem(nouveau)
129       event.accept()
130       
131
132   def CreeListeCommande(self,filtre):
133       listeGroupes,dictGroupes=self.jdc.get_groups()
134       if "CACHE" in dictGroupes.keys():
135          aExclure=dictGroupes["CACHE"]
136       else:
137          aExclure=()
138       listeACreer=[]
139       for l in self.jdc.get_liste_cmd():
140          if l not in aExclure : 
141             if filtre != None and not filtre in l : continue
142             listeACreer.append(l)
143       return listeACreer
144
145   def AjouteRadioButton(self):
146       filtre=str(self.LEFiltre.text())
147       if filtre==str("") : filtre=None
148       if hasattr(self,'buttonGroup') :
149          for b in self.buttonGroup.buttons():
150              self.buttonGroup.removeButton(b)
151              b.close()
152       else :
153          self.buttonGroup = QButtonGroup()
154       for w in self.listeWidget :
155          w.close()
156       self.listeWidget=[]
157       if self.affiche_alpha==1 :
158          liste=self.CreeListeCommande(filtre)
159          for cmd in liste :
160            rbcmd=(QRadioButton(tr(cmd)))
161            self.buttonGroup.addButton(rbcmd)
162            self.commandesLayout.addWidget(rbcmd)
163            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
164            self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
165       elif  self.affiche_groupe==1 :
166          listeGroupes,dictGroupes=self.jdc.get_groups()
167          for grp in listeGroupes:
168            if grp == "CACHE" : continue
169            label=QLabel(self)
170            text=QString.fromUtf8('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
171            label.setText(text)
172            self.listeWidget.append(label)
173            aAjouter=1
174            for cmd in  dictGroupes[grp]:
175               if filtre != None and not filtre in cmd : continue
176               if aAjouter == 1 :
177                  self.commandesLayout.addWidget(label)
178                  aAjouter=0
179               rbcmd=(QRadioButton(tr(cmd)))
180               self.buttonGroup.addButton(rbcmd)
181               self.commandesLayout.addWidget(rbcmd)
182               rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
183               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
184            label2=QLabel(self)
185            label2.setText(" ")
186            self.listeWidget.append(label2)
187            self.commandesLayout.addWidget(label2)
188       elif  self.affiche_ordre==1 :
189          listeFiltre=self.CreeListeCommande(filtre)
190          liste=[]
191          if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
192          else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
193          for cmd in Ordre_Des_Commandes :
194             if cmd in listeFiltre :
195                  liste.append(cmd)
196          for cmd in liste :
197            rbcmd=(QRadioButton(tr(cmd)))
198            self.buttonGroup.addButton(rbcmd)
199            self.commandesLayout.addWidget(rbcmd)
200            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
201            self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
202
203      
204   def LEfiltreReturnPressed(self):
205       self.AjouteRadioButton(filtre)
206
207
208   def rbClique(self,id):
209       self.name=str(id.text().toLatin1())
210       definitionEtape=getattr(self.jdc.cata[0],self.name)
211       commentaire=getattr(definitionEtape,self.jdc.lang)
212       try :
213         commentaire=getattr(definitionEtape,self.jdc.lang)
214       except :
215         try :
216            commentaire=getattr(definitionEtape,"ang")
217         except :
218            commentaire=""
219       self.editor.labelCommentaire.setText(commentaire)
220
221
222
223   def setValide(self):
224       #PNPN a priori pas d icone mais peut-etre a faire
225       pass