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 determine import monEnvQT5
28 from PyQt5.QtWidgets import QApplication, QWidget, QSpacerItem, QSizePolicy
29 from PyQt5.QtGui import QFont, QIcon
30 from PyQt5.QtCore import QTimer
32 from PyQt4.QtGui import *
33 from PyQt4.QtCore import *
36 from Extensions.i18n import tr
44 class MonWidgetCommande(Ui_WidgetCommande,Groupe):
47 def __init__(self,node,editor,etape):
48 self.listeAffichageWidget=[]
51 editor.inhibeSplitter=1
52 Groupe.__init__(self,node,editor,None,etape.definition,etape,1,self)
53 editor.inhibeSplitter=0
55 self.frameAffichage.setMinimumHeight(20)
56 if node.item.get_fr() != "" : self.labelDoc.setText(node.item.get_fr())
59 self.frameAffichage.resize(self.frameAffichage.width(),50)
61 #if (etape.get_type_produit()==None): self.LENom.close()
62 if not(hasattr(etape.definition,'sd_prod')) or (etape.definition.sd_prod==None): self.LENom.close()
63 elif (hasattr(etape, 'sdnom')) and etape.sdnom != "sansnom" and etape.sdnom != None: self.LENom.setText(etape.sdnom)
64 else : self.LENom.setText("")
67 maPolice= QFont("Times", 10,)
68 self.setFont(maPolice)
69 self.labelNomCommande.setText(tr(self.obj.nom))
71 self.commandesLayout.addStretch()
72 self.commandesLayout.focusInEvent=self.focusInEvent
73 self.scrollAreaCommandes.focusInEvent=self.focusInEvent
76 if self.editor.closeFrameRechercheCommande==True : self.closeAutreCommande()
80 self.bCatalogue.clicked.connect(self.afficheCatalogue)
81 self.bAvant.clicked.connect(self.afficheAvant)
82 self.bApres.clicked.connect(self.afficheApres)
85 self.LENom.returnPressed.connect(self.nomChange)
88 self.connect(self.bCatalogue,SIGNAL("clicked()"), self.afficheCatalogue)
89 self.connect(self.bAvant,SIGNAL("clicked()"), self.afficheAvant)
90 self.connect(self.bApres,SIGNAL("clicked()"), self.afficheApres)
93 self.connect(self.LENom,SIGNAL("returnPressed()"),self.nomChange)
95 if self.editor.code in ['CARMELCND',] : self.closeAutreCommande()
96 self.racine=self.node.tree.racine
97 if self.node.item.GetIconName() == "ast-red-square" : self.LENom.setDisabled(True)
99 self.setAcceptDrops(True)
102 if self.editor.code == "CARMELCND" :
103 self.RBPoubelle.close() # JDC Fige
104 return # Pas de MC Optionnels pour Carmel
106 from monWidgetOptionnel import MonWidgetOptionnel
107 if self.editor.widgetOptionnel!= None :
108 self.monOptionnel=self.editor.widgetOptionnel
110 self.monOptionnel=MonWidgetOptionnel(self)
111 self.editor.widgetOptionnel=self.monOptionnel
112 self.editor.inhibeSplitter=1
113 self.editor.splitter.addWidget(self.monOptionnel)
114 self.editor.inhibeSplitter=0
115 self.editor.ajoutOptionnel()
116 self.afficheOptionnel()
118 self.editor.restoreSplitterSizes()
119 #print "fin init de widget Commande"
121 def closeAutreCommande(self):
122 self.bCatalogue.close()
126 def donnePremier(self):
127 #print "dans donnePremier"
128 QApplication.processEvents()
129 if self.listeAffichageWidget != [] :
130 self.listeAffichageWidget[0].setFocus(7)
131 QApplication.processEvents()
132 #print self.focusWidget()
135 def focusNextPrevChild(self, next):
136 # on s assure que ce n est pas un chgt de fenetre
137 #print "je passe dans focusNextPrevChild"
138 if self.editor.fenetreCentraleAffichee != self : return True
140 if f not in self.listeAffichageWidget :
142 while not hasattr (f,'AAfficher') :
143 if f==None :i=-1; break
145 if hasattr(f,'AAfficher') : f=f.AAfficher
146 if i != -1 : i=self.listeAffichageWidget.index(f)
147 else :i=self.listeAffichageWidget.index(f)
148 if (i==len(self.listeAffichageWidget) -1) and next and not self.inhibe:
150 self.listeAffichageWidget[1].setFocus(7)
153 w.focusPreviousChild()
158 #print self.listeAffichageWidget
159 #print "souci ds focusNextPrevChild"
160 if i==0 and next==False and not self.inhibe:
161 if hasattr(self.editor.fenetreCentraleAffichee,'scrollArea'):
162 self.editor.fenetreCentraleAffichee.scrollArea.ensureWidgetVisible(self.listeAffichageWidget[-1])
163 self.listeAffichageWidget[-2].setFocus(7)
169 if i==0 and next==True and not self.inhibe:
170 self.listeAffichageWidget[0].setFocus(7)
176 if i>0 and next==False and not self.inhibe:
177 if isinstance(self.listeAffichageWidget[i-1],QRadioButton):
178 self.listeAffichageWidget[i-1].setFocus(7)
180 return QWidget.focusNextPrevChild(self, next)
182 def etablitOrdre(self):
184 while(i +1 < len(self.listeAffichageWidget)):
185 self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
187 # si on boucle on perd l'ordre
189 def afficheSuivant(self,f):
191 i=self.listeAffichageWidget.index(f)
195 if (next==len(self.listeAffichageWidget) -1 ): next =0
197 #QTimer.singleShot(1, self.rendVisible)
199 self.listeAffichageWidget[next].setFocus(7)
204 nom = str(self.LENom.text())
205 nom = string.strip(nom)
206 if nom == '' : return # si pas de nom, on ressort sans rien faire
207 test,mess = self.node.item.nomme_sd(nom)
208 self.editor.affiche_commentaire(mess)
210 #Notation scientifique
212 from politiquesValidation import Validation
213 validation=Validation(self.node,self.editor)
214 validation.AjoutDsDictReelEtape()
216 def afficheOptionnel(self):
217 # N a pas de parentQt. doit donc etre redefini
218 liste=self.ajouteMCOptionnelDesBlocs()
219 #print "dans afficheOptionnel", self.monOptionnel
220 # dans le cas ou l insertion n a pas eu leiu (souci d ordre par exemple)
221 #if self.monOptionnel == None : return
222 self.monOptionnel.parentCommande=self
223 self.monOptionnel.titre(self.obj.nom)
224 self.monGroupe=self.monOptionnel.afficheOptionnel(liste,self)
227 #def focusInEvent(self,event):
228 #print "je mets a jour dans focusInEvent de monWidget Commande "
229 # if self.editor.code == "CARMELCND" : return #Pas de MC Optionnels pour Carmel
230 # self.afficheOptionnel()
233 def reaffiche(self,nodeAVoir=None):
234 # Attention delicat. les appels de fonctions ne semblent pas pouvoir etre supprimes!
235 self.avantH=self.editor.fenetreCentraleAffichee.scrollAreaCommandes.horizontalScrollBar().sliderPosition()
236 self.avantV=self.editor.fenetreCentraleAffichee.scrollAreaCommandes.verticalScrollBar().sliderPosition()
237 self.inhibeExpand=True
238 self.node.affichePanneau()
239 #QTimer.singleShot(1, self.recentre)
240 if nodeAVoir != None and nodeAVoir!=0:
241 self.f=nodeAVoir.fenetre
243 newNode=nodeAVoir.treeParent.chercheNoeudCorrespondant(nodeAVoir.item.object)
244 self.f = newNode.fenetre
245 if self.f != None and self.f.isVisible() : self.inhibeExpand=False; return
246 if self.f != None : self.rendVisible()
247 else : self.recentre()
248 else : self.recentre()
249 self.inhibeExpand=False
253 QApplication.processEvents()
254 s=self.editor.fenetreCentraleAffichee.scrollAreaCommandes
255 s.horizontalScrollBar().setSliderPosition(self.avantH)
256 s.verticalScrollBar().setSliderPosition(self.avantV)
258 def rendVisibleNoeud(self,node):
260 #print "dans rendVisibleNoeud",self.f
261 QTimer.singleShot(1, self.rendVisible)
263 def rendVisible(self):
264 #print "dans rendVisible",self.f
265 QApplication.processEvents()
267 self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(self.f)
269 def afficheCatalogue(self):
270 if self.editor.widgetOptionnel != None : self.monOptionnel.hide()
271 self.racine.affichePanneau()
272 if self.node : self.node.select()
273 else : self.racine.select()
275 def afficheApres(self):
276 self.node.selectApres()
278 def afficheAvant(self):
279 self.node.selectAvant()
282 if not(hasattr (self,'RBValide')) : return
284 if self.node.item.object.isvalid() :
285 icon=QIcon(self.repIcon+"/ast-green-ball.png")
287 icon=QIcon(self.repIcon+"/ast-red-ball.png")
288 if self.node.item.GetIconName() == "ast-yellow-square" :
289 icon=QIcon(self.repIcon+"/ast-yel-ball.png")
290 self.LENom.setDisabled(False)
291 if self.node.item.GetIconName() == "ast-red-square" : self.LENom.setDisabled(True)
292 self.RBValide.setIcon(icon)