X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FTools%2FYamsPlug%2FmonViewText.py;h=9d92a0c55a7eac476d31cc47d38bc3f10d865d62;hb=a38b958b273ded56f74a783859e0781aa49e8787;hp=19dcd3ea238fbdb6a2a10c09b7a4a27648261313;hpb=1067ffa6e7e5c394e3a1b17219d8b355a57607cd;p=modules%2Fsmesh.git diff --git a/src/Tools/YamsPlug/monViewText.py b/src/Tools/YamsPlug/monViewText.py index 19dcd3ea2..9d92a0c55 100644 --- a/src/Tools/YamsPlug/monViewText.py +++ b/src/Tools/YamsPlug/monViewText.py @@ -1,10 +1,10 @@ -# -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2012 EDF R&D +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2016 EDF R&D # # 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. +# version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -17,70 +17,110 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -# Modules Python -import string,types,os + +import os +import sys +import string +import types +import tempfile import traceback +import pprint as PP #pretty print -from PyQt4 import * -from PyQt4.QtGui import * -from PyQt4.QtCore import * +from qtsalome import * # Import des panels +from ViewText_ui import Ui_ViewExe + +verbose = True + +force = os.getenv("FORCE_DISTENE_LICENSE_FILE") +if force != None: + os.environ["DISTENE_LICENSE_FILE"] = force + os.environ["DLIM8VAR"] = "NOTHING" -# ------------------------------- # -from ViewText import Ui_ViewExe -class MonViewText(Ui_ViewExe,QDialog): -# ------------------------------- # +class MonViewText(Ui_ViewExe, QDialog): """ Classe permettant la visualisation de texte """ - def __init__(self,parent,txt): + def __init__(self, parent, txt): QDialog.__init__(self,parent) self.setupUi(self) - self.resize( QSize(600,600).expandedTo(self.minimumSizeHint()) ) - self.connect( self.PB_Ok,SIGNAL("clicked()"), self, SLOT("close()") ) - self.connect( self.PB_Save,SIGNAL("clicked()"), self.saveFile ) + self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) ) + # self.PB_Ok.clicked.connect(self.close) + self.PB_Ok.clicked.connect( self.theClose ) + self.PB_Save.clicked.connect( self.saveFile ) self.monExe=QProcess(self) + self.monExe.readyReadStandardOutput.connect( self.readFromStdOut ) + self.monExe.readyReadStandardError.connect( self.readFromStdErr ) + self.monExe.finished.connect( self.finished ) + + cmds = '' + ext = '' + if sys.platform == "win32": + if os.path.exists(self.parent().fichierOut): + cmds += 'del %s\n' % self.parent().fichierOut + ext = '.bat' + else: + 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' + + cmds += 'echo %s\n' % txt #to see what is compute command + cmds += txt+'\n' + cmds += 'echo "END_OF_MGSurfOpt"\n' - 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 ??? - LICENCE=os.environ['DISTENE_LICENCE_FILE_FOR_YAMS'] - txt='export DISTENE_LICENSE_FILE='+LICENCE+';'+ txt - pid=self.monExe.pid() - nomFichier='/tmp/yam_'+str(pid)+'.py' - f=open(nomFichier,'w') - f.write(txt) - f.close() - - maBidouille='sh ' + nomFichier - self.monExe.start(maBidouille) + 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) self.monExe.closeWriteChannel() + self.enregistreResultatsDone=False self.show() - + def make_executable(self, path): + mode = os.stat(path).st_mode + mode |= (mode & 0o444) >> 2 # copy R bits to X + os.chmod(path, mode) + 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)) + fn, mask = QFileDialog.getSaveFileName(None,"Save File",savedir) + if not fn: return + ulfile = os.path.abspath(str(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 %1 could not be saved.
Reason: %2') - .arg(unicode(fn)).arg(str(why))) + f = open(fn, 'wb') + f.write(self.TB_Exe.toPlainText().encode("utf-8")) + f.close() + except IOError as why: + QMessageBox.critical(self, 'Save File', + 'The file %s could not be saved.
Reason: %s'%(str(fn), str(why))) def readFromStdErr(self): a=self.monExe.readAllStandardError() - self.TB_Exe.append(QString.fromUtf8(a.data(),len(a))) ; + aa=a.data().decode(errors='ignore') + self.TB_Exe.append(aa) def readFromStdOut(self) : a=self.monExe.readAllStandardOutput() - self.TB_Exe.append(QString.fromUtf8(a.data(),len(a))) ; + aa=a.data().decode(errors='ignore') + self.TB_Exe.append(aa) + + def finished(self): + self.parent().enregistreResultat() + self.enregistreResultatsDone=True + + def theClose(self): + if not self.enregistreResultatsDone: + self.parent().enregistreResultat() + self.enregistreResultatsDone=True + self.close()