1 # Copyright (C) 2007-2013 EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
35 class MonWidgetCommande(Ui_WidgetCommande,Groupe):
38 def __init__(self,node,editor,etape):
39 #print "MonWidgetCommande ", self
40 self.listeAffichageWidget=[]
43 Groupe.__init__(self,node,editor,None,etape.definition,etape,1,self)
45 if node.item.get_fr() != "" : self.labelDoc.setText(QString(node.item.get_fr()))
46 else : self.labelDoc.close()
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("")
52 maPolice= QFont("Times", 10,)
53 self.setFont(maPolice)
54 self.labelNomCommande.setText(tr(self.obj.nom))
56 self.commandesLayout.addStretch()
57 self.commandesLayout.focusInEvent=self.focusInEvent
58 self.scrollAreaCommandes.focusInEvent=self.focusInEvent
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'] :
66 self.connect(self.bAvant,SIGNAL("clicked()"), self.afficheAvant)
67 self.connect(self.bApres,SIGNAL("clicked()"), self.afficheApres)
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)
74 self.setAcceptDrops(True)
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
85 self.monOptionnel=MonWidgetOptionnel(self)
86 self.editor.widgetOptionnel=self.monOptionnel
87 self.editor.splitter.addWidget(self.monOptionnel)
88 self.afficheOptionnel()
89 #print "fin init de widget Commande"
92 def donnePremier(self):
93 #print "dans donnePremier"
95 if self.listeAffichageWidget != [] :
96 self.listeAffichageWidget[0].setFocus(7)
98 #print self.focusWidget()
101 def focusNextPrevChild(self, next):
102 # on s assure que ce n est pas un chgt de fenetre
103 #print "je passe dans focusNextPrevChild"
104 if self.editor.fenetreCentraleAffichee != self : return True
106 if f not in self.listeAffichageWidget :
108 while not hasattr (f,'AAfficher') :
109 if f==None :i=-1; break
111 if hasattr(f,'AAfficher') : f=f.AAfficher
112 if i != -1 : i=self.listeAffichageWidget.index(f)
113 else :i=self.listeAffichageWidget.index(f)
114 if (i==len(self.listeAffichageWidget) -1) and next and not self.inhibe:
116 self.listeAffichageWidget[1].setFocus(7)
119 w.focusPreviousChild()
123 print self.listeAffichageWidget
124 print "souci ds focusNextPrevChild"
125 if i==0 and next==False and not self.inhibe:
126 if hasattr(self.editor.fenetreCentraleAffichee,'scrollArea'):
127 self.editor.fenetreCentraleAffichee.scrollArea.ensureWidgetVisible(self.listeAffichageWidget[-1])
128 self.listeAffichageWidget[-2].setFocus(7)
134 return QWidget.focusNextPrevChild(self, next)
136 def etablitOrdre(self):
138 while(i +1 < len(self.listeAffichageWidget)):
139 self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
141 # si on boucle on perd l'ordre
143 def afficheSuivant(self,f):
145 i=self.listeAffichageWidget.index(f)
149 if (next==len(self.listeAffichageWidget) -1 ): next =0
151 #QTimer.singleShot(1, self.rendVisible)
153 self.listeAffichageWidget[next].setFocus(7)
158 nom = str(self.LENom.text())
159 nom = string.strip(nom)
160 if nom == '' : return # si pas de nom, on ressort sans rien faire
161 test,mess = self.node.item.nomme_sd(nom)
162 self.editor.affiche_commentaire(mess)
164 #Notation scientifique
166 from politiquesValidation import Validation
167 validation=Validation(self.node,self.editor)
168 validation.AjoutDsDictReelEtape()
170 def afficheOptionnel(self):
171 # N a pas de parentQt. doit donc etre redefini
172 liste=self.ajouteMCOptionnelDesBlocs()
173 #print "dans afficheOptionnel", self.monOptionnel
174 # dans le cas ou l insertion n a pas eu leiu (souci d ordre par exemple)
175 #if self.monOptionnel == None : return
176 self.monOptionnel.parentMC=self
177 self.monOptionnel.affiche(liste)
179 #def focusInEvent(self,event):
180 #print "je mets a jour dans focusInEvent de monWidget Commande "
181 # if self.editor.code == "CARMELCND" : return #Pas de MC Optionnels pour Carmel
182 # self.afficheOptionnel()
185 def reaffiche(self,nodeAVoir=None):
186 self.avantH=self.editor.fenetreCentraleAffichee.scrollAreaCommandes.horizontalScrollBar().sliderPosition()
187 self.avantV=self.editor.fenetreCentraleAffichee.scrollAreaCommandes.verticalScrollBar().sliderPosition()
188 self.inhibeExpand=True
189 self.node.affichePanneau()
190 #print "dans reaffiche de monWidgetCommande", self.avantH, self.avantV
191 QTimer.singleShot(1, self.recentre)
192 if nodeAVoir != None:
193 self.f=nodeAVoir.fenetre
195 newNode=nodeAVoir.treeParent.chercheNoeudCorrespondant(nodeAVoir.item.object)
196 self.f = newNode.fenetre
197 print "dans reaffiche",self.f, nodeAVoir.item.nom
198 if self.f != None and self.f.isVisible() : return
199 if self.f != None : QTimer.singleShot(1, self.rendVisible)
200 self.inhibeExpand=False
205 s=self.editor.fenetreCentraleAffichee.scrollAreaCommandes
206 s.horizontalScrollBar().setSliderPosition(self.avantH)
207 s.verticalScrollBar().setSliderPosition(self.avantV)
209 def rendVisibleNoeud(self,node):
211 print "dans rendVisibleNoeud",self.f, node.item.nom
212 QTimer.singleShot(1, self.rendVisible)
214 def rendVisible(self):
217 self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(self.f)
219 def afficheCatalogue(self):
220 if self.editor.widgetOptionnel != None : self.monOptionnel.hide()
221 self.racine.affichePanneau()
222 if self.node : self.node.select()
223 else : self.racine.select()
225 def afficheApres(self):
226 self.node.selectApres()
228 def afficheAvant(self):
229 self.node.selectAvant()
232 if not(hasattr (self,'RBValide')) : return
234 if self.node.item.object.isvalid() :
235 icon=QIcon(self.repIcon+"/ast-green-ball.png")
237 icon=QIcon(self.repIcon+"/ast-red-ball.png")
238 if self.node.item.GetIconName() == "ast-yellow-square" :
239 icon=QIcon(self.repIcon+"/ast-yel-ball.png")
240 self.RBValide.setIcon(icon)