]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/monWidgetCommande.py
Salome HOME
monWidgetCommande.py
[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       self.listeAffichageWidget=[]
49       self.inhibe=0
50       self.ensure=0
51       editor.inhibeSplitter=1
52       Groupe.__init__(self,node,editor,None,etape.definition,etape,1,self)
53       editor.inhibeSplitter=0
54
55       self.frameAffichage.setMinimumHeight(20)
56       if node.item.get_fr() != "" : self.labelDoc.setText(node.item.get_fr())
57       else : 
58         self.labelDoc.close()
59         self.frameAffichage.resize(self.frameAffichage.width(),50)
60       
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("")
65
66
67       maPolice= QFont("Times", 10,)
68       self.setFont(maPolice)
69       self.labelNomCommande.setText(tr(self.obj.nom))
70
71       self.commandesLayout.addStretch()
72       self.commandesLayout.focusInEvent=self.focusInEvent
73       self.scrollAreaCommandes.focusInEvent=self.focusInEvent
74
75      
76       if self.editor.closeFrameRechercheCommande==True : self.closeAutreCommande()
77       else :
78         if monEnvQT5 :
79          try :
80            self.bCatalogue.clicked.connect(self.afficheCatalogue)
81            self.bAvant.clicked.connect(self.afficheAvant)
82            self.bApres.clicked.connect(self.afficheApres)
83          except :
84            pass
85          self.LENom.returnPressed.connect(self.nomChange)
86         else : 
87          try :
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)
91          except :
92             pass
93          self.connect(self.LENom,SIGNAL("returnPressed()"),self.nomChange)
94    
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)
98
99       self.setAcceptDrops(True)
100       self.etablitOrdre()
101
102       if self.editor.code == "CARMELCND" : 
103          self.RBPoubelle.close() # JDC Fige
104          return                  # Pas de MC Optionnels pour Carmel
105
106       from monWidgetOptionnel import MonWidgetOptionnel
107       if self.editor.widgetOptionnel!= None : 
108         self.monOptionnel=self.editor.widgetOptionnel
109       else :
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()
117
118       self.editor.restoreSplitterSizes()
119       #print "fin init de widget Commande"
120       
121   def closeAutreCommande(self):
122       self.bCatalogue.close()
123       self.bAvant.close()
124       self.bApres.close()
125
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()
133
134
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
139       f=self.focusWidget()
140       if f not in self.listeAffichageWidget :
141          i=0
142          while not hasattr (f,'AAfficher') :
143            if f==None :i=-1; break
144            f=f.parentWidget()
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: 
149          try :
150            self.listeAffichageWidget[1].setFocus(7)
151            w=self.focusWidget()
152            self.inhibe=1
153            w.focusPreviousChild()
154            self.inhibe=0
155            return True
156          except :
157            pass
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)
164          self.inhibe=1
165          w=self.focusWidget()
166          w.focusNextChild()
167          self.inhibe=0
168          return True
169       if i==0 and next==True and not self.inhibe:
170          self.listeAffichageWidget[0].setFocus(7)
171          self.inhibe=1
172          w=self.focusWidget()
173          w.focusNextChild()
174          self.inhibe=0
175          return True
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)
179            return True
180       return QWidget.focusNextPrevChild(self, next)
181
182   def etablitOrdre(self):
183       i=0
184       while(i +1 < len(self.listeAffichageWidget)):
185          self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
186          i=i+1
187       # si on boucle on perd l'ordre
188  
189   def  afficheSuivant(self,f):
190       try :
191         i=self.listeAffichageWidget.index(f) 
192         next=i+1
193       except :
194         next=1
195       if (next==len(self.listeAffichageWidget) -1 ): next =0
196       #self.f=next
197       #QTimer.singleShot(1, self.rendVisible)
198       try :
199         self.listeAffichageWidget[next].setFocus(7)
200       except :
201         pass
202
203   def nomChange(self):
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)
209
210       #Notation scientifique
211       if test :
212         from politiquesValidation import Validation
213         validation=Validation(self.node,self.editor)
214         validation.AjoutDsDictReelEtape()
215
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)
225       
226
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()
231
232
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
242         if self.f==None : 
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
250
251
252   def recentre(self):
253       QApplication.processEvents()
254       s=self.editor.fenetreCentraleAffichee.scrollAreaCommandes
255       s.horizontalScrollBar().setSliderPosition(self.avantH)
256       s.verticalScrollBar().setSliderPosition(self.avantV)
257
258   def rendVisibleNoeud(self,node):
259       self.f=node.fenetre
260       #print "dans rendVisibleNoeud",self.f
261       QTimer.singleShot(1, self.rendVisible)
262      
263   def rendVisible(self):
264       #print "dans rendVisible",self.f
265       QApplication.processEvents()
266       self.f.setFocus(7)
267       self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(self.f)
268
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()
274
275   def afficheApres(self):
276        self.node.selectApres()
277
278   def afficheAvant(self):
279        self.node.selectAvant()
280
281   def setValide(self):
282       if not(hasattr (self,'RBValide')) : return
283       icon = QIcon()
284       if self.node.item.object.isvalid() :
285          icon=QIcon(self.repIcon+"/ast-green-ball.png")
286       else :
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)
293
294