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