Salome HOME
Merge branch 'nouvelEficas' of http://git.forge-pleiade.der.edf.fr/git/eficas into...
[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 PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27 from Extensions.i18n import tr
28 import Accas 
29 import os
30 import string
31
32     
33 # Import des panels
34
35 class MonWidgetCommande(Ui_WidgetCommande,Groupe):
36   """
37   """
38   def __init__(self,node,editor,etape):
39       #print "MonWidgetCommande ", self
40       self.listeAffichageWidget=[]
41       self.inhibe=0
42       self.ensure=0
43       Groupe.__init__(self,node,editor,None,etape.definition,etape,1,self)
44       self.labelDoc.setText(QString(etape.definition.fr))
45       if (etape.get_type_produit()==None): self.LENom.close()
46       elif (hasattr (etape, 'sdnom')) and etape.sdnom != "sansnom" : self.LENom.setText(etape.sdnom) 
47       else : self.LENom.setText("")
48       maPolice= QFont("Times", 10,)
49       self.setFont(maPolice)
50       self.repIcon=self.appliEficas.repIcon
51       self.labelNomCommande.setText(tr(self.obj.nom))
52       self.commandesLayout.addStretch()
53       self.commandesLayout.focusInEvent=self.focusInEvent
54       self.scrollAreaCommandes.focusInEvent=self.focusInEvent
55       if self.editor.code in ['MAP','Adao','CARMELCND'] : self.bCatalogue.close()
56       else : self.connect(self.bCatalogue,SIGNAL("clicked()"), self.afficheCatalogue)
57       self.connect(self.LENom,SIGNAL("returnPressed()"),self.nomChange)
58       self.racine=self.node.tree.racine
59       if self.node.item.GetIconName() == "ast-red-square" : self.LENom.setDisabled(True)
60
61       self.setAcceptDrops(True)
62       self.etablitOrdre()
63
64       if self.editor.code == "CARMELCND" : 
65          self.RBPoubelle.close() # JDC Fige
66          return                  # Pas de MC Optionnels pour Carmel
67       from monWidgetOptionnel import MonWidgetOptionnel
68       if hasattr(self.editor,'widgetOptionnel') : 
69         self.monOptionnel=self.editor.widgetOptionnel
70       else :
71         self.monOptionnel=MonWidgetOptionnel(self)
72         self.editor.widgetOptionnel=self.monOptionnel
73         self.editor.splitter.addWidget(self.monOptionnel)
74       print "dans init ", self.monOptionnel
75       self.afficheOptionnel()
76
77
78   def focusNextPrevChild(self, next):
79       # on s assure que ce n est pas un chgt de fenetre
80       print "je passe dans focusNextPrevChild"
81       if self.editor.fenetreCentraleAffichee != self : return True
82       try :
83         i= self.listeAffichageWidget.index(self.focusWidget())
84       except :
85         i = -1
86       if (i==len(self.listeAffichageWidget) -1) and next and not self.inhibe: 
87          self.listeAffichageWidget[1].setFocus(7)
88          w=self.focusWidget()
89          self.inhibe=1
90          w.focusPreviousChild()
91          self.inhibe=0
92          return True
93       if i==0 and next==False and not self.inhibe: 
94          if hasattr(self.editor.fenetreCentraleAffichee,'scrollArea'):
95             self.editor.fenetreCentraleAffichee.scrollArea.ensureWidgetVisible(self.listeAffichageWidget[-1])
96          self.listeAffichageWidget[-2].setFocus(7)
97          self.inhibe=1
98          w=self.focusWidget()
99          w.focusNextChild()
100          self.inhibe=0
101          return True
102       return QWidget.focusNextPrevChild(self, next)
103
104   def etablitOrdre(self):
105       i=0
106       while(i +1 < len(self.listeAffichageWidget)):
107          self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
108          i=i+1
109       # si on boucle on perd l'ordre
110
111   def nomChange(self):
112       nom = str(self.LENom.text())
113       nom = string.strip(nom)
114       if nom == '' : return                  # si pas de nom, on ressort sans rien faire
115       test,mess = self.node.item.nomme_sd(nom)
116       self.editor.affiche_infos(mess)
117
118       #Notation scientifique
119       if test :
120         from politiquesValidation import Validation
121         validation=Validation(self.node,self.editor)
122         validation.AjoutDsDictReelEtape()
123
124   def afficheOptionnel(self):
125       # N a pas de parentQt. doit donc etre redefini
126       liste=self.ajouteMCOptionnelDesBlocs()
127       print "dans afficheOptionnel", self.monOptionnel
128       self.monOptionnel.parentMC=self
129       self.monOptionnel.affiche(liste)
130
131   def focusInEvent(self,event):
132       print "je mets a jour dans focusInEvent de monWidget Commande "
133       if self.editor.code == "CARMELCND" : return #Pas de MC Optionnels pour Carmel
134       self.afficheOptionnel()
135
136
137   def reaffiche(self,nodeAVoir=None):
138       self.avantH=self.editor.fenetreCentraleAffichee.scrollAreaCommandes.horizontalScrollBar().sliderPosition()
139       self.avantV=self.editor.fenetreCentraleAffichee.scrollAreaCommandes.verticalScrollBar().sliderPosition()
140       self.node.affichePanneau()
141       print "dans reaffiche de monWidgetCommande", self.avantH, self.avantV
142       QTimer.singleShot(1, self.recentre)
143       if nodeAVoir != None:
144         self.f=nodeAVoir.fenetre
145         if self.f==None : 
146              newNode=nodeAVoir.treeParent.chercheNoeudCorrespondant(nodeAVoir.item.object)
147              self.f = newNode.fenetre 
148         print "dans reaffiche",self.f, nodeAVoir.item.nom
149         if self.f != None and self.f.isVisible() : return
150         if self.f != None : QTimer.singleShot(1, self.rendVisible)
151
152
153   def recentre(self):
154       qApp.processEvents()
155       s=self.editor.fenetreCentraleAffichee.scrollAreaCommandes
156       s.horizontalScrollBar().setSliderPosition(self.avantH)
157       s.verticalScrollBar().setSliderPosition(self.avantV)
158
159   def rendVisibleNoeud(self,node):
160       self.f=node.fenetre
161       print "dans rendVisibleNoeud",self.f, node.item.nom
162       QTimer.singleShot(1, self.rendVisible)
163      
164   def rendVisible(self):
165       qApp.processEvents()
166       self.f.setFocus()
167       self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(self.f)
168
169   def afficheCatalogue(self):
170       if self.editor.code != "CARMELCND" : self.monOptionnel.hide()
171       self.racine.affichePanneau()
172       if self.node : self.node.select()
173       else : self.racine.select()
174
175   def setValide(self):
176       if not(hasattr (self,'RBValide')) : return
177       icon = QIcon()
178       if self.node.item.object.isvalid() :
179          icon=QIcon(self.repIcon+"/ast-green-ball.png")
180       else :
181          icon=QIcon(self.repIcon+"/ast-red-ball.png")
182       if self.node.item.GetIconName() == "ast-yellow-square" :
183          icon=QIcon(self.repIcon+"/ast-yel-ball.png")
184       self.RBValide.setIcon(icon)