Salome HOME
Modifications liees a MT
[tools/eficas.git] / InterfaceQT4 / monSelectVal.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017   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, QMessageBox
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         try :
88           f = open(self.file, "r")
89           self.texte = f.read()
90           f.close()
91         except :
92           QMessageBox.warning( self,tr( "Fichier Indisponible"),tr( "Lecture impossible"))
93           self.texte=""
94           return
95
96   def initVal(self):
97         self.TBtext.clear()
98         self.TBtext.setText(self.texte)
99
100   def selectEsp(self):
101         self.separateur=" "
102         
103   def selectVir(self):
104         self.separateur=","
105         
106   def selectPoint(self):
107         self.separateur=";"
108         
109   def BImportSelPressed(self):
110
111         texte = self.TBtext.textCursor().selectedText()
112         textTraite=texte.replace(u'\u2029',"\n")
113         self.textTraite=str(textTraite)
114         self.traitement()
115         
116   def BImportToutPressed(self):
117         self.textTraite=self.texte
118         self.traitement()
119
120   def traitement(self):
121         if self.textTraite == "" : return
122         if self.textTraite[-1]=="\n" : self.textTraite=self.textTraite[0:-1]
123         self.textTraite=self.textTraite.replace("\n",self.separateur)
124         liste1=self.textTraite.split(self.separateur)
125         liste=[]
126         for val in liste1 :
127           if val != '' and val != ' ' and val != self.separateur :
128             val=str(val)
129             try :
130             #if 1 :
131                val2=eval(val,{})
132                liste.append(val2)
133             except :
134               pass
135         self.parent.ajoutNValeur(liste) 
136