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