1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 import string,types,os
24 from PyQt4.QtGui import *
25 from PyQt4.QtCore import *
26 from Extensions.i18n import tr
28 from feuille import Feuille
29 from desWidgetSimpComplexe import Ui_WidgetSimpComplexe
30 from politiquesValidation import PolitiqueUnique
31 from qtSaisie import SaisieValeur
34 class MonWidgetSimpComplexe (Ui_WidgetSimpComplexe,Feuille):
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)
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))
60 self.LEReel.setText(str(x1))
61 self.LEImag.setText(str(x2))
63 self.RBRI.setChecked(1)
65 self.RBMP.setChecked(1)
67 def LECompRPressed(self) :
70 commentaire=tr("expression valide")
71 valeur = str(self.LEComp.text())
76 commentaire=tr("expression invalide")
77 self.editor.affiche_infos(commentaire,Qt.red)
81 self.editor.affiche_infos(commentaire)
84 commentaire=tr("l expression n est pas de la forme a+bj")
85 self.editor.affiche_infos(commentaire,Qt.red)
87 def LEReelRPressed(self):
89 commentaire=tr("expression valide")
90 valeur = str(self.LEReel.text())
93 self.editor.affiche_infos(commentaire)
95 commentaire=tr("expression invalide")
96 self.editor.affiche_infos(commentaire,Qt.red)
97 if self.LEImag.text()!="" : self.ValeurPressed()
99 def LEImagRPressed(self):
101 commentaire=tr("expression valide")
102 valeur = str(self.LEImag.text())
104 a=string.atof(valeur)
105 self.editor.affiche_infos(commentaire)
107 commentaire=tr("expression invalide")
108 self.editor.affiche_infos(commentaire,Qt.red)
109 if self.LEReel.text()!="" : self.ValeurPressed()
111 def finCommentaire(self):
112 commentaire="valeur de type complexe"
115 def getValeurComp(self):
116 commentaire=tr("expression valide")
117 valeur = str(self.LEComp.text())
122 commentaire=tr("expression invalide")
123 self.editor.affiche_infos(commentaire,Qt.red)
128 commentaire=tr("expression n est pas de la forme a+bj")
129 self.editor.affiche_infos(commentaire,Qt.red)
134 def ValeurPressed(self):
135 if self.LEComp.text()== "" and (self.LEReel.text()=="" or self.LEImag.text()=="") :
137 if self.LEComp.text()== "" : valeur = self.getValeurRI()
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)
143 valeur= self.getValeurComp()
144 self.politique.RecordValeur(valeur)
146 self.parentQt.donneFocus()
148 def getValeurRI(self):
150 Retourne le complexe saisi par l'utilisateur
153 if (self.RBMP.isChecked() == 1 ) :
155 elif (self.RBRI.isChecked() == 1) :
158 commentaire=tr("saisir le type de complexe")
159 self.editor.affiche_infos(commentaire,Qt.red)
162 l.append(string.atof(str(self.LEReel.text())))
163 l.append(string.atof(str(self.LEImag.text())))