From: Christophe Bourcier Date: Tue, 22 Jan 2019 14:32:06 +0000 (+0100) Subject: Improve behaviour of Cleaner and SurfOpt in case of error and add a cancel button. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9f605b3b0d4aec96b07beb08eeee99a8448aab78;p=modules%2Fsmesh.git Improve behaviour of Cleaner and SurfOpt in case of error and add a cancel button. --- diff --git a/src/Tools/MGCleanerPlug/MGCleanerMonViewText.py b/src/Tools/MGCleanerPlug/MGCleanerMonViewText.py index 0271821e3..d0cf51e07 100644 --- a/src/Tools/MGCleanerPlug/MGCleanerMonViewText.py +++ b/src/Tools/MGCleanerPlug/MGCleanerMonViewText.py @@ -37,19 +37,24 @@ verbose = True force = os.getenv("FORCE_DISTENE_LICENSE_FILE") if force != None: - os.environ["DISTENE_LICENSE_FILE"] = force - os.environ["DLIM8VAR"] = "NOTHING" + 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.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") @@ -58,21 +63,15 @@ class MGCleanerMonViewText(Ui_ViewExe, QDialog): self.monExe.readyReadStandardOutput.connect( self.readFromStdOut ) self.monExe.readyReadStandardError.connect( self.readFromStdErr ) self.monExe.finished.connect( self.finished ) + self.monExe.errorOccurred.connect( self.errorOccured ) - """ for test set environment - env = QProcessEnvironment().systemEnvironment() - env.insert("HELLO", "bonjour") #Add an environment variable for debug - self.monExe.setProcessEnvironment(env) - if verbose: - PP.pprint([str(i) for i in sorted(self.monExe.processEnvironment().toStringList()) if 'DISTENE' in i]) - """ - 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): @@ -103,13 +102,26 @@ class MGCleanerMonViewText(Ui_ViewExe, QDialog): a=self.monExe.readAllStandardOutput() 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: + 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() diff --git a/src/Tools/MGCleanerPlug/MGCleanerViewText.ui b/src/Tools/MGCleanerPlug/MGCleanerViewText.ui index 8bec19a12..a2cd43e61 100644 --- a/src/Tools/MGCleanerPlug/MGCleanerViewText.ui +++ b/src/Tools/MGCleanerPlug/MGCleanerViewText.ui @@ -14,7 +14,7 @@ Run MGCleaner - + @@ -25,9 +25,16 @@ + + + Cancel + + + + - Save + Save log diff --git a/src/Tools/YamsPlug/ViewText.ui b/src/Tools/YamsPlug/ViewText.ui index 18fa63e46..a2cd43e61 100644 --- a/src/Tools/YamsPlug/ViewText.ui +++ b/src/Tools/YamsPlug/ViewText.ui @@ -11,10 +11,10 @@ - Run Yams + Run MGCleaner - + @@ -25,9 +25,16 @@ + + + Cancel + + + + - Save + Save log diff --git a/src/Tools/YamsPlug/monViewText.py b/src/Tools/YamsPlug/monViewText.py index afbc87e3b..c165085d0 100644 --- a/src/Tools/YamsPlug/monViewText.py +++ b/src/Tools/YamsPlug/monViewText.py @@ -29,6 +29,7 @@ import pprint as PP #pretty print from qtsalome import * # Import des panels + from ViewText_ui import Ui_ViewExe verbose = True @@ -46,21 +47,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): @@ -93,11 +103,24 @@ 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: + 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()