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