Salome HOME
6b8bd6914b603518bfe63e8d1f9f0fb8cb1a9674
[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       Groupe.__init__(self,node,editor,None,etape.definition,etape,1,self)
43       if (etape.get_type_produit()==None): self.LENom.close()
44       elif (hasattr (etape, 'sdnom')) and etape.sdnom != "sansnom" : self.LENom.setText(etape.sdnom) 
45       else : self.LENom.setText("")
46       maPolice= QFont("Times", 10,)
47       self.setFont(maPolice)
48       self.repIcon=self.appliEficas.repIcon
49       self.labelNomCommande.setText(tr(self.obj.nom))
50       self.commandesLayout.addStretch()
51       self.commandesLayout.focusInEvent=self.focusInEvent
52       self.scrollAreaCommandes.focusInEvent=self.focusInEvent
53       #self.RBValide.focusInEvent=FacultatifOuOptionnel.focusInEvent
54       if self.editor.code in ['MAP','Adao','CARMELCND'] : self.bCatalogue.close()
55       else : self.connect(self.bCatalogue,SIGNAL("clicked()"), self.afficheCatalogue)
56       self.connect(self.LENom,SIGNAL("returnPressed()"),self.nomChange)
57       self.racine=self.node.tree.racine
58       if self.node.item.GetIconName() == "ast-red-square" : self.LENom.setDisabled(True)
59
60       self.setAcceptDrops(True)
61       self.etablitOrdre()
62
63       if self.editor.code == "CARMELCND" : 
64          self.RBPoubelle.close() # JDC Fige
65          return                  # Pas de MC Optionnels pour Carmel
66       from monWidgetOptionnel import MonWidgetOptionnel
67       if hasattr(self.editor,'widgetOptionnel') : 
68         self.monOptionnel=self.editor.widgetOptionnel
69       else :
70         self.monOptionnel=MonWidgetOptionnel(self)
71         self.editor.widgetOptionnel=self.monOptionnel
72         self.editor.splitter.addWidget(self.monOptionnel)
73       self.afficheOptionnel()
74
75
76   def focusNextPrevChild(self, next):
77       # on s assure que ce n est pas un chgt de fenetre
78       if self.editor.fenetreAffichee != self : return True
79       try :
80         i= self.listeAffichageWidget.index(self.focusWidget())
81       except :
82         i = -1
83       if (i==len(self.listeAffichageWidget) -1) and next and not self.inhibe: 
84          self.listeAffichageWidget[1].setFocus(7)
85          w=self.focusWidget()
86          self.inhibe=1
87          w.focusPreviousChild()
88          self.inhibe=0
89          return True
90       if i==0 and next==False and not self.inhibe: 
91          if hasattr(self.editor.fenetreCentraleAffichee,'scrollArea'):
92             self.editor.fenetreCentraleAffichee.scrollArea.ensureWidgetVisible(self.listeAffichageWidget[-1])
93          self.listeAffichageWidget[-2].setFocus(7)
94          self.inhibe=1
95          w=self.focusWidget()
96          w.focusNextChild()
97          self.inhibe=0
98          return True
99       return QWidget.focusNextPrevChild(self, next)
100
101   def etablitOrdre(self):
102       i=0
103       while(i +1 < len(self.listeAffichageWidget)):
104          self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
105          i=i+1
106       # si on boucle on perd l'ordre
107
108   def nomChange(self):
109       nom = str(self.LENom.text())
110       nom = string.strip(nom)
111       if nom == '' : return                  # si pas de nom, on ressort sans rien faire
112       test,mess = self.node.item.nomme_sd(nom)
113       self.editor.affiche_infos(mess)
114
115       #Notation scientifique
116       if test :
117         from politiquesValidation import Validation
118         validation=Validation(self.node,self.editor)
119         validation.AjoutDsDictReelEtape()
120
121   def afficheOptionnel(self):
122       # N a pas de parentQt. doit donc etre redefini
123       liste=self.ajouteMCOptionnelDesBlocs()
124       self.monOptionnel.parentMC=self
125       self.monOptionnel.affiche(liste)
126
127   def focusInEvent(self,event):
128       #print "je mets a jour dans focusInEvent de monWidget Commande "
129       if self.editor.code == "CARMELCND" : return #Pas de MC Optionnels pour Carmel
130       self.afficheOptionnel()
131
132
133   def reaffiche(self,nodeAVoir=None):
134       self.node.affichePanneau()
135       if nodeAVoir != None:
136         f=nodeAVoir.fenetre
137         qApp.processEvents()
138         self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(f)
139
140   def afficheCatalogue(self):
141       if self.editor.code != "CARMELCND" : self.monOptionnel.hide()
142       self.racine.affichePanneau()
143       if self.node : self.node.select()
144       else : self.racine.select()
145
146   def setValide(self):
147       if not(hasattr (self,'RBValide')) : return
148       icon = QIcon()
149       if self.node.item.object.isvalid() :
150          icon=QIcon(self.repIcon+"/ast-green-ball.png")
151       else :
152          icon=QIcon(self.repIcon+"/ast-red-ball.png")
153       if self.node.item.GetIconName() == "ast-yellow-square" :
154          icon=QIcon(self.repIcon+"/ast-yel-ball.png")
155       self.RBValide.setIcon(icon)