Salome HOME
fin portage python 3
[tools/eficas.git] / InterfaceQT4 / monViewTexte.py
1 # -*- coding: utf-8 -*-
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 # Modules Python
21 from __future__ import absolute_import
22 try :
23    from builtins import str
24 except : pass
25
26 import types,os
27 import traceback
28
29 from Extensions.i18n import tr
30 import six
31
32 from PyQt5.QtWidgets import QDialog, QMessageBox, QFileDialog
33 from PyQt5.QtCore import QSize
34 from desViewTexte import Ui_dView
35
36 # ------------------------------- #
37 class ViewText(Ui_dView,QDialog):
38 # ------------------------------- #
39     """
40     Classe permettant la visualisation de texte
41     """
42     def __init__(self,parent,editor=None,entete=None,texte=None,largeur=600,hauteur=600):
43         QDialog.__init__(self,parent)
44         self.editor=editor
45         self.setupUi(self)
46
47         self.resize( QSize(largeur,hauteur).expandedTo(self.minimumSizeHint()) )
48         self.bclose.clicked.connect(self.close)
49         self.bsave.clicked.connect(self.saveFile )
50
51         if entete != None : self.setWindowTitle (entete)
52         if entete != None : self.setText (texte)
53
54         
55     def setText(self, txt ):    
56         self.view.setText(txt)
57         
58     def saveFile(self):
59         #recuperation du nom du fichier
60         if self.editor != None :
61            dir=self.editor.appliEficas.CONFIGURATION.savedir
62         else:
63            dir='/tmp'
64         fn = QFileDialog.getSaveFileName(None,
65                 tr("Sauvegarder le fichier"),
66                 dir)
67         fn=fn[0]
68         if fn == ""  : return
69         if fn == None : return (0, None)
70
71         ulfile = os.path.abspath(six.text_type(fn))
72         if self.editor != None :
73            self.editor.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
74         try:
75            f = open(fn, 'w')
76            f.write(str(self.view.toPlainText()))
77            f.close()
78            return 1
79         except IOError as why:
80            QMessageBox.critical(self, tr("Sauvegarder le fichier"),
81                  tr('Le fichier')+str(fn) + tr('n a pas pu etre sauvegarde : ') + str(why))
82            return
83
84