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