1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021 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 from __future__ import absolute_import
23 from builtins import str
26 import types,os, locale
29 from PyQt5.QtWidgets import QLineEdit, QRadioButton
30 from PyQt5.QtCore import Qt
33 from Extensions.i18n import tr
35 from .feuille import Feuille
36 from desWidgetSimpComplexe import Ui_WidgetSimpComplexe
37 from .politiquesValidation import PolitiqueUnique
38 from .qtSaisie import SaisieValeur
41 class MonWidgetSimpComplexe (Ui_WidgetSimpComplexe,Feuille):
43 def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
44 Feuille.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
45 self.parentQt.commandesLayout.insertWidget(-1,self)
46 self.setFocusPolicy(Qt.StrongFocus)
47 self.LEImag.returnPressed.connect(self.LEImagRPressed)
48 self.LEReel.returnPressed.connect(self.LEReelRPressed)
49 self.RBRI.clicked.connect(self.valeurPressed )
50 self.RBMP.clicked.connect(self.valeurPressed )
51 self.maCommande.listeAffichageWidget.append(self.RBRI)
52 self.maCommande.listeAffichageWidget.append(self.RBMP)
53 self.maCommande.listeAffichageWidget.append(self.LEReel)
54 self.maCommande.listeAffichageWidget.append(self.LEImag)
58 self.politique=PolitiqueUnique(self.node,self.editor)
59 valeur=self.node.item.getValeur()
60 if valeur == None or valeur == '' : return
61 if type(valeur) not in (list,tuple) :
62 self.LEComp.setText(str(valeur))
63 commentaire=tr('complexe form deprecated, od value : ', valeur)
64 self.editor.afficheInfos(commentaire,Qt.red)
67 self.LEReel.setText(str(x1))
68 self.LEImag.setText(str(x2))
70 self.RBRI.setChecked(1)
72 self.RBMP.setChecked(1)
74 #def LECompRPressed(self) :
77 # commentaire=tr("expression valide")
78 # valeur = str(self.LEComp.text())
84 # commentaire=tr("expression invalide")
85 # self.editor.afficheInfos(commentaire,Qt.red)
89 # self.editor.afficheInfos(commentaire)
90 # self.valeurPressed()
92 # commentaire=tr("l expression n est pas de la forme a+bj")
93 # self.editor.afficheInfos(commentaire,Qt.red)
95 def LEReelRPressed(self):
97 commentaire=tr("expression valide")
98 valeur = str(self.LEReel.text())
100 a=locale.atof(valeur)
101 self.editor.afficheInfos(commentaire)
103 commentaire=tr("expression invalide")
104 self.editor.afficheInfos(commentaire,Qt.red)
105 if self.LEImag.text()!="" : self.valeurPressed()
106 else : self.LEImag.setFocus(True)
108 def LEImagRPressed(self):
109 commentaire=tr("expression valide")
110 valeur = str(self.LEImag.text())
112 a=locale.atof(valeur)
113 self.editor.afficheInfos(commentaire)
115 commentaire=tr("expression invalide")
116 self.editor.afficheInfos(commentaire,Qt.red)
117 if self.LEReel.text()!="" : self.valeurPressed()
118 else : self.LEReel.setFocus(True)
120 def finCommentaire(self):
121 commentaire="valeur de type complexe"
124 #def getValeurComp(self):
125 # commentaire=tr("expression valide")
126 # valeur = str(self.LEComp.text())
131 # commentaire=tr("expression invalide")
132 # self.editor.afficheInfos(commentaire,Qt.red)
137 # commentaire=tr("expression n est pas de la forme a+bj")
138 # self.editor.afficheInfos(commentaire,Qt.red)
143 def valeurPressed(self):
144 if (self.LEReel.text()=="" and self.LEImag.text()=="") : self.LEReel.setFocus(True)
145 if (self.LEReel.text()=="" and self.LEImag.text()!="") : self.LEReel.setFocus(True)
146 if (self.LEReel.text()!="" and self.LEImag.text()=="") : self.LEImag.setFocus(True)
147 valeur = self.getValeurRI()
148 self.politique.recordValeur(valeur)
150 self.parentQt.donneFocus()
152 def getValeurRI(self):
154 Retourne le complexe saisi par l'utilisateur
157 if (self.RBMP.isChecked() == 1 ) : l.append("MP")
158 elif (self.RBRI.isChecked() == 1) : l.append("RI")
160 self.editor.afficheInfos(commentaire,Qt.red)
161 self.RBMP.setFocus(True)
164 l.append(locale.atof(str(self.LEReel.text())))
165 l.append(locale.atof(str(self.LEImag.text())))
168 return repr(tuple(l))