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 if node.item.get_fr() != "" : self.labelDoc.setText(node.item.get_fr())
56 else : self.labelDoc.close()
58 if (etape.get_type_produit()==None): self.LENom.close()
59 elif (hasattr(etape, 'sdnom')) and etape.sdnom != "sansnom" and etape.sdnom != None: self.LENom.setText(etape.sdnom)
60 else : self.LENom.setText("")
62 maPolice= QFont("Times", 10,)
63 self.setFont(maPolice)
64 self.labelNomCommande.setText(tr(self.obj.nom))
66 self.commandesLayout.addStretch()
67 self.commandesLayout.focusInEvent=self.focusInEvent
68 self.scrollAreaCommandes.focusInEvent=self.focusInEvent
71 if self.editor.closeFrameRechercheCommande==True : self.closeAutreCommande()
75 self.bCatalogue.clicked.connect(self.afficheCatalogue)
76 self.bAvant.clicked.connect(self.afficheAvant)
77 self.bApres.clicked.connect(self.afficheApres)
80 self.LENom.returnPressed.connect(self.nomChange)
83 self.connect(self.bCatalogue,SIGNAL("clicked()"), self.afficheCatalogue)
84 self.connect(self.bAvant,SIGNAL("clicked()"), self.afficheAvant)
85 self.connect(self.bApres,SIGNAL("clicked()"), self.afficheApres)
88 self.connect(self.LENom,SIGNAL("returnPressed()"),self.nomChange)
90 if self.editor.code in ['CARMELCND',] : self.closeAutreCommande()
91 self.racine=self.node.tree.racine
92 if self.node.item.GetIconName() == "ast-red-square" : self.LENom.setDisabled(True)
94 self.setAcceptDrops(True)
97 if self.editor.code == "CARMELCND" :
98 self.RBPoubelle.close() # JDC Fige
99 return # Pas de MC Optionnels pour Carmel
101 from monWidgetOptionnel import MonWidgetOptionnel
102 if self.editor.widgetOptionnel!= None :
103 self.monOptionnel=self.editor.widgetOptionnel
105 self.monOptionnel=MonWidgetOptionnel(self)
106 self.editor.widgetOptionnel=self.monOptionnel
107 self.editor.inhibeSplitter=1
108 self.editor.splitter.addWidget(self.monOptionnel)
109 self.editor.inhibeSplitter=0
110 self.editor.ajoutOptionnel()
111 self.afficheOptionnel()
113 self.editor.restoreSplitterSizes()
114 #print "fin init de widget Commande"
116 def closeAutreCommande(self):
117 self.bCatalogue.close()
121 def donnePremier(self):
122 #print "dans donnePremier"
123 QApplication.processEvents()
124 if self.listeAffichageWidget != [] :
125 self.listeAffichageWidget[0].setFocus(7)
126 QApplication.processEvents()
127 #print self.focusWidget()
130 def focusNextPrevChild(self, next):
131 # on s assure que ce n est pas un chgt de fenetre
132 #print "je passe dans focusNextPrevChild"
133 if self.editor.fenetreCentraleAffichee != self : return True
135 if f not in self.listeAffichageWidget :
137 while not hasattr (f,'AAfficher') :
138 if f==None :i=-1; break
140 if hasattr(f,'AAfficher') : f=f.AAfficher
141 if i != -1 : i=self.listeAffichageWidget.index(f)
142 else :i=self.listeAffichageWidget.index(f)
143 if (i==len(self.listeAffichageWidget) -1) and next and not self.inhibe:
145 self.listeAffichageWidget[1].setFocus(7)
148 w.focusPreviousChild()
152 print self.listeAffichageWidget
153 print "souci ds focusNextPrevChild"
154 if i==0 and next==False and not self.inhibe:
155 if hasattr(self.editor.fenetreCentraleAffichee,'scrollArea'):
156 self.editor.fenetreCentraleAffichee.scrollArea.ensureWidgetVisible(self.listeAffichageWidget[-1])
157 self.listeAffichageWidget[-2].setFocus(7)
163 if i==0 and next==True and not self.inhibe:
164 self.listeAffichageWidget[0].setFocus(7)
170 if i>0 and next==False and not self.inhibe:
171 if isinstance(self.listeAffichageWidget[i-1],QRadioButton):
172 self.listeAffichageWidget[i-1].setFocus(7)
174 return QWidget.focusNextPrevChild(self, next)
176 def etablitOrdre(self):
178 while(i +1 < len(self.listeAffichageWidget)):
179 self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
181 # si on boucle on perd l'ordre
183 def afficheSuivant(self,f):
185 i=self.listeAffichageWidget.index(f)
189 if (next==len(self.listeAffichageWidget) -1 ): next =0
191 #QTimer.singleShot(1, self.rendVisible)
193 self.listeAffichageWidget[next].setFocus(7)
198 nom = str(self.LENom.text())
199 nom = string.strip(nom)
200 if nom == '' : return # si pas de nom, on ressort sans rien faire
201 test,mess = self.node.item.nomme_sd(nom)
202 self.editor.affiche_commentaire(mess)
204 #Notation scientifique
206 from politiquesValidation import Validation
207 validation=Validation(self.node,self.editor)
208 validation.AjoutDsDictReelEtape()
210 def afficheOptionnel(self):
211 # N a pas de parentQt. doit donc etre redefini
212 liste=self.ajouteMCOptionnelDesBlocs()
213 #print "dans afficheOptionnel", self.monOptionnel
214 # dans le cas ou l insertion n a pas eu leiu (souci d ordre par exemple)
215 #if self.monOptionnel == None : return
216 self.monOptionnel.parentCommande=self
217 self.monOptionnel.titre(self.obj.nom)
218 self.monGroupe=self.monOptionnel.afficheOptionnel(liste,self)
221 #def focusInEvent(self,event):
222 #print "je mets a jour dans focusInEvent de monWidget Commande "
223 # if self.editor.code == "CARMELCND" : return #Pas de MC Optionnels pour Carmel
224 # self.afficheOptionnel()
227 def reaffiche(self,nodeAVoir=None):
228 # Attention delicat. les appels de fonctions ne semblent pas pouvoir etre supprimes!
229 self.avantH=self.editor.fenetreCentraleAffichee.scrollAreaCommandes.horizontalScrollBar().sliderPosition()
230 self.avantV=self.editor.fenetreCentraleAffichee.scrollAreaCommandes.verticalScrollBar().sliderPosition()
231 self.inhibeExpand=True
232 self.node.affichePanneau()
233 #QTimer.singleShot(1, self.recentre)
234 if nodeAVoir != None and nodeAVoir!=0:
235 self.f=nodeAVoir.fenetre
237 newNode=nodeAVoir.treeParent.chercheNoeudCorrespondant(nodeAVoir.item.object)
238 self.f = newNode.fenetre
239 if self.f != None and self.f.isVisible() : self.inhibeExpand=False; return
240 if self.f != None : self.rendVisible()
241 else : self.recentre()
242 else : self.recentre()
243 self.inhibeExpand=False
247 QApplication.processEvents()
248 s=self.editor.fenetreCentraleAffichee.scrollAreaCommandes
249 s.horizontalScrollBar().setSliderPosition(self.avantH)
250 s.verticalScrollBar().setSliderPosition(self.avantV)
252 def rendVisibleNoeud(self,node):
254 print "dans rendVisibleNoeud",self.f
255 QTimer.singleShot(1, self.rendVisible)
257 def rendVisible(self):
258 print "dans rendVisible",self.f
259 QApplication.processEvents()
261 self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(self.f)
263 def afficheCatalogue(self):
264 if self.editor.widgetOptionnel != None : self.monOptionnel.hide()
265 self.racine.affichePanneau()
266 if self.node : self.node.select()
267 else : self.racine.select()
269 def afficheApres(self):
270 self.node.selectApres()
272 def afficheAvant(self):
273 self.node.selectAvant()
276 if not(hasattr (self,'RBValide')) : return
278 if self.node.item.object.isvalid() :
279 icon=QIcon(self.repIcon+"/ast-green-ball.png")
281 icon=QIcon(self.repIcon+"/ast-red-ball.png")
282 if self.node.item.GetIconName() == "ast-yellow-square" :
283 icon=QIcon(self.repIcon+"/ast-yel-ball.png")
284 self.RBValide.setIcon(icon)