Salome HOME
c51fbb775610ffda67a8bfa82a0235ddc3ddffe8
[tools/eficas.git] / InterfaceQT4 / monWidgetCommande.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 desWidgetCommande import Ui_WidgetCommande
23 from groupe import Groupe
24 from gereIcones import FacultatifOuOptionnel
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27 from Extensions.i18n import tr
28 import Accas 
29 import os
30 import string
31
32     
33 # Import des panels
34
35 class MonWidgetCommande(Ui_WidgetCommande,Groupe):
36   """
37   """
38   def __init__(self,node,editor,etape):
39       #print "MonWidgetCommande ", self
40       self.listeAffichageWidget=[]
41       self.inhibe=0
42       self.ensure=0
43       Groupe.__init__(self,node,editor,None,etape.definition,etape,1,self)
44
45       if node.item.get_fr() != "" : self.labelDoc.setText(QString(node.item.get_fr()))
46       else : self.labelDoc.close()
47       
48       if (etape.get_type_produit()==None): self.LENom.close()
49       elif (hasattr(etape, 'sdnom')) and etape.sdnom != "sansnom" and etape.sdnom != None: self.LENom.setText(etape.sdnom) 
50       else : self.LENom.setText("")
51
52       maPolice= QFont("Times", 10,)
53       self.setFont(maPolice)
54       self.labelNomCommande.setText(tr(self.obj.nom))
55
56       self.commandesLayout.addStretch()
57       self.commandesLayout.focusInEvent=self.focusInEvent
58       self.scrollAreaCommandes.focusInEvent=self.focusInEvent
59
60       if self.editor.code in ['MAP','CARMELCND'] : self.bCatalogue.close()
61       else : self.connect(self.bCatalogue,SIGNAL("clicked()"), self.afficheCatalogue)
62       if self.editor.code in ['Adao','MAP'] : 
63             self.bAvant.close()
64             self.bApres.close()
65       else : 
66             self.connect(self.bAvant,SIGNAL("clicked()"), self.afficheAvant)
67             self.connect(self.bApres,SIGNAL("clicked()"), self.afficheApres)
68       self.connect(self.LENom,SIGNAL("returnPressed()"),self.nomChange)
69       self.racine=self.node.tree.racine
70       if self.node.item.GetIconName() == "ast-red-square" : self.LENom.setDisabled(True)
71
72       self.setAcceptDrops(True)
73       self.etablitOrdre()
74
75       if self.editor.code == "CARMELCND" : 
76          self.RBPoubelle.close() # JDC Fige
77          return                  # Pas de MC Optionnels pour Carmel
78       from monWidgetOptionnel import MonWidgetOptionnel
79       if hasattr(self.editor,'widgetOptionnel') : 
80         self.monOptionnel=self.editor.widgetOptionnel
81       else :
82         self.monOptionnel=MonWidgetOptionnel(self)
83         self.editor.widgetOptionnel=self.monOptionnel
84         self.editor.splitter.addWidget(self.monOptionnel)
85       self.afficheOptionnel()
86       #print "fin init de widget Commande"
87       
88
89   def donnePremier(self):
90       #print "dans donnePremier"
91       qApp.processEvents()
92       if self.listeAffichageWidget != [] :
93          self.listeAffichageWidget[0].setFocus(7)
94       qApp.processEvents()
95       #print self.focusWidget()
96
97
98   def focusNextPrevChild(self, next):
99       # on s assure que ce n est pas un chgt de fenetre
100       #print "je passe dans focusNextPrevChild"
101       if self.editor.fenetreCentraleAffichee != self : return True
102       f=self.focusWidget()
103       if f not in self.listeAffichageWidget :
104          i=0
105          while not hasattr (f,'AAfficher') :
106            if f==None :i=-1; break
107            f=f.parentWidget()
108          if hasattr(f,'AAfficher') : f=f.AAfficher
109          if i != -1 : i=self.listeAffichageWidget.index(f)
110       else :i=self.listeAffichageWidget.index(f) 
111       if (i==len(self.listeAffichageWidget) -1) and next and not self.inhibe: 
112          self.listeAffichageWidget[1].setFocus(7)
113          w=self.focusWidget()
114          self.inhibe=1
115          w.focusPreviousChild()
116          self.inhibe=0
117          return True
118       if i==0 and next==False and not self.inhibe: 
119          if hasattr(self.editor.fenetreCentraleAffichee,'scrollArea'):
120             self.editor.fenetreCentraleAffichee.scrollArea.ensureWidgetVisible(self.listeAffichageWidget[-1])
121          self.listeAffichageWidget[-2].setFocus(7)
122          self.inhibe=1
123          w=self.focusWidget()
124          w.focusNextChild()
125          self.inhibe=0
126          return True
127       return QWidget.focusNextPrevChild(self, next)
128
129   def etablitOrdre(self):
130       i=0
131       while(i +1 < len(self.listeAffichageWidget)):
132          self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
133          i=i+1
134       # si on boucle on perd l'ordre
135  
136   def  afficheSuivant(self,f):
137       try :
138         i=self.listeAffichageWidget.index(f) 
139         next=i+1
140       except :
141         next=1
142       if (next==len(self.listeAffichageWidget) -1 ): next =0
143       #self.f=next
144       #QTimer.singleShot(1, self.rendVisible)
145       self.listeAffichageWidget[next].setFocus(7)
146
147   def nomChange(self):
148       nom = str(self.LENom.text())
149       nom = string.strip(nom)
150       if nom == '' : return                  # si pas de nom, on ressort sans rien faire
151       test,mess = self.node.item.nomme_sd(nom)
152       self.editor.affiche_infos(mess)
153
154       #Notation scientifique
155       if test :
156         from politiquesValidation import Validation
157         validation=Validation(self.node,self.editor)
158         validation.AjoutDsDictReelEtape()
159
160   def afficheOptionnel(self):
161       # N a pas de parentQt. doit donc etre redefini
162       liste=self.ajouteMCOptionnelDesBlocs()
163       #print "dans afficheOptionnel", self.monOptionnel
164       self.monOptionnel.parentMC=self
165       self.monOptionnel.affiche(liste)
166
167   #def focusInEvent(self,event):
168       #print "je mets a jour dans focusInEvent de monWidget Commande "
169   #    if self.editor.code == "CARMELCND" : return #Pas de MC Optionnels pour Carmel
170   #    self.afficheOptionnel()
171
172
173   def reaffiche(self,nodeAVoir=None):
174       self.avantH=self.editor.fenetreCentraleAffichee.scrollAreaCommandes.horizontalScrollBar().sliderPosition()
175       self.avantV=self.editor.fenetreCentraleAffichee.scrollAreaCommandes.verticalScrollBar().sliderPosition()
176       self.inhibeExpand=True
177       self.node.affichePanneau()
178       print "dans reaffiche de monWidgetCommande", self.avantH, self.avantV
179       QTimer.singleShot(1, self.recentre)
180       if nodeAVoir != None:
181         self.f=nodeAVoir.fenetre
182         if self.f==None : 
183              newNode=nodeAVoir.treeParent.chercheNoeudCorrespondant(nodeAVoir.item.object)
184              self.f = newNode.fenetre 
185         print "dans reaffiche",self.f, nodeAVoir.item.nom
186         if self.f != None and self.f.isVisible() : return
187         if self.f != None : QTimer.singleShot(1, self.rendVisible)
188       self.inhibeExpand=False
189
190
191   def recentre(self):
192       qApp.processEvents()
193       s=self.editor.fenetreCentraleAffichee.scrollAreaCommandes
194       s.horizontalScrollBar().setSliderPosition(self.avantH)
195       s.verticalScrollBar().setSliderPosition(self.avantV)
196
197   def rendVisibleNoeud(self,node):
198       self.f=node.fenetre
199       print "dans rendVisibleNoeud",self.f, node.item.nom
200       QTimer.singleShot(1, self.rendVisible)
201      
202   def rendVisible(self):
203       qApp.processEvents()
204       self.f.setFocus(7)
205       self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(self.f)
206
207   def afficheCatalogue(self):
208       if self.editor.code != "CARMELCND" : self.monOptionnel.hide()
209       self.racine.affichePanneau()
210       if self.node : self.node.select()
211       else : self.racine.select()
212
213   def afficheApres(self):
214        self.node.selectApres()
215
216   def afficheAvant(self):
217        self.node.selectAvant()
218
219   def setValide(self):
220       if not(hasattr (self,'RBValide')) : return
221       icon = QIcon()
222       if self.node.item.object.isvalid() :
223          icon=QIcon(self.repIcon+"/ast-green-ball.png")
224       else :
225          icon=QIcon(self.repIcon+"/ast-red-ball.png")
226       if self.node.item.GetIconName() == "ast-yellow-square" :
227          icon=QIcon(self.repIcon+"/ast-yel-ball.png")
228       self.RBValide.setIcon(icon)
229
230