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 )
59 if sys.platform == "win32":
60 cmds += 'delete %s\n' % self.parent().fichierOut
62 cmds += '#!/bin/bash\n'
64 #cmds += 'which mg-surfopt.exe\n'
65 cmds += 'echo "DISTENE_LICENSE_FILE="$DISTENE_LICENSE_FILE\n'
66 cmds += 'echo "DLIM8VAR="$DLIM8VAR\n'
67 cmds += 'rm -f %s\n' % self.parent().fichierOut
70 cmds += 'echo %s\n' % txt #to see what is compute command
72 cmds += 'echo "END_OF_MGSurfOpt"\n'
74 nomFichier = os.path.splitext(self.parent().fichierOut)[0] + ext
75 with open(nomFichier, 'w') as f:
77 self.make_executable(nomFichier)
79 if verbose: print("INFO: MGSurfOpt launch script file: %s" % nomFichier)
81 self.monExe.start(nomFichier)
82 self.monExe.closeWriteChannel()
83 self.enregistreResultatsDone=False
86 def make_executable(self, path):
87 mode = os.stat(path).st_mode
88 mode |= (mode & 0o444) >> 2 # copy R bits to X
92 #recuperation du nom du fichier
93 savedir=os.environ['HOME']
94 fn = QFileDialog.getSaveFileName(None,"Save File",savedir)
95 if fn.isNull() : return
96 ulfile = os.path.abspath(unicode(fn))
99 f.write(str(self.TB_Exe.toPlainText()))
102 QMessageBox.critical(self, 'Save File',
103 'The file <b>%1</b> could not be saved.<br>Reason: %2'%(unicode(fn), str(why)))
105 def readFromStdErr(self):
106 a=self.monExe.readAllStandardError()
107 self.TB_Exe.append(unicode(a.data().encode()))
109 def readFromStdOut(self) :
110 a=self.monExe.readAllStandardOutput()
112 self.TB_Exe.append(aa)
113 if "END_OF_MGSurfOpt" in aa:
114 self.parent().enregistreResultat()
115 self.enregistreResultatsDone=True
119 if not self.enregistreResultatsDone:
120 self.parent().enregistreResultat()
121 self.enregistreResultatsDone=True