Salome HOME
6dd35550d967f850437c7db23536c5a9a3ae5cf7
[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       if self.editor.widgetTree != None:
46          self.connect(self.bFormulaire,SIGNAL("clicked()"),self.bFormulaireReturnPressed)
47       else :
48          self.bFormulaire.close()
49       debutTitre=self.editor.titre
50       self.listeWidget=[]
51       if self.editor.fichier != None : 
52           nouveauTitre=debutTitre+" "+str(os.path.basename(self.editor.fichier))
53       else :
54           nouveauTitre=debutTitre
55       self.editor.appliEficas.setWindowTitle(nouveauTitre)
56       self.connect(self.RBalpha,SIGNAL("clicked()"),self.afficheAlpha)
57       self.connect(self.RBGroupe,SIGNAL("clicked()"),self.afficheGroupe)
58       self.editor.labelCommentaire.setText("")
59       self.affiche_alpha=self.editor.affiche_alpha
60       self.name=None
61       self.AjouteRadioButton()
62       self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.AjouteRadioButton)
63
64   def afficheAlpha(self):
65       self.affiche_alpha=1
66       self.editor.affiche_alpha=1
67       self.AjouteRadioButton()
68
69   def afficheGroupe(self):
70       self.affiche_alpha=0
71       self.editor.affiche_alpha=0
72       self.AjouteRadioButton()
73
74   def bFormulaireReturnPressed(self):
75       print "PNPNPNPN a Programmer" 
76       self.connect(self.bFormulaire,SIGNAL("clicked()"),self.bFormulaireReturnPressed)
77
78   def mouseDoubleClickEvent(self,event):
79       nodeCourrant=self.node.tree.currentItem()
80       if nodeCourrant==None: nodeCourrant=self.node.tree.racine
81       if self.name != None :
82          if nodeCourrant==self.node : nouveau=self.node.append_child(self.name,'first')
83          else : nouveau=nodeCourrant.append_brother(self.name)
84          print "je suis la"
85          from InterfaceQT4 import compojdc
86          if self.editor.afficheCommandesPliees==True and isinstance(nouveau.treeParent,compojdc.Node) :
87             nouveau.plieToutEtReaffiche()
88
89   def CreeListeCommande(self,filtre):
90       listeGroupes,dictGroupes=self.jdc.get_groups()
91       if "CACHE" in dictGroupes.keys():
92          aExclure=dictGroupes["CACHE"]
93       else:
94          aExclure=()
95       listeACreer=[]
96       for l in self.jdc.get_liste_cmd():
97          if l not in aExclure : 
98             if filtre != None and not filtre in l : continue
99             listeACreer.append(l)
100       return listeACreer
101
102   def AjouteRadioButton(self):
103       filtre=str(self.LEFiltre.text())
104       if filtre==str("") : filtre=None
105       if hasattr(self,'buttonGroup') :
106          for b in self.buttonGroup.buttons():
107              self.buttonGroup.removeButton(b)
108              b.close()
109       else :
110          self.buttonGroup = QButtonGroup()
111       for w in self.listeWidget :
112          w.close()
113       self.listeWidget=[]
114       if self.affiche_alpha==1 :
115          liste=self.CreeListeCommande(filtre)
116          for cmd in liste :
117            rbcmd=(QRadioButton(tr(cmd)))
118            self.buttonGroup.addButton(rbcmd)
119            self.commandesLayout.addWidget(rbcmd)
120            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
121            self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
122       else :
123          listeGroupes,dictGroupes=self.jdc.get_groups()
124          for grp in listeGroupes:
125            if grp == "CACHE" : continue
126            label=QLabel(self)
127            text=QString.fromUtf8('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
128            label.setText(text)
129            self.listeWidget.append(label)
130            aAjouter=1
131            for cmd in  dictGroupes[grp]:
132               if filtre != None and not filtre in cmd : continue
133               if aAjouter == 1 :
134                  self.commandesLayout.addWidget(label)
135                  aAjouter=0
136               rbcmd=(QRadioButton(tr(cmd)))
137               self.buttonGroup.addButton(rbcmd)
138               self.commandesLayout.addWidget(rbcmd)
139               rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
140               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
141            label2=QLabel(self)
142            label2.setText(" ")
143            self.listeWidget.append(label2)
144            self.commandesLayout.addWidget(label2)
145
146      
147   def LEfiltreReturnPressed(self):
148       self.AjouteRadioButton(filtre)
149
150
151   def rbClique(self,id):
152       self.name=str(id.text().toLatin1())
153       definitionEtape=getattr(self.jdc.cata[0],self.name)
154       commentaire=getattr(definitionEtape,self.jdc.lang)
155       try :
156         commentaire=getattr(definitionEtape,self.jdc.lang)
157       except :
158         try :
159            commentaire=getattr(definitionEtape,"ang")
160         except :
161            commentaire=""
162       self.editor.labelCommentaire.setText(commentaire)
163
164   def bOkPressed(self):
165       if self.name==None :  
166          QMessageBox.critical(None, tr("Commande non choisie "),
167                      tr("Vous devez choisir une commande") )
168          return
169       #new_node = self.node.append_child(self.name,'first')
170       self.node.tree.choisitPremier(self.name)
171
172
173   def setValide(self):
174       #PNPN a priori pas d icone mais peut-etre a faire
175       pass