1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2014 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
22 import string,types,os
26 from PyQt4.QtGui import *
27 from PyQt4.QtCore import *
31 from MGCleanerViewText_ui import Ui_ViewExe
33 class MGCleanerMonViewText(Ui_ViewExe, QDialog):
35 Classe permettant la visualisation de texte
37 def __init__(self, parent, txt, ):
38 QDialog.__init__(self,parent)
40 self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) )
41 #self.connect( self.PB_Ok,SIGNAL("clicked()"), self, SLOT("close()") )
42 self.connect( self.PB_Ok,SIGNAL("clicked()"), self.theClose )
43 self.connect( self.PB_Save,SIGNAL("clicked()"), self.saveFile )
44 self.PB_Save.setToolTip("Save trace in log file")
45 self.PB_Ok.setToolTip("Close view")
46 self.monExe=QProcess(self)
48 self.connect(self.monExe, SIGNAL("readyReadStandardOutput()"), self.readFromStdOut )
49 self.connect(self.monExe, SIGNAL("readyReadStandardError()"), self.readFromStdErr )
51 # Je n arrive pas a utiliser le setEnvironment du QProcess
52 # fonctionne hors Salome mais pas dans Salome ???
55 LICENCE_FILE=os.environ["DISTENE_LICENCE_FILE_FOR_MGCLEANER"]
59 PATH=os.environ["DISTENE_PATH_FOR_MGCLEANER"]
62 if LICENCE_FILE != '':
63 cmds+='source '+LICENCE_FILE+'\n'
65 cmds+="# $DISTENE_LICENCE_FILE_FOR_MGCLEANER NOT SET\n"
67 cmds+='export PATH='+PATH+':$PATH\n'
69 cmds+="# $DISTENE_PATH_FOR_MGCLEANER NOT SET\n"
71 cmds+='rm -f '+self.parent().fichierOut+'\n'
73 cmds+='echo END_OF_MGCleaner\n'
75 nomFichier='/tmp/MGCleaner_'+str(pid)+'.sh'
76 f=open(nomFichier,'w')
80 maBidouille='sh ' + nomFichier
81 self.monExe.start(maBidouille)
82 self.monExe.closeWriteChannel()
83 self.enregistreResultatsDone=False
87 #recuperation du nom du fichier
88 savedir=os.environ['HOME']
89 fn = QFileDialog.getSaveFileName(None, self.trUtf8("Save File"),savedir)
90 if fn.isNull() : return
91 ulfile = os.path.abspath(unicode(fn))
94 f.write(str(self.TB_Exe.toPlainText()))
97 QMessageBox.critical(self, self.trUtf8('Save File'),
98 self.trUtf8('The file <b>%1</b> could not be saved.<br>Reason: %2')
99 .arg(unicode(fn)).arg(str(why)))
101 def readFromStdErr(self):
102 a=self.monExe.readAllStandardError()
103 self.TB_Exe.append(QString.fromUtf8(a.data(),len(a)))
105 def readFromStdOut(self) :
106 a=self.monExe.readAllStandardOutput()
107 aa=QString.fromUtf8(a.data(),len(a))
108 self.TB_Exe.append(aa)
109 if "END_OF_MGCleaner" in aa:
110 self.parent().enregistreResultat()
111 self.enregistreResultatsDone=True
115 if not self.enregistreResultatsDone:
116 self.parent().enregistreResultat()
117 self.enregistreResultatsDone=True