1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013-2021 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
28 import pprint as PP #pretty print
30 from qtsalome import *
34 from MGCleanerViewText_ui import Ui_ViewExe
38 class MGCleanerMonViewText(Ui_ViewExe, QDialog):
40 Classe permettant la visualisation de texte
42 def __init__(self, parent, txt):
43 QDialog.__init__(self,parent)
45 self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) )
46 self.PB_Ok.clicked.connect( self.theClose )
47 # Button OK is disabled until computation is finished
48 self.PB_Ok.setEnabled(False)
49 # Button cancel allows to kill the computation
50 # It is disabled when the computation is finished
51 self.PB_Cancel.clicked.connect( self.cancelComputation )
52 self.PB_Cancel.setToolTip("Cancel computation")
53 self.PB_Save.clicked.connect( self.saveFile )
54 self.PB_Save.setToolTip("Save trace in log file")
55 self.PB_Ok.setToolTip("Close view")
56 self.monExe=QProcess(self)
58 self.monExe.readyReadStandardOutput.connect( self.readFromStdOut )
59 self.monExe.readyReadStandardError.connect( self.readFromStdErr )
60 self.monExe.finished.connect( self.finished )
61 self.monExe.errorOccurred.connect( self.errorOccured )
63 if os.path.exists(self.parent().fichierOut):
64 os.remove(self.parent().fichierOut)
66 self.monExe.start(txt)
67 self.monExe.closeWriteChannel()
68 self.hasBeenCanceled = False
69 self.anErrorOccured = False
72 def make_executable(self, path):
73 mode = os.stat(path).st_mode
74 mode |= (mode & 0o444) >> 2 # copy R bits to X
78 #recuperation du nom du fichier
79 savedir=os.path.expanduser("~")
80 fn, mask = QFileDialog.getSaveFileName(None,"Save File",savedir)
82 ulfile = os.path.abspath(str(fn))
85 f.write(self.TB_Exe.toPlainText().encode("utf-8"))
87 except IOError as why:
88 QMessageBox.critical(self, 'Save File',
89 'The file <b>%s</b> could not be saved.<br>Reason: %s'%(str(fn), str(why)))
91 def readFromStdErr(self):
92 a=self.monExe.readAllStandardError()
93 aa=a.data().decode(errors='ignore')
94 self.TB_Exe.append(aa)
96 def readFromStdOut(self) :
97 a=self.monExe.readAllStandardOutput()
98 aa=a.data().decode(errors='ignore')
99 self.TB_Exe.append(aa)
102 self.PB_Ok.setEnabled(True)
103 self.PB_Cancel.setEnabled(False)
104 exit_code = self.monExe.exitCode()
105 if exit_code == 0 and not self.anErrorOccured:
106 self.parent().enregistreResultat()
107 elif not self.hasBeenCanceled:
108 if os.path.exists(self.parent().fichierOut):
109 self.parent().enregistreResultat()
110 QMessageBox.critical(self, 'Computation ended in error',
111 'A new mesh has been generated but with some errors.'+
112 '<br>Please, check the log message.')
114 QMessageBox.critical(self, 'Computation failed',
115 'The computation has failed.<br>Please, check the log message.')
118 def errorOccured(self):
119 # for instance if the executable is not found
120 self.anErrorOccured = True
123 def cancelComputation(self):
124 self.hasBeenCanceled = True