Salome HOME
Update of CheckDone
[modules/smesh.git] / src / Tools / YamsPlug / monViewText.py
index afbc87e3bb71dc361fbef42b9f7806d7568653de..73d53aebd0ed9e1d749279f6148b13590afb70a2 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Copyright (C) 2007-2016  EDF R&D
+# Copyright (C) 2007-2024  EDF
 #
 # 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,21 +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 )
+        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):
@@ -70,7 +75,7 @@ class MonViewText(Ui_ViewExe, QDialog):
 
     def saveFile(self):
         #recuperation du nom du fichier
-        savedir=os.environ['HOME']
+        savedir=os.path.expanduser("~")
         fn, mask = QFileDialog.getSaveFileName(None,"Save File",savedir)
         if not fn: return
         ulfile = os.path.abspath(str(fn))
@@ -93,11 +98,30 @@ class MonViewText(Ui_ViewExe, QDialog):
         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.'+
+                  '<br>Please, check the log message.')
+            else:
+                QMessageBox.critical(self, 'Computation failed',
+                  'The computation has failed.<br>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()