1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013-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
28 import pprint as PP #pretty print
30 from qtsalome import *
34 from MGCleanerViewText_ui import Ui_ViewExe
38 force = os.getenv("FORCE_DISTENE_LICENSE_FILE")
40 os.environ["DISTENE_LICENSE_FILE"] = force
41 os.environ["DLIM8VAR"] = "NOTHING"
43 class MGCleanerMonViewText(Ui_ViewExe, QDialog):
45 Classe permettant la visualisation de texte
47 def __init__(self, parent, txt, ):
48 QDialog.__init__(self,parent)
50 self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) )
51 #self.connect( self.PB_Ok,SIGNAL("clicked()"), self, SLOT("close()") )
52 self.PB_Ok.clicked.connect( self.theClose )
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 )
62 """ for test set environment
63 env = QProcessEnvironment().systemEnvironment()
64 env.insert("HELLO", "bonjour") #Add an environment variable for debug
65 self.monExe.setProcessEnvironment(env)
67 PP.pprint([str(i) for i in sorted(self.monExe.processEnvironment().toStringList()) if 'DISTENE' in i])
70 if os.path.exists(self.parent().fichierOut):
71 os.remove(self.parent().fichierOut)
73 self.monExe.start(txt)
74 self.monExe.closeWriteChannel()
75 self.enregistreResultatsDone=False
78 def make_executable(self, path):
79 mode = os.stat(path).st_mode
80 mode |= (mode & 0o444) >> 2 # copy R bits to X
84 #recuperation du nom du fichier
85 savedir=os.environ['HOME']
86 fn, mask = QFileDialog.getSaveFileName(None,"Save File",savedir)
88 ulfile = os.path.abspath(str(fn))
91 f.write(self.TB_Exe.toPlainText().encode("utf-8"))
93 except IOError as why:
94 QMessageBox.critical(self, 'Save File',
95 'The file <b>%s</b> could not be saved.<br>Reason: %s'%(str(fn), str(why)))
97 def readFromStdErr(self):
98 a=self.monExe.readAllStandardError()
99 aa=a.data().decode(errors='ignore')
100 self.TB_Exe.append(aa)
102 def readFromStdOut(self) :
103 a=self.monExe.readAllStandardOutput()
104 aa=a.data().decode(errors='ignore')
105 self.TB_Exe.append(aa)
108 self.parent().enregistreResultat()
109 self.enregistreResultatsDone=True
112 if not self.enregistreResultatsDone:
113 self.parent().enregistreResultat()
114 self.enregistreResultatsDone=True