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