Salome HOME
legere difference ds VARIABLES_TO_BE...
[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 __future__ import absolute_import
24 try :
25    from builtins import str
26 except : pass
27
28 from desSelectVal import Ui_DSelVal
29 from Extensions.i18n import tr
30
31 from PyQt5.QtWidgets import QDialog, QFileDialog
32 from PyQt5.QtCore import QTimer, Qt
33 from PyQt5.QtGui import QPalette
34
35 class DSelVal(Ui_DSelVal,QDialog):
36    def __init__(self,parent ,modal ) :
37        QDialog.__init__(self,parent)
38        self.setupUi(self)
39
40 class MonSelectVal(DSelVal):
41   """
42   Classe definissant le panel associe aux mots-cles qui demandent
43   a l'utilisateur de choisir une seule valeur parmi une liste de valeurs
44   discretes
45   """
46   def __init__(self,file,parent,name = None,fl = 0):
47         #print "MonSelectVal"
48         self.parent=parent
49         DSelVal.__init__(self,parent,0)
50         self.separateur=" "
51         self.texte=" "
52         self.textTraite=""
53         self.file=str(file)
54         self.readVal()
55         self.initVal()
56         self.connecterSignaux()
57
58   def connecterSignaux(self) :
59         self.Bespace.clicked.connect(self.SelectEsp)
60         self.BpointVirgule.clicked.connect(self.SelectPoint)
61         self.Bvirgule.clicked.connect(self.SelectVir)
62         self.BImportSel.clicked.connect(self.BImportSelPressed)
63         self.BImportTout.clicked.connect(self.BImportToutPressed)
64         self.parent.editor.sb.messageChanged.connect(self.messageAChanger)
65
66   def connecterSignauxQT4(self) :
67         self.connect(self.Bespace,SIGNAL("clicked()"),self.SelectEsp)
68         self.connect(self.BpointVirgule,SIGNAL("clicked()"),self.SelectPoint)
69         self.connect(self.Bvirgule,SIGNAL("clicked()"),self.SelectVir)
70         self.connect(self.BImportSel,SIGNAL("clicked()"),self.BImportSelPressed)
71         self.connect(self.BImportTout,SIGNAL("clicked()"),self.BImportToutPressed)
72         self.connect(self.parent.editor.sb,SIGNAL("messageChanged(QString)"),self.messageAChanger)
73
74   def messageAChanger(self):
75       message=self.parent.editor.sb.currentMessage()
76       mapalette=self.sb.palette()
77       mapalette.setColor( QPalette.Text,Qt.red )
78       self.sb.setPalette( mapalette )
79       self.sb.setText(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, "r")
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         if self.textTraite == "" : return
117         if self.textTraite[-1]=="\n" : self.textTraite=self.textTraite[0:-1]
118         self.textTraite=self.textTraite.replace("\n",self.separateur)
119         liste1=self.textTraite.split(self.separateur)
120         liste=[]
121         for val in liste1 :
122           if val != '' and val != ' ' and val != self.separateur :
123             val=str(val)
124             try :
125                val2=eval(val,{})
126                liste.append(val2)
127             except :
128               pass
129         self.parent.ajoutNValeur(liste) 
130         
131