2013-06-17 14:56:45 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-03-18 20:10:20 +03:00
|
|
|
# Copyright (C) 2007-2016 EDF R&D
|
2012-12-13 11:41:29 +00: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
|
2014-02-20 16:25:37 +04:00
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
2012-12-13 11:41:29 +00:00
|
|
|
#
|
|
|
|
# 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 13:05:47 +00:00
|
|
|
|
2016-06-14 14:57:25 +03:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import string
|
|
|
|
import types
|
2016-03-22 11:26:23 +03:00
|
|
|
import tempfile
|
2016-06-14 14:57:25 +03:00
|
|
|
import traceback
|
|
|
|
import pprint as PP #pretty print
|
2012-12-13 11:41:29 +00:00
|
|
|
|
2016-01-28 17:40:22 +03:00
|
|
|
from qtsalome import *
|
2012-12-13 11:41:29 +00:00
|
|
|
|
|
|
|
# Import des panels
|
2013-10-10 12:57:42 +00:00
|
|
|
from ViewText_ui import Ui_ViewExe
|
2013-06-17 14:56:45 +00:00
|
|
|
|
2016-06-14 14:57:25 +03:00
|
|
|
verbose = True
|
|
|
|
|
|
|
|
force = os.getenv("FORCE_DISTENE_LICENSE_FILE")
|
|
|
|
if force != None:
|
|
|
|
os.environ["DISTENE_LICENSE_FILE"] = force
|
|
|
|
os.environ["DLIM8VAR"] = "NOTHING"
|
|
|
|
|
2013-06-17 14:56:45 +00:00
|
|
|
class MonViewText(Ui_ViewExe, QDialog):
|
2012-12-13 11:41:29 +00:00
|
|
|
"""
|
|
|
|
Classe permettant la visualisation de texte
|
|
|
|
"""
|
2013-06-17 14:56:45 +00:00
|
|
|
def __init__(self, parent, txt):
|
2012-12-13 11:41:29 +00:00
|
|
|
QDialog.__init__(self,parent)
|
|
|
|
self.setupUi(self)
|
2013-06-17 14:56:45 +00:00
|
|
|
self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) )
|
2016-01-28 17:40:22 +03:00
|
|
|
# self.PB_Ok.clicked.connect(self.close)
|
|
|
|
self.PB_Ok.clicked.connect( self.theClose )
|
|
|
|
self.PB_Save.clicked.connect( self.saveFile )
|
2012-12-13 11:41:29 +00:00
|
|
|
self.monExe=QProcess(self)
|
|
|
|
|
2016-01-28 17:40:22 +03:00
|
|
|
self.monExe.readyReadStandardOutput.connect( self.readFromStdOut )
|
|
|
|
self.monExe.readyReadStandardError.connect( self.readFromStdErr )
|
2016-09-21 17:31:37 +02:00
|
|
|
self.monExe.finished.connect( self.finished )
|
2012-12-13 11:41:29 +00:00
|
|
|
|
2016-06-14 14:57:25 +03:00
|
|
|
cmds = ''
|
|
|
|
ext = ''
|
2016-03-22 11:26:23 +03:00
|
|
|
if sys.platform == "win32":
|
2016-09-21 17:31:37 +02:00
|
|
|
if os.path.exists(self.parent().fichierOut):
|
|
|
|
cmds += 'del %s\n' % self.parent().fichierOut
|
|
|
|
ext = '.bat'
|
2016-03-22 11:26:23 +03:00
|
|
|
else:
|
2016-06-14 14:57:25 +03:00
|
|
|
cmds += '#!/bin/bash\n'
|
|
|
|
cmds += 'pwd\n'
|
|
|
|
#cmds += 'which mg-surfopt.exe\n'
|
|
|
|
cmds += 'echo "DISTENE_LICENSE_FILE="$DISTENE_LICENSE_FILE\n'
|
|
|
|
cmds += 'echo "DLIM8VAR="$DLIM8VAR\n'
|
|
|
|
cmds += 'rm -f %s\n' % self.parent().fichierOut
|
|
|
|
ext = '.bash'
|
2016-03-22 11:26:23 +03:00
|
|
|
|
2016-06-14 14:57:25 +03:00
|
|
|
cmds += 'echo %s\n' % txt #to see what is compute command
|
|
|
|
cmds += txt+'\n'
|
|
|
|
cmds += 'echo "END_OF_MGSurfOpt"\n'
|
|
|
|
|
|
|
|
nomFichier = os.path.splitext(self.parent().fichierOut)[0] + ext
|
|
|
|
with open(nomFichier, 'w') as f:
|
|
|
|
f.write(cmds)
|
|
|
|
self.make_executable(nomFichier)
|
|
|
|
|
|
|
|
if verbose: print("INFO: MGSurfOpt launch script file: %s" % nomFichier)
|
|
|
|
|
|
|
|
self.monExe.start(nomFichier)
|
2012-12-13 11:41:29 +00:00
|
|
|
self.monExe.closeWriteChannel()
|
2013-06-17 14:56:45 +00:00
|
|
|
self.enregistreResultatsDone=False
|
2012-12-13 11:41:29 +00:00
|
|
|
self.show()
|
|
|
|
|
2016-06-14 14:57:25 +03:00
|
|
|
def make_executable(self, path):
|
|
|
|
mode = os.stat(path).st_mode
|
|
|
|
mode |= (mode & 0o444) >> 2 # copy R bits to X
|
|
|
|
os.chmod(path, mode)
|
|
|
|
|
2012-12-13 11:41:29 +00:00
|
|
|
def saveFile(self):
|
|
|
|
#recuperation du nom du fichier
|
|
|
|
savedir=os.environ['HOME']
|
2016-01-28 17:40:22 +03:00
|
|
|
fn = QFileDialog.getSaveFileName(None,"Save File",savedir)
|
2012-12-13 11:41:29 +00:00
|
|
|
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:
|
2016-01-28 17:40:22 +03:00
|
|
|
QMessageBox.critical(self, 'Save File',
|
|
|
|
'The file <b>%1</b> could not be saved.<br>Reason: %2'%(unicode(fn), str(why)))
|
2012-12-13 11:41:29 +00:00
|
|
|
|
|
|
|
def readFromStdErr(self):
|
|
|
|
a=self.monExe.readAllStandardError()
|
2016-01-28 17:40:22 +03:00
|
|
|
self.TB_Exe.append(unicode(a.data().encode()))
|
2012-12-13 11:41:29 +00:00
|
|
|
|
|
|
|
def readFromStdOut(self) :
|
|
|
|
a=self.monExe.readAllStandardOutput()
|
2016-07-08 11:37:47 +02:00
|
|
|
aa=unicode(a.data())
|
2016-09-21 17:31:37 +02:00
|
|
|
self.TB_Exe.append(aa)
|
|
|
|
|
|
|
|
def finished(self):
|
|
|
|
self.parent().enregistreResultat()
|
|
|
|
self.enregistreResultatsDone=True
|
2013-06-17 14:56:45 +00:00
|
|
|
|
|
|
|
def theClose(self):
|
|
|
|
if not self.enregistreResultatsDone:
|
|
|
|
self.parent().enregistreResultat()
|
|
|
|
self.enregistreResultatsDone=True
|
|
|
|
self.close()
|