1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013-2020 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
27 import pprint as PP #pretty print
29 from qtsalome import *
33 from TopIIVolMeshMonitor_ui import Ui_qdLogger
37 class TopIIVolMeshMonitor(Ui_qdLogger, QDialog):
38 def __init__(self, parent, txt):
39 QDialog.__init__(self,parent)
41 self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) )
42 self.qpbOK.clicked.connect( self.OnQpbOKClicked )
43 # Button OK is disabled until computation is finished
44 self.qpbOK.setEnabled(False)
45 self.qpbSave.clicked.connect( self.OnQpbSaveClicked )
46 self.qpbSave.setToolTip("Save trace in log file")
47 self.qpbOK.setToolTip("Close view")
48 self.myExecutable=QProcess(self)
49 self.myExecutable.readyReadStandardOutput.connect( self.readFromStdOut )
50 self.myExecutable.readyReadStandardError.connect( self.readFromStdErr )
51 self.myExecutable.finished.connect( self.computationFinished )
52 self.myExecutable.errorOccurred.connect( self.computationOnError )
53 if os.path.exists(self.parent().outputMesh):
54 os.remove(self.parent().outputMesh)
55 self.myExecutable.start(txt)
56 self.myExecutable.closeWriteChannel()
59 def OnQpbOKClicked(self):
62 def OnQpbSaveClicked(self):
63 outputDirectory=os.path.expanduser("~")
64 fn, mask = QFileDialog.getSaveFileName(None,"Save File",outputDirectory)
67 ulfile = os.path.abspath(str(fn))
70 f.write(self.qtbLogWindow.toPlainText().encode("utf-8"))
72 except IOError as why:
73 QMessageBox.critical(self, 'Save File',
74 'The file <b>%s</b> could not be saved.<br>Reason: %s'%(str(fn), str(why)))
76 def readFromStdErr(self):
77 a=self.myExecutable.readAllStandardError()
78 aa=a.data().decode(errors='ignore')
79 self.qtbLogWindow.append(aa)
81 def readFromStdOut(self) :
82 a=self.myExecutable.readAllStandardOutput()
83 aa=a.data().decode(errors='ignore')
84 self.qtbLogWindow.append(aa)
86 def computationFinished(self):
87 self.qpbOK.setEnabled(True)
88 if self.myExecutable.exitCode() == 0:
89 self.parent().saveOutputMesh()
91 QMessageBox.critical(self, 'Computation failed',
92 'The computation has failed.<br>Please, check the log message.')
94 def computationOnError(self):
95 self.qpbOK.setEnabled(True)
96 QMessageBox.critical(self, 'Computation failed',
97 'The computation has failed.<br>Please, check the log message.')