Salome HOME
sauve du 10/06
[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 determine import monEnvQT5
26
27 if monEnvQT5:
28    from PyQt5.QtWidgets  import QApplication, QWidget, QSpacerItem, QSizePolicy
29    from PyQt5.QtGui import QFont, QIcon
30    from PyQt5.QtCore import QTimer
31 else :
32    from PyQt4.QtGui import *
33    from PyQt4.QtCore import *
34
35
36 from Extensions.i18n import tr
37 import Accas 
38 import os
39 import string
40
41     
42 # Import des panels
43
44 class MonWidgetCommande(Ui_WidgetCommande,Groupe):
45   """
46   """
47   def __init__(self,node,editor,etape):
48       #print "MonWidgetCommande ", self
49       self.listeAffichageWidget=[]
50       self.inhibe=0
51       self.ensure=0
52       editor.inhibeSplitter=1
53       Groupe.__init__(self,node,editor,None,etape.definition,etape,1,self)
54       editor.inhibeSplitter=0
55
56       if node.item.get_fr() != "" : self.labelDoc.setText(node.item.get_fr())
57       else : self.labelDoc.close()
58       
59       if (etape.get_type_produit()==None): self.LENom.close()
60       elif (hasattr(etape, 'sdnom')) and etape.sdnom != "sansnom" and etape.sdnom != None: self.LENom.setText(etape.sdnom) 
61       else : self.LENom.setText("")
62
63       maPolice= QFont("Times", 10,)
64       self.setFont(maPolice)
65       self.labelNomCommande.setText(tr(self.obj.nom))
66
67       self.commandesLayout.addStretch()
68       self.commandesLayout.focusInEvent=self.focusInEvent
69       self.scrollAreaCommandes.focusInEvent=self.focusInEvent
70
71      
72       if monEnvQT5 :
73          if self.editor.code in ['MAP','CARMELCND'] : self.bCatalogue.close()
74          else : self.bCatalogue.clicked.connect(self.afficheCatalogue)
75          if self.editor.code in ['Adao','MAP'] : 
76                self.bAvant.close()
77                self.bApres.close()
78          else : 
79                self.bAvant.clicked.connect(self.afficheAvant)
80                self.bApres.clicked.connect(self.afficheApres)
81          self.LENom.returnPressed.connect(self.nomChange)
82       else : 
83          if self.editor.code in ['MAP','CARMELCND'] : self.bCatalogue.close()
84          else : self.connect(self.bCatalogue,SIGNAL("clicked()"), self.afficheCatalogue)
85          if self.editor.code in ['Adao','MAP'] : 
86                self.bAvant.close()
87                self.bApres.close()
88          else : 
89                self.connect(self.bAvant,SIGNAL("clicked()"), self.afficheAvant)
90                self.connect(self.bApres,SIGNAL("clicked()"), self.afficheApres)
91          self.connect(self.LENom,SIGNAL("returnPressed()"),self.nomChange)
92    
93       self.racine=self.node.tree.racine
94       if self.node.item.GetIconName() == "ast-red-square" : self.LENom.setDisabled(True)
95
96       self.setAcceptDrops(True)
97       self.etablitOrdre()
98
99       if self.editor.code == "CARMELCND" : 
100          self.RBPoubelle.close() # JDC Fige
101          return                  # Pas de MC Optionnels pour Carmel
102
103       from monWidgetOptionnel import MonWidgetOptionnel
104       if self.editor.widgetOptionnel!= None : 
105         self.monOptionnel=self.editor.widgetOptionnel
106       else :
107         self.monOptionnel=MonWidgetOptionnel(self)
108         self.editor.widgetOptionnel=self.monOptionnel
109         self.editor.inhibeSplitter=1
110         self.editor.splitter.addWidget(self.monOptionnel)
111         self.editor.inhibeSplitter=0
112         self.editor.ajoutOptionnel()
113       self.afficheOptionnel()
114
115       self.editor.restoreSplitterSizes()
116       #print "fin init de widget Commande"
117       
118
119   def donnePremier(self):
120       #print "dans donnePremier"
121       QApplication.processEvents()
122       if self.listeAffichageWidget != [] :
123          self.listeAffichageWidget[0].setFocus(7)
124       QApplication.processEvents()
125       #print self.focusWidget()
126
127
128   def focusNextPrevChild(self, next):
129       # on s assure que ce n est pas un chgt de fenetre
130       #print "je passe dans focusNextPrevChild"
131       if self.editor.fenetreCentraleAffichee != self : return True
132       f=self.focusWidget()
133       if f not in self.listeAffichageWidget :
134          i=0
135          while not hasattr (f,'AAfficher') :
136            if f==None :i=-1; break
137            f=f.parentWidget()
138          if hasattr(f,'AAfficher') : f=f.AAfficher
139          if i != -1 : i=self.listeAffichageWidget.index(f)
140       else :i=self.listeAffichageWidget.index(f) 
141       if (i==len(self.listeAffichageWidget) -1) and next and not self.inhibe: 
142          try :
143            self.listeAffichageWidget[1].setFocus(7)
144            w=self.focusWidget()
145            self.inhibe=1
146            w.focusPreviousChild()
147            self.inhibe=0
148            return True
149          except :
150            print self.listeAffichageWidget
151            print "souci ds focusNextPrevChild"
152       if i==0 and next==False and not self.inhibe: 
153          if hasattr(self.editor.fenetreCentraleAffichee,'scrollArea'):
154             self.editor.fenetreCentraleAffichee.scrollArea.ensureWidgetVisible(self.listeAffichageWidget[-1])
155          self.listeAffichageWidget[-2].setFocus(7)
156          self.inhibe=1
157          w=self.focusWidget()
158          w.focusNextChild()
159          self.inhibe=0
160          return True
161       if i==0 and next==True and not self.inhibe:
162          self.listeAffichageWidget[0].setFocus(7)
163          self.inhibe=1
164          w=self.focusWidget()
165          w.focusNextChild()
166          self.inhibe=0
167          return True
168       if i>0 and next==False and not self.inhibe:
169          if isinstance(self.listeAffichageWidget[i-1],QRadioButton):
170            self.listeAffichageWidget[i-1].setFocus(7)
171            return True
172       return QWidget.focusNextPrevChild(self, next)
173
174   def etablitOrdre(self):
175       i=0
176       while(i +1 < len(self.listeAffichageWidget)):
177          self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
178          i=i+1
179       # si on boucle on perd l'ordre
180  
181   def  afficheSuivant(self,f):
182       try :
183         i=self.listeAffichageWidget.index(f) 
184         next=i+1
185       except :
186         next=1
187       if (next==len(self.listeAffichageWidget) -1 ): next =0
188       #self.f=next
189       #QTimer.singleShot(1, self.rendVisible)
190       try :
191         self.listeAffichageWidget[next].setFocus(7)
192       except :
193         pass
194
195   def nomChange(self):
196       nom = str(self.LENom.text())
197       nom = string.strip(nom)
198       if nom == '' : return                  # si pas de nom, on ressort sans rien faire
199       test,mess = self.node.item.nomme_sd(nom)
200       self.editor.affiche_commentaire(mess)
201
202       #Notation scientifique
203       if test :
204         from politiquesValidation import Validation
205         validation=Validation(self.node,self.editor)
206         validation.AjoutDsDictReelEtape()
207
208   def afficheOptionnel(self):
209       # N a pas de parentQt. doit donc etre redefini
210       liste=self.ajouteMCOptionnelDesBlocs()
211       #print "dans afficheOptionnel", self.monOptionnel
212       # dans le cas ou l insertion n a pas eu leiu (souci d ordre par exemple)
213       #if self.monOptionnel == None : return
214       self.monOptionnel.parentCommande=self
215       self.monOptionnel.titre(self.obj.nom)
216       self.monGroupe=self.monOptionnel.afficheOptionnel(liste,self)
217       
218
219   #def focusInEvent(self,event):
220       #print "je mets a jour dans focusInEvent de monWidget Commande "
221   #    if self.editor.code == "CARMELCND" : return #Pas de MC Optionnels pour Carmel
222   #    self.afficheOptionnel()
223
224
225   def reaffiche(self,nodeAVoir=None):
226       self.avantH=self.editor.fenetreCentraleAffichee.scrollAreaCommandes.horizontalScrollBar().sliderPosition()
227       self.avantV=self.editor.fenetreCentraleAffichee.scrollAreaCommandes.verticalScrollBar().sliderPosition()
228       self.inhibeExpand=True
229       self.node.affichePanneau()
230       #print "dans reaffiche de monWidgetCommande", self.avantH, self.avantV
231       QTimer.singleShot(1, self.recentre)
232       if nodeAVoir != None and nodeAVoir!=0:
233         self.f=nodeAVoir.fenetre
234         if self.f==None : 
235              newNode=nodeAVoir.treeParent.chercheNoeudCorrespondant(nodeAVoir.item.object)
236              self.f = newNode.fenetre 
237         #print "dans reaffiche",self.f, nodeAVoir.item.nom
238         if self.f != None and self.f.isVisible() : return
239         if self.f != None : QTimer.singleShot(1, self.rendVisible)
240       self.inhibeExpand=False
241
242
243   def recentre(self):
244       QApplication.processEvents()
245       s=self.editor.fenetreCentraleAffichee.scrollAreaCommandes
246       s.horizontalScrollBar().setSliderPosition(self.avantH)
247       s.verticalScrollBar().setSliderPosition(self.avantV)
248
249   def rendVisibleNoeud(self,node):
250       self.f=node.fenetre
251       print "dans rendVisibleNoeud",self.f, node.item.nom
252       QTimer.singleShot(1, self.rendVisible)
253      
254   def rendVisible(self):
255       QApplication.processEvents()
256       self.f.setFocus(7)
257       self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(self.f)
258
259   def afficheCatalogue(self):
260       if self.editor.widgetOptionnel != None : self.monOptionnel.hide()
261       self.racine.affichePanneau()
262       if self.node : self.node.select()
263       else : self.racine.select()
264
265   def afficheApres(self):
266        self.node.selectApres()
267
268   def afficheAvant(self):
269        self.node.selectAvant()
270
271   def setValide(self):
272       if not(hasattr (self,'RBValide')) : return
273       icon = QIcon()
274       if self.node.item.object.isvalid() :
275          icon=QIcon(self.repIcon+"/ast-green-ball.png")
276       else :
277          icon=QIcon(self.repIcon+"/ast-red-ball.png")
278       if self.node.item.GetIconName() == "ast-yellow-square" :
279          icon=QIcon(self.repIcon+"/ast-yel-ball.png")
280       self.RBValide.setIcon(icon)
281
282