1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2015 EDF R&D
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, or (at your option) any later version.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 import string,types,os
25 from qtsalome import *
29 from ViewText_ui import Ui_ViewExe
31 class MonViewText(Ui_ViewExe, QDialog):
33 Classe permettant la visualisation de texte
35 def __init__(self, parent, txt):
36 QDialog.__init__(self,parent)
38 self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) )
39 # self.PB_Ok.clicked.connect(self.close)
40 self.PB_Ok.clicked.connect( self.theClose )
41 self.PB_Save.clicked.connect( self.saveFile )
42 self.monExe=QProcess(self)
44 self.monExe.readyReadStandardOutput.connect( self.readFromStdOut )
45 self.monExe.readyReadStandardError.connect( self.readFromStdErr )
47 # Je n arrive pas a utiliser le setEnvironment du QProcess
48 # fonctionne hors Salome mais pas dans Salome ???
50 cmds+='rm -f '+self.parent().fichierOut+'\n'
52 cmds+='echo END_OF_Yams\n'
54 nomFichier='/tmp/Yams_'+str(pid)+'.sh'
55 f=open(nomFichier,'w')
59 maBidouille='sh ' + nomFichier
60 self.monExe.start(maBidouille)
61 self.monExe.closeWriteChannel()
62 self.enregistreResultatsDone=False
66 #recuperation du nom du fichier
67 savedir=os.environ['HOME']
68 fn = QFileDialog.getSaveFileName(None,"Save File",savedir)
69 if fn.isNull() : return
70 ulfile = os.path.abspath(unicode(fn))
73 f.write(str(self.TB_Exe.toPlainText()))
76 QMessageBox.critical(self, 'Save File',
77 'The file <b>%1</b> could not be saved.<br>Reason: %2'%(unicode(fn), str(why)))
79 def readFromStdErr(self):
80 a=self.monExe.readAllStandardError()
81 self.TB_Exe.append(unicode(a.data().encode()))
83 def readFromStdOut(self) :
84 a=self.monExe.readAllStandardOutput()
85 aa=unicode(a.data(),len(a))
86 self.TB_Exe.append(aa)
87 if "END_OF_Yams" in aa:
88 self.parent().enregistreResultat()
89 self.enregistreResultatsDone=True
93 if not self.enregistreResultatsDone:
94 self.parent().enregistreResultat()
95 self.enregistreResultatsDone=True