Salome HOME
Merge remote branch 'origin/nouvelEficas' into nouvelEficas
[tools/eficas.git] / InterfaceQT4 / monSelectVal.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 # Modules Eficas
22
23 from desSelectVal import Ui_DSelVal
24 from PyQt4.QtGui import *
25 from PyQt4.QtCore import *
26
27 class DSelVal(Ui_DSelVal,QDialog):
28    def __init__(self,parent ,modal ) :
29        QDialog.__init__(self,parent)
30        self.setupUi(self)
31
32 class MonSelectVal(DSelVal):
33   """
34   Classe definissant le panel associe aux mots-cles qui demandent
35   a l'utilisateur de choisir une seule valeur parmi une liste de valeurs
36   discretes
37   """
38   def __init__(self,file,parent,name = None,fl = 0):
39         #print "MonSelectVal"
40         self.FonctPanel=parent
41         DSelVal.__init__(self,parent,0)
42         self.separateur=" "
43         self.texte=" "
44         self.textTraite=""
45         self.file=str(file)
46         self.readVal()
47         self.initVal()
48         self.connecterSignaux()
49
50   def connecterSignaux(self) :
51         self.connect(self.Bespace,SIGNAL("clicked()"),self.SelectEsp)
52         self.connect(self.BpointVirgule,SIGNAL("clicked()"),self.SelectPoint)
53         self.connect(self.Bvirgule,SIGNAL("clicked()"),self.SelectVir)
54         self.connect(self.BImportSel,SIGNAL("clicked()"),self.BImportSelPressed)
55         self.connect(self.BImportTout,SIGNAL("clicked()"),self.BImportToutPressed)
56
57   def readVal(self):
58         if self.file == "" : return
59         f = open(self.file, "rb")
60         self.texte = f.read()
61         f.close()
62
63   def initVal(self):
64         self.TBtext.clear()
65         self.TBtext.setText(self.texte)
66
67   def SelectEsp(self):
68         self.separateur=" "
69         
70   def SelectVir(self):
71         self.separateur=","
72         
73   def SelectPoint(self):
74         self.separateur=";"
75         
76   def BImportSelPressed(self):
77
78         texte = self.TBtext.textCursor().selectedText()
79         textTraite=texte.replace(u'\u2029',"\n")
80         self.textTraite=str(textTraite)
81         self.Traitement()
82         
83   def BImportToutPressed(self):
84         self.textTraite=self.texte
85         self.Traitement()
86
87   def Traitement(self):
88         import string
89         if self.textTraite == "" : return
90         if self.textTraite[-1]=="\n" : self.textTraite=self.textTraite[0:-1]
91         self.textTraite=string.replace(self.textTraite,"\n",self.separateur)
92         liste1=self.textTraite.split(self.separateur)
93         liste=[]
94         for val in liste1 :
95           if val != '' and val != ' ' and val != self.separateur :
96             val=str(val)
97             try :
98                val2=eval(val,{})
99                liste.append(val2)
100             except :
101               pass
102         print self.FonctPanel.AjoutNValeur 
103         self.FonctPanel.AjoutNValeur(liste)