]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/monWidgetRadioButton.py
Salome HOME
update version
[tools/eficas.git] / InterfaceQT4 / monWidgetRadioButton.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021   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 from __future__ import absolute_import
22 from __future__ import print_function
23 try :
24     from builtins import str
25 except : pass
26
27 import types,os
28
29 from PyQt5.QtCore     import  Qt
30 from PyQt5.QtWidgets  import  QWidget
31
32 # Modules Eficas
33
34 from Extensions.i18n import tr
35
36 from .feuille               import Feuille
37 from desWidgetRadioButton  import Ui_WidgetRadioButton
38 from .politiquesValidation  import PolitiqueUnique
39 from .qtSaisie              import SaisieValeur
40
41
42 class MonWidgetRadioButtonCommun (Feuille):
43     def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
44         self.setMaxI()
45         Feuille.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
46         self.politique=PolitiqueUnique(self.node,self.editor)
47         self.dict_bouton={}
48         self.determineChoix()
49         self.setValeursApresBouton()
50         self.parentQt.commandesLayout.insertWidget(-1,self)
51         self.AAfficher=self.radioButton_1
52         self.maCommande.listeAffichageWidget.append(self.radioButton_1)
53
54
55     def setValeursApresBouton(self):
56         if self.objSimp.getValeur()==None : return
57         valeur=self.objSimp.getValeur()
58         if not(isinstance(valeur, str)) : valeur = str(valeur)
59         try :
60             self.dict_bouton[valeur].setChecked(True)
61             self.dict_bouton[valeur].setFocus(True)
62         except :
63             pass
64
65     def determineChoix(self):
66         self.horizontalLayout.setAlignment(Qt.AlignLeft)
67         i=1
68         j=len(self.maListeDeValeur)
69         if j > self.maxI :
70             print ("poumbadaboum")
71             return
72         while i < j+1 :
73             nomBouton="radioButton_"+str(i)
74             bouton=getattr(self,nomBouton)
75             valeur=self.maListeDeValeur[i-1]
76             if not(isinstance(valeur, str)) : valeur = str(valeur)
77             bouton.setText(tr(valeur))
78             self.dict_bouton[valeur]=bouton
79             bouton.clicked.connect(self.boutonclic)
80             bouton.keyPressEvent=self.keyPressEvent
81             setattr(self,nomBouton,bouton)
82             i=i+1
83         while i < self.maxI +1 :
84             nomBouton="radioButton_"+str(i)
85             bouton=getattr(self,nomBouton)
86             bouton.close()
87             i=i+1
88
89     def boutonclic(self):
90         for valeur in self.dict_bouton:
91             if self.dict_bouton[valeur].isChecked():
92                 SaisieValeur.LEvaleurPressed(self,valeur)
93         self.reaffiche()
94
95
96     def keyPressEvent(self, event):
97         if event.key() == Qt.Key_Right : self.selectSuivant(); return
98         if event.key() == Qt.Key_Left  : self.selectPrecedent(); return
99         if event.key() == Qt.Key_Return or event.key() == Qt.Key_Space : self.checkFocused(); return
100         QWidget.keyPressEvent(self,event)
101
102     def selectSuivant(self):
103         aLeFocus=self.focusWidget()
104         nom=aLeFocus.objectName()[12:]
105         i=int(nom)+1
106         if i ==  len(self.maListeDeValeur) +1 : i=1
107         nomBouton="radioButton_"+str(i)
108         courant=getattr(self,nomBouton)
109         courant.setFocus(True)
110
111     def selectPrecedent(self):
112         aLeFocus=self.focusWidget()
113         nom=aLeFocus.objectName()[12:]
114         i=int(nom)-1
115         if i == 0 : i= len(self.maListeDeValeur)
116         nomBouton="radioButton_"+str(i)
117         courant=getattr(self,nomBouton)
118         courant.setFocus(True)
119
120     def checkFocused(self):
121         aLeFocus=self.focusWidget()
122         nom=aLeFocus.objectName()[12:]
123         i=int(nom)
124         if i > 0 and i <= len(self.maListeDeValeur):
125             nomBouton="radioButton_"+str(i)
126             courant=getattr(self,nomBouton)
127             if not courant.isChecked():
128                 courant.setChecked(True)
129                 self.boutonclic()
130
131
132 class MonWidgetRadioButton (Ui_WidgetRadioButton,MonWidgetRadioButtonCommun):
133     def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
134             #print "MonWidgetRadioButton ", self
135         if type(monSimpDef.into) ==types.FunctionType : self.maListeDeValeur=monSimpDef.into()
136         else : self.maListeDeValeur=monSimpDef.into
137
138         MonWidgetRadioButtonCommun.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
139
140     def setMaxI(self):
141         self.maxI=3
142
143
144 class MonWidgetRadioButtonSD (Ui_WidgetRadioButton,MonWidgetRadioButtonCommun):
145
146     def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
147         #print "dans le init de MonWidgetRadioButtonSD",self
148         self.maListeDeValeur=node.item.getSdAvantDuBonType()
149         MonWidgetRadioButtonCommun.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
150
151     def setMaxI(self):
152         self.maxI=3