Salome HOME
05378eb3cc7a32a9c8becc86c54474544c19ed5e
[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 setRun(self):
83       if hasattr(self.editor.appliEficas, 'mesScripts'):
84          if self.tree.currentItem().item.get_nom() in self.appliEficas.mesScripts.dict_commandes.keys() :
85                print 'il faut programmer le self.ajoutScript()'
86                print '#PNPNPNPN'
87                return
88       if hasattr(self,"RBRun"): self.RBRun.close()
89
90
91   def aDetruire(self):
92       self.node.delete()
93
94   def setValide(self):
95       #print " c est le moment de gerer le passage au suivant"
96       if not(hasattr (self,'RBValide')) : return
97       icon = QIcon()
98       if self.node.item.object.isvalid() : 
99          icon=QIcon(self.repIcon+"/ast-green-ball.png")
100       else :
101          icon=QIcon(self.repIcon+"/ast-red-ball.png")
102       self.RBValide.setIcon(icon)
103
104   def rendVisible(self):
105       self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(self)
106       self.setFocus()
107
108
109 class ContientIcones:
110
111   def BFichierVisu(self):
112        fichier=self.lineEditVal.text()
113        if fichier == None or str(fichier)=="" : return
114        from qtCommun import ViewText
115        try :
116          cmd="xdg-open "+str(fichier)
117          os.system(cmd)
118        except:
119          try :
120             fp=open(fichier)
121             txt=fp.read()
122             nomFichier=QFileInfo(fichier).baseName()
123             maVue=ViewText(self,entete=nomFichier)
124             maVue.setText(txt)
125             maVue.show()
126             fp.close()
127          except:
128             QMessageBox.warning( None,
129                        tr("Visualisation Fichier "),
130                        tr("Impossibilite d'afficher le Fichier"),)
131
132   def BFichierPressed(self):
133       mctype = self.node.item.get_definition().type
134       if len(mctype) > 1:
135           filters = mctype[1]
136       elif hasattr(mctype[0], "filters"):
137           filters = mctype[0].filters
138       else:
139           filters = QString()
140       if len(mctype) > 2 and mctype[2] == "Sauvegarde":
141           fichier = QFileDialog.getSaveFileName(self.appliEficas,
142                               tr('Sauvegarder Fichier'),
143                               self.appliEficas.CONFIGURATION.savedir,
144                               filters)
145       else:
146           fichier = QFileDialog.getOpenFileName(self.appliEficas,
147                               tr('Ouvrir Fichier'),
148                               self.appliEficas.CONFIGURATION.savedir,
149                               filters)
150
151       if not(fichier.isNull()):
152          ulfile = os.path.abspath(unicode(fichier))
153          self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
154          self.lineEditVal.setText(fichier)
155          self.editor.affiche_infos(tr("Fichier selectionne"))
156          self.LEValeurPressed()
157          if (QFileInfo(fichier).suffix() in listeSuffixe ):
158              self.image=fichier
159              if (not hasattr(self,"BSelectInFile")):
160                self.BSelectInFile = QPushButton(self.Widget8)
161                self.BSelectInFile.setMinimumSize(QSize(140,40))
162                self.BSelectInFile.setObjectName("BSelectInFile")
163                self.gridLayout.addWidget(self.BSelectInFile,1,1,1,1)
164                self.BSelectInFile.setText(tr("Selection"))
165                self.connect(self.BSelectInFile,SIGNAL("clicked()"),self.BSelectInFilePressed)
166              else :
167                self.BSelectInFile.setVisible(1)
168          elif hasattr(self, "BSelectInFile"):
169              self.BSelectInFile.setVisible(0)
170
171   def BRepertoirePressed(self):
172       directory = QFileDialog.getExistingDirectory(self.appliEficas,
173             directory = self.appliEficas.CONFIGURATION.savedir,
174             options = QFileDialog.ShowDirsOnly)
175
176       if not directory.isNull():
177          absdir = os.path.abspath(unicode(directory))
178          self.appliEficas.CONFIGURATION.savedir = os.path.dirname(absdir)
179          self.lineEditVal.setText(directory)
180          self.LEValeurPressed()
181
182   def BSelectInFilePressed(self):
183       from monSelectImage import MonSelectImage
184       MonSelectImage(file=self.image,parent=self).show()
185
186           
187
188   def BSalomePressed(self):
189         self.editor.affiche_infos(QString(""))
190         selection=[]
191         commentaire=""
192         genea=self.node.item.get_genealogie()
193         kwType = self.node.item.get_definition().type[0]
194         for e in genea:
195             if "GROUP_NO" in e: kwType = "GROUP_NO"
196             if "GROUP_MA" in e: kwType = "GROUP_MA"
197
198         if 'grno' in repr(kwType): kwType = "GROUP_NO"
199         if 'grma' in repr(kwType): kwType = "GROUP_NO"
200
201         if kwType in ("GROUP_NO","GROUP_MA"):
202            selection, commentaire = self.appliEficas.selectGroupFromSalome(kwType,editor=self.editor)
203
204         mc = self.node.item.get_definition()
205
206         if  (isinstance(mc.type,types.TupleType) and len(mc.type) > 1 and "(*.med)" in mc.type[1] ):
207            selection, commentaire = self.appliEficas.selectMeshFile(editor=self.editor)
208            print selection, commentaire
209            if commentaire != "" : 
210                   QMessageBox.warning( None,
211                   tr("Export Med vers Fichier "),
212                   tr("Impossibilite d exporter le Fichier"),)
213                   return
214            else :
215                   self.lineEditVal.setText(QString(selection))
216                   return
217
218         from Accas import SalomeEntry
219         if isinstance(kwType, types.ClassType) and issubclass(kwType, SalomeEntry):
220            selection, commentaire = self.appliEficas.selectEntryFromSalome(kwType,editor=self.editor)
221
222         if commentaire !="" :
223             self.editor.affiche_infos(tr(QString(commentaire)))
224         monTexte=""
225         if selection == [] : return
226         for geomElt in selection:
227             monTexte=geomElt+","
228         monTexte= monTexte[0:-1]
229         self.lineEditVal.setText(QString(monTexte))
230
231   def BView2DPressed(self):
232         valeur=self.lineEditVal.text()
233         if valeur == QString("") : return
234         valeur = str(valeur)
235         if valeur :
236            ok, msgError = self.appliEficas.displayShape(valeur)
237            if not ok:
238               self.appliEficas.affiche_infos(msgError,Qt.red)
239
240   def BParametresPressed(self):
241         liste=self.node.item.get_liste_param_possible()
242         from monListeParamPanel import MonListeParamPanel
243         MonListeParamPanel(liste=liste,parent=self).show()
244