Salome HOME
cc8e84df20d0d3bb3f04b34e0364f1814c825429
[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       cle_doc=None
42       if not hasattr(self,"RBInfo"):return
43       if isinstance(self,MonWidgetCommande) and self.editor.code =="MAP":
44          self.cle_doc = self.chercheDocMAP()
45       else :
46          self.cle_doc = self.node.item.get_docu()
47       if self.cle_doc == None  : self.RBInfo.close()
48       else : self.connect (self.RBInfo,SIGNAL("clicked()"),self.viewDoc)
49
50
51   def chercheDocMAP(self):
52       try :
53         clef=self.editor.CONFIGURATION.adresse+"/"
54       except :
55         return None
56       for k in self.editor.readercata.cata[0].JdC.dict_groupes.keys():
57           if self.obj.nom in self.editor.readercata.cata[0].JdC.dict_groupes[k]:
58              clef+=k
59              break
60       clef+="/"+ self.obj.nom[0:-5].lower()+"/spec_"+self.obj.nom[0:-5].lower()+".html"
61
62       return clef
63  
64   def viewDoc(self):
65       try :
66           cmd="xdg-open "+self.cle_doc
67           os.system(cmd)
68       except:
69           QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
70
71
72   def setPoubelle(self):
73       if not(hasattr(self,"RBPoubelle")):return
74       if self.node.item.object.isoblig() : 
75          icon1 = QtGui.QIcon()
76          icon1.addPixmap(QtGui.QPixmap("/home/A96028/Install_EficasV1/KarineEficas/Editeur/icons/deleteRondVide.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
77          self.RBPoubelle.setIcon(icon1)
78          return
79       self.RBPoubelle.show()
80       self.connect(self.RBPoubelle,SIGNAL("clicked()"),self.aDetruire)
81
82   def aDetruire(self):
83       self.node.delete()
84
85   def setValide(self):
86       #print " c est le moment de gerer le passage au suivant"
87       if not(hasattr (self,'RBValide')) : return
88       icon = QIcon()
89       if self.node.item.object.isvalid() : 
90          icon=QIcon(self.repIcon+"/ast-green-ball.png")
91       else :
92          icon=QIcon(self.repIcon+"/ast-red-ball.png")
93       self.RBValide.setIcon(icon)
94
95   def rendVisible(self):
96       self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(self)
97       self.setFocus()
98
99
100 class ContientIcones:
101
102   def BFichierVisu(self):
103        fichier=self.lineEditVal.text()
104        if fichier == None or str(fichier)=="" : return
105        from qtCommun import ViewText
106        try :
107          cmd="xdg-open "+str(fichier)
108          os.system(cmd)
109        except:
110          try :
111             fp=open(fichier)
112             txt=fp.read()
113             nomFichier=QFileInfo(fichier).baseName()
114             maVue=ViewText(self,entete=nomFichier)
115             maVue.setText(txt)
116             maVue.show()
117             fp.close()
118          except:
119             QMessageBox.warning( None,
120                        tr("Visualisation Fichier "),
121                        tr("Impossibilite d'afficher le Fichier"),)
122
123   def BFichierPressed(self):
124       mctype = self.node.item.get_definition().type
125       if len(mctype) > 1:
126           filters = mctype[1]
127       elif hasattr(mctype[0], "filters"):
128           filters = mctype[0].filters
129       else:
130           filters = QString()
131       if len(mctype) > 2 and mctype[2] == "Sauvegarde":
132           fichier = QFileDialog.getSaveFileName(self.appliEficas,
133                               tr('Sauvegarder Fichier'),
134                               self.appliEficas.CONFIGURATION.savedir,
135                               filters)
136       else:
137           fichier = QFileDialog.getOpenFileName(self.appliEficas,
138                               tr('Ouvrir Fichier'),
139                               self.appliEficas.CONFIGURATION.savedir,
140                               filters)
141
142       if not(fichier.isNull()):
143          ulfile = os.path.abspath(unicode(fichier))
144          self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
145          self.lineEditVal.setText(fichier)
146          self.editor.affiche_infos(tr("Fichier selectionne"))
147          self.LEValeurPressed()
148          if (QFileInfo(fichier).suffix() in listeSuffixe ):
149              self.image=fichier
150              if (not hasattr(self,"BSelectInFile")):
151                self.BSelectInFile = QPushButton(self.Widget8)
152                self.BSelectInFile.setMinimumSize(QSize(140,40))
153                self.BSelectInFile.setObjectName("BSelectInFile")
154                self.gridLayout.addWidget(self.BSelectInFile,1,1,1,1)
155                self.BSelectInFile.setText(tr("Selection"))
156                self.connect(self.BSelectInFile,SIGNAL("clicked()"),self.BSelectInFilePressed)
157              else :
158                self.BSelectInFile.setVisible(1)
159          elif hasattr(self, "BSelectInFile"):
160              self.BSelectInFile.setVisible(0)
161
162   def BRepertoirePressed(self):
163       directory = QFileDialog.getExistingDirectory(self.appliEficas,
164             directory = self.appliEficas.CONFIGURATION.savedir,
165             options = QFileDialog.ShowDirsOnly)
166
167       if not directory.isNull():
168          absdir = os.path.abspath(unicode(directory))
169          self.appliEficas.CONFIGURATION.savedir = os.path.dirname(absdir)
170          self.lineEditVal.setText(directory)
171          self.LEValeurPressed()
172
173   def BSelectInFilePressed(self):
174       from monSelectImage import MonSelectImage
175       MonSelectImage(file=self.image,parent=self).show()
176
177           
178
179   def BSalomePressed(self):
180         self.editor.affiche_infos(QString(""))
181         selection=[]
182         commentaire=""
183         genea=self.node.item.get_genealogie()
184         kwType = self.node.item.get_definition().type[0]
185         for e in genea:
186             if "GROUP_NO" in e: kwType = "GROUP_NO"
187             if "GROUP_MA" in e: kwType = "GROUP_MA"
188
189         if 'grno' in repr(kwType): kwType = "GROUP_NO"
190         if 'grma' in repr(kwType): kwType = "GROUP_NO"
191
192         if kwType in ("GROUP_NO","GROUP_MA"):
193            selection, commentaire = self.appliEficas.selectGroupFromSalome(kwType,editor=self.editor)
194
195         mc = self.node.item.get_definition()
196
197         if  (isinstance(mc.type,types.TupleType) and len(mc.type) > 1 and "(*.med)" in mc.type[1] ):
198            selection, commentaire = self.appliEficas.selectMeshFile(editor=self.editor)
199            print selection, commentaire
200            if commentaire != "" : 
201                   QMessageBox.warning( None,
202                   tr("Export Med vers Fichier "),
203                   tr("Impossibilite d exporter le Fichier"),)
204                   return
205            else :
206                   self.lineEditVal.setText(QString(selection))
207                   return
208
209         from Accas import SalomeEntry
210         if isinstance(kwType, types.ClassType) and issubclass(kwType, SalomeEntry):
211            selection, commentaire = self.appliEficas.selectEntryFromSalome(kwType,editor=self.editor)
212
213         if commentaire !="" :
214             self.editor.affiche_infos(tr(QString(commentaire)))
215         monTexte=""
216         if selection == [] : return
217         for geomElt in selection:
218             monTexte=geomElt+","
219         monTexte= monTexte[0:-1]
220         self.lineEditVal.setText(QString(monTexte))
221
222   def BView2DPressed(self):
223         valeur=self.lineEditVal.text()
224         if valeur == QString("") : return
225         valeur = str(valeur)
226         if valeur :
227            ok, msgError = self.appliEficas.displayShape(valeur)
228            if not ok:
229               self.appliEficas.affiche_infos(msgError,Qt.red)
230
231   def BParametresPressed(self):
232         liste=self.node.item.get_liste_param_possible()
233         from monListeParamPanel import MonListeParamPanel
234         MonListeParamPanel(liste=liste,parent=self).show()
235