Salome HOME
Push double click
[modules/smesh.git] / src / Tools / YamsPlug / monViewText.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013  EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 # Modules Python
22 import string,types,os
23 import traceback
24
25 from PyQt4 import *
26 from PyQt4.QtGui import *
27 from PyQt4.QtCore import *
28
29 # Import des panels
30
31 # ------------------------------- #
32 from ViewText import Ui_ViewExe
33 class MonViewText(Ui_ViewExe,QDialog):
34 # ------------------------------- #
35     """
36     Classe permettant la visualisation de texte
37     """
38     def __init__(self,parent,txt):
39         QDialog.__init__(self,parent)
40         self.pere=parent
41         self.setupUi(self)
42         self.resize( QSize(600,600).expandedTo(self.minimumSizeHint()) )
43         self.connect( self.PB_Ok,SIGNAL("clicked()"), self, SLOT("close()") )
44         self.connect( self.PB_Save,SIGNAL("clicked()"), self.saveFile )
45         self.monExe=QProcess(self)
46
47
48         self.connect(self.monExe, SIGNAL("readyReadStandardOutput()"), self.readFromStdOut )
49         self.connect(self.monExe, SIGNAL("readyReadStandardError()"), self.readFromStdErr )
50         self.connect(self.monExe, SIGNAL("finished(int  )"), self.exeFinished )
51       
52         # Je n arrive pas a utiliser le setEnvironment du QProcess
53         # fonctionne hors Salome mais pas dans Salome ???
54         LICENCE=os.environ['DISTENE_LICENCE_FILE_FOR_YAMS']
55         txt='export DISTENE_LICENSE_FILE='+LICENCE+';'+ txt
56         pid=self.monExe.pid()
57         nomFichier='/tmp/yam_'+str(pid)+'.py'
58         f=open(nomFichier,'w')
59         f.write(txt)
60         f.close()
61
62         maBidouille='sh  ' + nomFichier
63         self.monExe.start(maBidouille)
64         self.monExe.closeWriteChannel()
65         self.show()
66
67     def exeFinished(self):
68         self.pere.enregistreResultat()
69         
70     def saveFile(self):
71         #recuperation du nom du fichier
72         savedir=os.environ['HOME']
73         fn = QFileDialog.getSaveFileName(None, self.trUtf8("Save File"),savedir)
74         if fn.isNull() : return
75         ulfile = os.path.abspath(unicode(fn))
76         try:
77            f = open(fn, 'wb')
78            f.write(str(self.TB_Exe.toPlainText()))
79            f.close()
80         except IOError, why:
81            QMessageBox.critical(self, self.trUtf8('Save File'),
82                 self.trUtf8('The file <b>%1</b> could not be saved.<br>Reason: %2')
83                     .arg(unicode(fn)).arg(str(why)))
84
85     def readFromStdErr(self):
86         a=self.monExe.readAllStandardError()
87         self.TB_Exe.append(QString.fromUtf8(a.data(),len(a))) ;
88
89     def readFromStdOut(self) :
90         a=self.monExe.readAllStandardOutput()
91         self.TB_Exe.append(QString.fromUtf8(a.data(),len(a))) ;