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):
37 Feuille.__init__(self,node,monSimpDef,nom,objSimp,parentQt)
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)
48 self.politique=PolitiqueUnique(self.node,self.editor)
49 valeur=self.node.item.get_valeur()
50 if valeur == None or valeur == '' : return
51 if type(valeur) not in (types.ListType,types.TupleType) :
52 self.LEComp.setText(str(valeur))
55 self.LEReel.setText(str(x1))
56 self.LEImag.setText(str(x2))
58 self.RBRI.setChecked(1)
60 self.RBMP.setChecked(1)
62 def LECompRPressed(self) :
65 commentaire=tr("expression valide")
66 valeur = str(self.LEComp.text())
71 commentaire=tr("expression invalide")
72 self.editor.affiche_infos(commentaire,Qt.red)
76 self.editor.affiche_infos(commentaire)
79 commentaire=tr("l expression n est pas de la forme a+bj")
80 self.editor.affiche_infos(commentaire,Qt.red)
82 def LEReelRPressed(self):
84 commentaire=tr("expression valide")
85 valeur = str(self.LEReel.text())
88 self.editor.affiche_infos(commentaire)
90 commentaire=tr("expression invalide")
91 self.editor.affiche_infos(commentaire,Qt.red)
92 if self.LEImag.text()!="" : self.ValeurPressed()
94 def LEImagRPressed(self):
96 commentaire=tr("expression valide")
97 valeur = str(self.LEImag.text())
100 self.editor.affiche_infos(commentaire)
102 commentaire=tr("expression invalide")
103 self.editor.affiche_infos(commentaire,Qt.red)
104 if self.LEReel.text()!="" : self.ValeurPressed()
106 def finCommentaire(self):
107 commentaire="valeur de type complexe"
110 def getValeurComp(self):
111 commentaire=tr("expression valide")
112 valeur = str(self.LEComp.text())
117 commentaire=tr("expression invalide")
118 self.editor.affiche_infos(commentaire,Qt.red)
123 commentaire=tr("expression n est pas de la forme a+bj")
124 self.editor.affiche_infos(commentaire,Qt.red)
129 def ValeurPressed(self):
130 if self.LEComp.text()== "" and (self.LEReel.text()=="" or self.LEImag.text()=="") :
132 if self.LEComp.text()== "" : valeur = self.getValeurRI()
134 if self.LEReel.text() != "" or self.LEImag.text() != "" :
135 commentaire=tr("entrer une seule valeur SVP")
136 self.editor.affiche_infos(commentaire,Qt.red)
138 valeur= self.getValeurComp()
139 self.politique.RecordValeur(valeur)
140 self.parentQt.donneFocus()
142 def getValeurRI(self):
144 Retourne le complexe saisi par l'utilisateur
147 if (self.RBMP.isChecked() == 1 ) :
149 elif (self.RBRI.isChecked() == 1) :
152 commentaire=tr("saisir le type de complexe")
153 self.editor.affiche_infos(commentaire,Qt.red)
156 l.append(string.atof(str(self.LEReel.text())))
157 l.append(string.atof(str(self.LEImag.text())))