X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FTools%2FYamsPlug%2FmonViewText.py;h=3ae4570308c2cb1bf7b6600da385bf4734a949a8;hp=c1e90255b6e7a8bd3704d0acc589401956a25875;hb=499f29d24922cec66e41b41a0039a954993bc6df;hpb=a1920ff31054e2c882bd94d4f3c04abe53980ce0
diff --git a/src/Tools/YamsPlug/monViewText.py b/src/Tools/YamsPlug/monViewText.py
index c1e90255b..3ae457030 100644
--- a/src/Tools/YamsPlug/monViewText.py
+++ b/src/Tools/YamsPlug/monViewText.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2016 EDF R&D
+# Copyright (C) 2007-2022 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
@@ -29,15 +29,11 @@ import pprint as PP #pretty print
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"
-
class MonViewText(Ui_ViewExe, QDialog):
"""
Classe permettant la visualisation de texte
@@ -46,44 +42,30 @@ class MonViewText(Ui_ViewExe, QDialog):
QDialog.__init__(self,parent)
self.setupUi(self)
self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) )
- # self.PB_Ok.clicked.connect(self.close)
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.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'
-
- 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.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):
@@ -93,33 +75,53 @@ class MonViewText(Ui_ViewExe, QDialog):
def saveFile(self):
#recuperation du nom du fichier
- savedir=os.environ['HOME']
- fn = QFileDialog.getSaveFileName(None,"Save File",savedir)
- if fn.isNull() : return
- ulfile = os.path.abspath(unicode(fn))
+ savedir=os.path.expanduser("~")
+ 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, 'Save File',
- 'The file %1 could not be saved.
Reason: %2'%(unicode(fn), 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(unicode(a.data().encode()))
+ aa=a.data().decode(errors='ignore')
+ self.TB_Exe.append(aa)
def readFromStdOut(self) :
a=self.monExe.readAllStandardOutput()
- aa=unicode(a.data())
- self.TB_Exe.append(aa)
-
+ aa=a.data().decode(errors='ignore')
+ self.TB_Exe.append(aa)
+
def finished(self):
- self.parent().enregistreResultat()
- self.enregistreResultatsDone=True
-
+ 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()