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