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