1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2016 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 *
32 from ViewText_ui import Ui_ViewExe
36 force = os.getenv("FORCE_DISTENE_LICENSE_FILE")
38 os.environ["DISTENE_LICENSE_FILE"] = force
39 os.environ["DLIM8VAR"] = "NOTHING"
41 class MonViewText(Ui_ViewExe, QDialog):
43 Classe permettant la visualisation de texte
45 def __init__(self, parent, txt):
46 QDialog.__init__(self,parent)
48 self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) )
49 # self.PB_Ok.clicked.connect(self.close)
50 self.PB_Ok.clicked.connect( self.theClose )
51 self.PB_Save.clicked.connect( self.saveFile )
52 self.monExe=QProcess(self)
54 self.monExe.readyReadStandardOutput.connect( self.readFromStdOut )
55 self.monExe.readyReadStandardError.connect( self.readFromStdErr )
56 self.monExe.finished.connect( self.finished )
58 if os.path.exists(self.parent().fichierOut):
59 os.remove(self.parent().fichierOut)
61 self.monExe.start(txt)
62 self.monExe.closeWriteChannel()
63 self.enregistreResultatsDone=False
66 def make_executable(self, path):
67 mode = os.stat(path).st_mode
68 mode |= (mode & 0o444) >> 2 # copy R bits to X
72 #recuperation du nom du fichier
73 savedir=os.environ['HOME']
74 fn, mask = QFileDialog.getSaveFileName(None,"Save File",savedir)
76 ulfile = os.path.abspath(str(fn))
79 f.write(self.TB_Exe.toPlainText().encode("utf-8"))
81 except IOError as why:
82 QMessageBox.critical(self, 'Save File',
83 'The file <b>%s</b> could not be saved.<br>Reason: %s'%(str(fn), str(why)))
85 def readFromStdErr(self):
86 a=self.monExe.readAllStandardError()
87 aa=a.data().decode(errors='ignore')
88 self.TB_Exe.append(aa)
90 def readFromStdOut(self) :
91 a=self.monExe.readAllStandardOutput()
92 aa=a.data().decode(errors='ignore')
93 self.TB_Exe.append(aa)
96 self.parent().enregistreResultat()
97 self.enregistreResultatsDone=True
100 if not self.enregistreResultatsDone:
101 self.parent().enregistreResultat()
102 self.enregistreResultatsDone=True