Salome HOME
5667d4775f102f9dc92f2c0988b504bebcde6bf9
[tools/eficas.git] / InterfaceQT4 / gereIcones.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 import string,types,os,re
22 import traceback
23
24 from PyQt4 import *
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27 from Extensions.i18n import tr
28 listeSuffixe=('bmp','png','jpg' ,'txt','med')
29
30
31 class FacultatifOuOptionnel:
32
33   def setReglesEtAide(self):
34       from monWidgetCommande import MonWidgetCommande
35       listeRegles=()
36       try :
37          listeRegles     = self.node.item.get_regles()
38       except :
39          pass
40       if listeRegles==() and hasattr(self,"RBRegle"): self.RBRegle.close() 
41       if isinstance(self,MonWidgetCommande):return
42       cle_doc = self.node.item.get_docu()
43       if cle_doc == None and hasattr(self,"RBInfo") : self.RBInfo.close()
44
45
46  
47   def setPoubelle(self):
48       if not(hasattr(self,"RBPoubelle")):return
49       if self.node.item.object.isoblig() : 
50          icon1 = QtGui.QIcon()
51          icon1.addPixmap(QtGui.QPixmap("/home/A96028/Install_EficasV1/KarineEficas/Editeur/icons/deleteRondVide.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
52          self.RBPoubelle.setIcon(icon1)
53          return
54       self.RBPoubelle.show()
55       self.connect(self.RBPoubelle,SIGNAL("clicked()"),self.aDetruire)
56
57   def aDetruire(self):
58       self.node.delete()
59       # Cas du mono-commande
60       if self.parentQt == None : self.afficheCatalogue()
61       else : self.parentQt.reaffiche()
62
63   def setValide(self):
64       if not(hasattr (self,'RBValide')) : return
65       icon = QIcon()
66       if self.node.item.object.isvalid() : 
67          icon=QIcon(self.repIcon+"/ast-green-ball.png")
68       else :
69          icon=QIcon(self.repIcon+"/ast-red-ball.png")
70       self.RBValide.setIcon(icon)
71
72
73
74 class ContientIcones:
75
76   def BFichierVisu(self):
77        fichier=self.lineEditVal.text()
78        if fichier == None or str(fichier)=="" : return
79        from qtCommun import ViewText
80        try :
81          cmd="xdg-open "+str(fichier)
82          os.system(cmd)
83        except:
84          try :
85             fp=open(fichier)
86             txt=fp.read()
87             nomFichier=QFileInfo(fichier).baseName()
88             maVue=ViewText(self,entete=nomFichier)
89             maVue.setText(txt)
90             maVue.show()
91             fp.close()
92          except:
93             QMessageBox.warning( None,
94                        tr("Visualisation Fichier "),
95                        tr("Impossibilite d'afficher le Fichier"),)
96
97   def BFichierPressed(self):
98       mctype = self.node.item.get_definition().type
99       if len(mctype) > 1:
100           filters = mctype[1]
101       elif hasattr(mctype[0], "filters"):
102           filters = mctype[0].filters
103       else:
104           filters = QString()
105       if len(mctype) > 2 and mctype[2] == "Sauvegarde":
106           fichier = QFileDialog.getSaveFileName(self.appliEficas,
107                               tr('Sauvegarder Fichier'),
108                               self.appliEficas.CONFIGURATION.savedir,
109                               filters)
110       else:
111           fichier = QFileDialog.getOpenFileName(self.appliEficas,
112                               tr('Ouvrir Fichier'),
113                               self.appliEficas.CONFIGURATION.savedir,
114                               filters)
115
116       if not(fichier.isNull()):
117          ulfile = os.path.abspath(unicode(fichier))
118          self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
119          self.lineEditVal.setText(fichier)
120          self.editor.affiche_infos(tr("Fichier selectionne"))
121          self.LEValeurPressed()
122          if (QFileInfo(fichier).suffix() in listeSuffixe ):
123              self.image=fichier
124              if (not hasattr(self,"BSelectInFile")):
125                self.BSelectInFile = QPushButton(self.Widget8)
126                self.BSelectInFile.setMinimumSize(QSize(140,40))
127                self.BSelectInFile.setObjectName("BSelectInFile")
128                self.gridLayout.addWidget(self.BSelectInFile,1,1,1,1)
129                self.BSelectInFile.setText(tr("Selection"))
130                self.connect(self.BSelectInFile,SIGNAL("clicked()"),self.BSelectInFilePressed)
131              else :
132                self.BSelectInFile.setVisible(1)
133          elif hasattr(self, "BSelectInFile"):
134              self.BSelectInFile.setVisible(0)
135
136   def BRepertoirePressed(self):
137       directory = QFileDialog.getExistingDirectory(self.appliEficas,
138             directory = self.appliEficas.CONFIGURATION.savedir,
139             options = QFileDialog.ShowDirsOnly)
140
141       if not directory.isNull():
142          absdir = os.path.abspath(unicode(directory))
143          self.appliEficas.CONFIGURATION.savedir = os.path.dirname(absdir)
144          self.lineEditVal.setText(directory)
145          self.LEValeurPressed()
146
147   def BSelectInFilePressed(self):
148       from monSelectImage import MonSelectImage
149       MonSelectImage(file=self.image,parent=self).show()
150
151           
152
153   def BSalomePressed(self):
154         self.editor.affiche_infos(QString(""))
155         selection=[]
156         commentaire=""
157         genea=self.node.item.get_genealogie()
158         kwType = self.node.item.get_definition().type[0]
159         for e in genea:
160             if "GROUP_NO" in e: kwType = "GROUP_NO"
161             if "GROUP_MA" in e: kwType = "GROUP_MA"
162
163         if 'grno' in repr(kwType): kwType = "GROUP_NO"
164         if 'grma' in repr(kwType): kwType = "GROUP_NO"
165
166         if kwType in ("GROUP_NO","GROUP_MA"):
167            selection, commentaire = self.appliEficas.selectGroupFromSalome(kwType,editor=self.editor)
168
169         mc = self.node.item.get_definition()
170
171         if  (isinstance(mc.type,types.TupleType) and len(mc.type) > 1 and "(*.med)" in mc.type[1] ):
172            selection, commentaire = self.appliEficas.selectMeshFile(editor=self.editor)
173            print selection, commentaire
174            if commentaire != "" : 
175                   QMessageBox.warning( None,
176                   tr("Export Med vers Fichier "),
177                   tr("Impossibilite d exporter le Fichier"),)
178                   return
179            else :
180                   self.lineEditVal.setText(QString(selection))
181                   return
182
183         from Accas import SalomeEntry
184         if isinstance(kwType, types.ClassType) and issubclass(kwType, SalomeEntry):
185            selection, commentaire = self.appliEficas.selectEntryFromSalome(kwType,editor=self.editor)
186
187         if commentaire !="" :
188             self.editor.affiche_infos(tr(QString(commentaire)))
189         monTexte=""
190         if selection == [] : return
191         for geomElt in selection:
192             monTexte=geomElt+","
193         monTexte= monTexte[0:-1]
194         self.lineEditVal.setText(QString(monTexte))
195
196   def BView2DPressed(self):
197         valeur=self.lineEditVal.text()
198         if valeur == QString("") : return
199         valeur = str(valeur)
200         if valeur :
201            ok, msgError = self.appliEficas.displayShape(valeur)
202            if not ok:
203               self.appliEficas.affiche_infos(msgError,Qt.red)
204
205   def BParametresPressed(self):
206         liste=self.node.item.get_liste_param_possible()
207         from monListeParamPanel import MonListeParamPanel
208         MonListeParamPanel(liste=liste,parent=self).show()
209