smesh/src/Tools/YamsPlug/monViewText.py

128 lines
4.4 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2021-03-23 17:44:27 +03:00
# Copyright (C) 2007-2021 EDF R&D
2012-12-13 11:41:29 +00:00
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
2014-02-20 16:25:37 +04:00
# version 2.1 of the License, or (at your option) any later version.
2012-12-13 11:41:29 +00:00
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
2013-04-01 13:05:47 +00:00
2016-06-14 14:57:25 +03:00
import os
import sys
import string
import types
import tempfile
2016-06-14 14:57:25 +03:00
import traceback
import pprint as PP #pretty print
2012-12-13 11:41:29 +00:00
2016-01-28 17:40:22 +03:00
from qtsalome import *
2012-12-13 11:41:29 +00:00
# Import des panels
from ViewText_ui import Ui_ViewExe
2016-06-14 14:57:25 +03:00
verbose = True
class MonViewText(Ui_ViewExe, QDialog):
2012-12-13 11:41:29 +00:00
"""
Classe permettant la visualisation de texte
"""
def __init__(self, parent, txt):
2012-12-13 11:41:29 +00:00
QDialog.__init__(self,parent)
self.setupUi(self)
self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) )
2016-01-28 17:40:22 +03:00
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")
2016-01-28 17:40:22 +03:00
self.PB_Save.clicked.connect( self.saveFile )
self.PB_Save.setToolTip("Save trace in log file")
self.PB_Ok.setToolTip("Close view")
2012-12-13 11:41:29 +00:00
self.monExe=QProcess(self)
2016-01-28 17:40:22 +03:00
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)
2012-12-13 11:41:29 +00:00
self.monExe.closeWriteChannel()
self.hasBeenCanceled = False
self.anErrorOccured = False
2012-12-13 11:41:29 +00:00
self.show()
2016-06-14 14:57:25 +03:00
def make_executable(self, path):
mode = os.stat(path).st_mode
mode |= (mode & 0o444) >> 2 # copy R bits to X
os.chmod(path, mode)
2012-12-13 11:41:29 +00:00
def saveFile(self):
#recuperation du nom du fichier
2020-04-14 11:47:24 +03:00
savedir=os.path.expanduser("~")
fn, mask = QFileDialog.getSaveFileName(None,"Save File",savedir)
if not fn: return
2017-03-20 13:27:30 +01:00
ulfile = os.path.abspath(str(fn))
2012-12-13 11:41:29 +00:00
try:
f = open(fn, 'wb')
f.write(self.TB_Exe.toPlainText().encode("utf-8"))
f.close()
2017-03-20 13:27:30 +01:00
except IOError as why:
QMessageBox.critical(self, 'Save File',
'The file <b>%s</b> could not be saved.<br>Reason: %s'%(str(fn), str(why)))
2012-12-13 11:41:29 +00:00
def readFromStdErr(self):
a=self.monExe.readAllStandardError()
aa=a.data().decode(errors='ignore')
self.TB_Exe.append(aa)
2012-12-13 11:41:29 +00:00
def readFromStdOut(self) :
a=self.monExe.readAllStandardOutput()
aa=a.data().decode(errors='ignore')
self.TB_Exe.append(aa)
def finished(self):
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):
self.close()