2013-06-17 20:56:45 +06:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-04-01 19:05:47 +06:00
|
|
|
# Copyright (C) 2007-2013 EDF R&D
|
2012-12-13 17:41:29 +06:00
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
|
|
|
#
|
2013-04-01 19:05:47 +06:00
|
|
|
|
2012-12-13 17:41:29 +06:00
|
|
|
# Modules Python
|
|
|
|
import string,types,os
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
from PyQt4 import *
|
|
|
|
from PyQt4.QtGui import *
|
|
|
|
from PyQt4.QtCore import *
|
|
|
|
|
|
|
|
# Import des panels
|
|
|
|
|
2013-10-10 18:57:42 +06:00
|
|
|
from ViewText_ui import Ui_ViewExe
|
2013-06-17 20:56:45 +06:00
|
|
|
|
|
|
|
class MonViewText(Ui_ViewExe, QDialog):
|
2012-12-13 17:41:29 +06:00
|
|
|
"""
|
|
|
|
Classe permettant la visualisation de texte
|
|
|
|
"""
|
2013-06-17 20:56:45 +06:00
|
|
|
def __init__(self, parent, txt):
|
2012-12-13 17:41:29 +06:00
|
|
|
QDialog.__init__(self,parent)
|
|
|
|
self.setupUi(self)
|
2013-06-17 20:56:45 +06:00
|
|
|
self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) )
|
|
|
|
#self.connect( self.PB_Ok,SIGNAL("clicked()"), self, SLOT("close()") )
|
|
|
|
self.connect( self.PB_Ok,SIGNAL("clicked()"), self.theClose )
|
2012-12-13 17:41:29 +06:00
|
|
|
self.connect( self.PB_Save,SIGNAL("clicked()"), self.saveFile )
|
|
|
|
self.monExe=QProcess(self)
|
|
|
|
|
|
|
|
self.connect(self.monExe, SIGNAL("readyReadStandardOutput()"), self.readFromStdOut )
|
|
|
|
self.connect(self.monExe, SIGNAL("readyReadStandardError()"), self.readFromStdErr )
|
|
|
|
|
|
|
|
# Je n arrive pas a utiliser le setEnvironment du QProcess
|
|
|
|
# fonctionne hors Salome mais pas dans Salome ???
|
2013-06-17 20:56:45 +06:00
|
|
|
cmds=''
|
|
|
|
try :
|
|
|
|
LICENCE_FILE=os.environ["DISTENE_LICENCE_FILE_FOR_YAMS"]
|
|
|
|
except:
|
|
|
|
LICENCE_FILE=''
|
|
|
|
try :
|
|
|
|
PATH=os.environ["DISTENE_PATH_FOR_YAMS"]
|
|
|
|
except:
|
|
|
|
PATH=''
|
|
|
|
if LICENCE_FILE != '':
|
|
|
|
cmds+='source '+LICENCE_FILE+'\n'
|
|
|
|
else:
|
|
|
|
cmds+="# $DISTENE_LICENCE_FILE_FOR_YAMS NOT SET\n"
|
|
|
|
if PATH != '':
|
|
|
|
cmds+='export PATH='+PATH+':$PATH\n'
|
|
|
|
else:
|
|
|
|
cmds+="# $DISTENE_PATH_FOR_YAMS NOT SET\n"
|
|
|
|
#cmds+='env\n'
|
|
|
|
cmds+='rm -f '+self.parent().fichierOut+'\n'
|
|
|
|
cmds+=txt+'\n'
|
|
|
|
cmds+='echo END_OF_Yams\n'
|
2012-12-13 17:41:29 +06:00
|
|
|
pid=self.monExe.pid()
|
2013-06-17 20:56:45 +06:00
|
|
|
nomFichier='/tmp/Yams_'+str(pid)+'.sh'
|
2012-12-13 17:41:29 +06:00
|
|
|
f=open(nomFichier,'w')
|
2013-06-17 20:56:45 +06:00
|
|
|
f.write(cmds)
|
2012-12-13 17:41:29 +06:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
maBidouille='sh ' + nomFichier
|
|
|
|
self.monExe.start(maBidouille)
|
|
|
|
self.monExe.closeWriteChannel()
|
2013-06-17 20:56:45 +06:00
|
|
|
self.enregistreResultatsDone=False
|
2012-12-13 17:41:29 +06:00
|
|
|
self.show()
|
|
|
|
|
|
|
|
def saveFile(self):
|
|
|
|
#recuperation du nom du fichier
|
|
|
|
savedir=os.environ['HOME']
|
|
|
|
fn = QFileDialog.getSaveFileName(None, self.trUtf8("Save File"),savedir)
|
|
|
|
if fn.isNull() : return
|
|
|
|
ulfile = os.path.abspath(unicode(fn))
|
|
|
|
try:
|
|
|
|
f = open(fn, 'wb')
|
|
|
|
f.write(str(self.TB_Exe.toPlainText()))
|
|
|
|
f.close()
|
|
|
|
except IOError, why:
|
|
|
|
QMessageBox.critical(self, self.trUtf8('Save File'),
|
|
|
|
self.trUtf8('The file <b>%1</b> could not be saved.<br>Reason: %2')
|
|
|
|
.arg(unicode(fn)).arg(str(why)))
|
|
|
|
|
|
|
|
def readFromStdErr(self):
|
|
|
|
a=self.monExe.readAllStandardError()
|
2013-06-17 20:56:45 +06:00
|
|
|
self.TB_Exe.append(QString.fromUtf8(a.data(),len(a)))
|
2012-12-13 17:41:29 +06:00
|
|
|
|
|
|
|
def readFromStdOut(self) :
|
|
|
|
a=self.monExe.readAllStandardOutput()
|
2013-06-17 20:56:45 +06:00
|
|
|
aa=QString.fromUtf8(a.data(),len(a))
|
|
|
|
self.TB_Exe.append(aa)
|
|
|
|
if "END_OF_Yams" in aa:
|
|
|
|
self.parent().enregistreResultat()
|
|
|
|
self.enregistreResultatsDone=True
|
|
|
|
#self.theClose()
|
|
|
|
|
|
|
|
def theClose(self):
|
|
|
|
if not self.enregistreResultatsDone:
|
|
|
|
self.parent().enregistreResultat()
|
|
|
|
self.enregistreResultatsDone=True
|
|
|
|
self.close()
|