X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FTools%2FMGCleanerPlug%2FMGCleanerMonViewText.py;h=c45e4cdf5244f817c2ccabb2a19077e4d69536f8;hp=b139a0d4c0db6e96c9ce5df36544ad86977f5317;hb=0fc0831670e27a5611b941c52dc152fd63964515;hpb=b0a908c0d20341651771d0249fb10882f54b2aad diff --git a/src/Tools/MGCleanerPlug/MGCleanerMonViewText.py b/src/Tools/MGCleanerPlug/MGCleanerMonViewText.py index b139a0d4c..c45e4cdf5 100644 --- a/src/Tools/MGCleanerPlug/MGCleanerMonViewText.py +++ b/src/Tools/MGCleanerPlug/MGCleanerMonViewText.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2007-2014 EDF R&D +# Copyright (C) 2013-2020 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 @@ -19,100 +19,115 @@ # # 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 MGCleanerViewText_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" + class MGCleanerMonViewText(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(1000,600).expandedTo(self.minimumSizeHint()) ) - #self.connect( self.PB_Ok,SIGNAL("clicked()"), self, SLOT("close()") ) - self.connect( self.PB_Ok,SIGNAL("clicked()"), self.theClose ) - self.connect( self.PB_Save,SIGNAL("clicked()"), self.saveFile ) + self.PB_Ok.clicked.connect( self.theClose ) + # Button OK is disabled until computation is finished + self.PB_Ok.setEnabled(False) + # Button cancel allows to kill the computation + # It is disabled when the computation is finished + self.PB_Cancel.clicked.connect( self.cancelComputation ) + self.PB_Cancel.setToolTip("Cancel computation") + self.PB_Save.clicked.connect( self.saveFile ) self.PB_Save.setToolTip("Save trace in log file") self.PB_Ok.setToolTip("Close view") 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 ??? - cmds='' - try : - LICENCE_FILE=os.environ["DISTENE_LICENCE_FILE_FOR_MGCLEANER"] - except: - LICENCE_FILE='' - try : - PATH=os.environ["DISTENE_PATH_FOR_MGCLEANER"] - except: - PATH='' - if LICENCE_FILE != '': - cmds+='source '+LICENCE_FILE+'\n' - else: - cmds+="# $DISTENE_LICENCE_FILE_FOR_MGCLEANER NOT SET\n" - if PATH != '': - cmds+='export PATH='+PATH+':$PATH\n' - else: - cmds+="# $DISTENE_PATH_FOR_MGCLEANER NOT SET\n" - #cmds+='env\n' - cmds+='rm -f '+self.parent().fichierOut+'\n' - cmds+=txt+'\n' - cmds+='echo END_OF_MGCleaner\n' - pid=self.monExe.pid() - nomFichier='/tmp/MGCleaner_'+str(pid)+'.sh' - f=open(nomFichier,'w') - f.write(cmds) - f.close() - - maBidouille='sh ' + nomFichier - self.monExe.start(maBidouille) + self.monExe.readyReadStandardOutput.connect( self.readFromStdOut ) + self.monExe.readyReadStandardError.connect( self.readFromStdErr ) + self.monExe.finished.connect( self.finished ) + self.monExe.errorOccurred.connect( self.errorOccured ) + + if os.path.exists(self.parent().fichierOut): + os.remove(self.parent().fichierOut) + + self.monExe.start(txt) self.monExe.closeWriteChannel() - self.enregistreResultatsDone=False + self.hasBeenCanceled = False + self.anErrorOccured = 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() - aa=QString.fromUtf8(a.data(),len(a)) + aa=a.data().decode(errors='ignore') self.TB_Exe.append(aa) - if "END_OF_MGCleaner" in aa: - self.parent().enregistreResultat() - self.enregistreResultatsDone=True - #self.theClose() - + + def finished(self): + self.PB_Ok.setEnabled(True) + self.PB_Cancel.setEnabled(False) + exit_code = self.monExe.exitCode() + if exit_code == 0 and not self.anErrorOccured: + self.parent().enregistreResultat() + elif not self.hasBeenCanceled: + if os.path.exists(self.parent().fichierOut): + self.parent().enregistreResultat() + QMessageBox.critical(self, 'Computation ended in error', + 'A new mesh has been generated but with some errors.'+ + '
Please, check the log message.') + else: + QMessageBox.critical(self, 'Computation failed', + 'The computation has failed.
Please, check the log message.') + pass + + def errorOccured(self): + # for instance if the executable is not found + self.anErrorOccured = True + self.finished() + + def cancelComputation(self): + self.hasBeenCanceled = True + self.monExe.kill() + def theClose(self): - if not self.enregistreResultatsDone: - self.parent().enregistreResultat() - self.enregistreResultatsDone=True - self.close() + self.close()