Salome HOME
QString et ses amis
[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 determine import monEnvQT5
25
26 if monEnvQT5:
27     from PyQt5.QtWidgets import QDialog
28     from PyQt5.QtCore import QTimer
29 else :
30     from PyQt4.QtGui  import *
31     from PyQt4.QtCore import *
32
33 class DSelVal(Ui_DSelVal,QDialog):
34    def __init__(self,parent ,modal ) :
35        QDialog.__init__(self,parent)
36        self.setupUi(self)
37
38 class MonSelectVal(DSelVal):
39   """
40   Classe definissant le panel associe aux mots-cles qui demandent
41   a l'utilisateur de choisir une seule valeur parmi une liste de valeurs
42   discretes
43   """
44   def __init__(self,file,parent,name = None,fl = 0):
45         #print "MonSelectVal"
46         self.parent=parent
47         DSelVal.__init__(self,parent,0)
48         self.separateur=" "
49         self.texte=" "
50         self.textTraite=""
51         self.file=str(file)
52         self.readVal()
53         self.initVal()
54         if monEnvQT5: self.connecterSignaux()
55         else : self.connecterSignauxQT4()
56
57   def connecterSignaux(self) :
58         self.Bespace.clicked.connect(self.SelectEsp)
59         self.BpointVirgule.clicked.connect(self.SelectPoint)
60         self.Bvirgule.clicked.connect(self.SelectVir)
61         self.BImportSel.clicked.connect(self.BImportSelPressed)
62         self.BImportTout.clicked.connect(self.BImportToutPressed)
63         self.parent.editor.sb.messageChanged.connect(self.messageAChanger)
64
65   def connecterSignauxQT4(self) :
66         self.connect(self.Bespace,SIGNAL("clicked()"),self.SelectEsp)
67         self.connect(self.BpointVirgule,SIGNAL("clicked()"),self.SelectPoint)
68         self.connect(self.Bvirgule,SIGNAL("clicked()"),self.SelectVir)
69         self.connect(self.BImportSel,SIGNAL("clicked()"),self.BImportSelPressed)
70         self.connect(self.BImportTout,SIGNAL("clicked()"),self.BImportToutPressed)
71         self.connect(self.parent.editor.sb,SIGNAL("messageChanged(QString)"),self.messageAChanger)
72
73   def messageAChanger(self):
74       message=self.parent.editor.sb.currentMessage()
75       mapalette=self.sb.palette()
76       from PyQt4.QtGui import QPalette
77       mapalette.setColor( QPalette.WindowText, self.parent.editor.couleur )
78       self.sb.setPalette( mapalette );
79       self.sb.setText(tr(message))
80       QTimer.singleShot(3000, self.efface)
81       
82   def efface(self):
83       self.sb.setText("")
84
85   def readVal(self):
86         if self.file == "" : return
87         f = open(self.file, "rb")
88         self.texte = f.read()
89         f.close()
90
91   def initVal(self):
92         self.TBtext.clear()
93         self.TBtext.setText(self.texte)
94
95   def SelectEsp(self):
96         self.separateur=" "
97         
98   def SelectVir(self):
99         self.separateur=","
100         
101   def SelectPoint(self):
102         self.separateur=";"
103         
104   def BImportSelPressed(self):
105
106         texte = self.TBtext.textCursor().selectedText()
107         textTraite=texte.replace(u'\u2029',"\n")
108         self.textTraite=str(textTraite)
109         self.Traitement()
110         
111   def BImportToutPressed(self):
112         self.textTraite=self.texte
113         self.Traitement()
114
115   def Traitement(self):
116         import string
117         if self.textTraite == "" : return
118         if self.textTraite[-1]=="\n" : self.textTraite=self.textTraite[0:-1]
119         self.textTraite=string.replace(self.textTraite,"\n",self.separateur)
120         liste1=self.textTraite.split(self.separateur)
121         liste=[]
122         for val in liste1 :
123           if val != '' and val != ' ' and val != self.separateur :
124             val=str(val)
125             try :
126                val2=eval(val,{})
127                liste.append(val2)
128             except :
129               pass
130         self.parent.ajoutNValeur(liste) 
131         
132