Salome HOME
PourLaura
[tools/eficas.git] / InterfaceQT4 / monWidgetSimpComplexe.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Modules Python
21 import string,types,os
22
23 # Modules Eficas
24 from PyQt4.QtGui import *
25 from PyQt4.QtCore import *
26 from Extensions.i18n import tr
27
28 from feuille                import Feuille
29 from desWidgetSimpComplexe  import Ui_WidgetSimpComplexe 
30 from politiquesValidation   import PolitiqueUnique
31 from qtSaisie               import SaisieValeur
32
33
34 class MonWidgetSimpComplexe (Ui_WidgetSimpComplexe,Feuille):
35
36   def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
37         Feuille.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
38         self.parentQt.commandesLayout.insertWidget(-1,self)
39         self.setFocusPolicy(Qt.StrongFocus)
40         self.connect(self.LEImag,SIGNAL("returnPressed()"),self.LEImagRPressed)
41         self.connect(self.LEReel,SIGNAL("returnPressed()"),self.LEReelRPressed)
42         self.connect(self.RBRI,SIGNAL("clicked()"), self.ValeurPressed )
43         self.connect(self.RBMP,SIGNAL("clicked()"), self.ValeurPressed )
44         self.connect(self.LEComp,SIGNAL("returnPressed()"),self.LECompRPressed)
45         self.maCommande.listeAffichageWidget.append(self.LEComp)
46         #self.maCommande.listeAffichageWidget.append(self.RBRI)
47         #self.maCommande.listeAffichageWidget.append(self.RBMP)
48         #self.maCommande.listeAffichageWidget.append(self.LEReel)
49         #self.maCommande.listeAffichageWidget.append(self.LEImag)
50
51
52   def setValeurs(self):
53        self.politique=PolitiqueUnique(self.node,self.editor)
54        valeur=self.node.item.get_valeur()
55        if valeur == None or valeur == '' : return
56        if type(valeur) not in (types.ListType,types.TupleType) :
57            self.LEComp.setText(str(valeur))
58        else :
59            typ_cplx,x1,x2=valeur
60            self.LEReel.setText(str(x1))
61            self.LEImag.setText(str(x2))
62            if typ_cplx == "RI" :
63               self.RBRI.setChecked(1)
64            else :
65               self.RBMP.setChecked(1)
66
67   def LECompRPressed(self) :
68         self.LEReel.clear()
69         self.LEImag.clear()
70         commentaire=tr("expression valide")
71         valeur = str(self.LEComp.text())
72         d={}
73         try :
74           v=eval(valeur,d)
75         except :
76           commentaire=tr("expression invalide")
77           self.editor.affiche_infos(commentaire,Qt.red)
78           return
79         try :
80           i=v.imag
81           self.editor.affiche_infos(commentaire)
82           self.ValeurPressed()
83         except :
84           commentaire=tr("l expression n est pas de la forme a+bj")
85           self.editor.affiche_infos(commentaire,Qt.red)
86
87   def LEReelRPressed(self):
88         self.LEComp.clear()
89         commentaire=tr("expression valide")
90         valeur = str(self.LEReel.text())
91         try :
92           a=string.atof(valeur)
93           self.editor.affiche_infos(commentaire)
94         except :
95           commentaire=tr("expression invalide")
96           self.editor.affiche_infos(commentaire,Qt.red)
97         if self.LEImag.text()!="" : self.ValeurPressed()
98
99   def LEImagRPressed(self):
100         self.LEComp.clear()
101         commentaire=tr("expression valide")
102         valeur = str(self.LEImag.text())
103         try :
104           a=string.atof(valeur)
105           self.editor.affiche_infos(commentaire)
106         except :
107           commentaire=tr("expression invalide")
108           self.editor.affiche_infos(commentaire,Qt.red)
109         if self.LEReel.text()!="" : self.ValeurPressed()
110
111   def finCommentaire(self):
112       commentaire="valeur de type complexe"
113       return commentaire
114
115   def getValeurComp(self):
116         commentaire=tr("expression valide")
117         valeur = str(self.LEComp.text())
118         d={}
119         try :
120           v=eval(valeur,d)
121         except :
122           commentaire=tr("expression invalide")
123           self.editor.affiche_infos(commentaire,Qt.red)
124           return None
125         try :
126           i=v.imag
127         except :
128           commentaire=tr("expression n est pas de la forme a+bj")
129           self.editor.affiche_infos(commentaire,Qt.red)
130           return None
131         return v
132
133
134   def ValeurPressed(self):
135       if self.LEComp.text()== ""  and (self.LEReel.text()=="" or self.LEImag.text()=="") :
136          return
137       if self.LEComp.text()== "" : valeur = self.getValeurRI()
138       else :
139           if self.LEReel.text() != "" or self.LEImag.text() != "" :
140               commentaire=tr("entrer une seule valeur SVP")
141               self.editor.affiche_infos(commentaire,Qt.red)
142               return
143           valeur=  self.getValeurComp()
144       self.politique.RecordValeur(valeur)
145       self.reaffiche()
146       self.parentQt.donneFocus()
147
148   def getValeurRI(self):
149       """
150       Retourne le complexe saisi par l'utilisateur
151       """
152       l=[]
153       if  (self.RBMP.isChecked() == 1 ) :
154          l.append("MP")
155       elif (self.RBRI.isChecked() == 1) :
156          l.append("RI")
157       else :
158          commentaire=tr("saisir le type de complexe")
159          self.editor.affiche_infos(commentaire,Qt.red)
160          return None
161       try :
162          l.append(string.atof(str(self.LEReel.text())))
163          l.append(string.atof(str(self.LEImag.text())))
164       except :
165          return None
166       return `tuple(l)`
167
168