Salome HOME
merge PSEN
[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,sys
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           if sys.platform[0:5]=="linux" : cmd="xdg-open "+self.cle_doc
67           else                          : cmd="start "+self.cle_doc
68           os.system(cmd)
69       except:
70           QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
71
72
73   def setIconePoubelle(self):
74       if not(hasattr(self,"RBPoubelle")):return
75       icon1 = QtGui.QIcon()
76       repIcon=os.path.join(os.path.abspath(os.path.dirname(__file__)),'../Editeur/icons')
77       if self.node.item.object.isoblig() : 
78          icon1.addPixmap(QtGui.QPixmap(repIcon+"/deleteRondVide.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
79          self.RBPoubelle.setIcon(icon1)
80          return
81       icon1.addPixmap(QtGui.QPixmap(repIcon+"/deleteRond.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
82       self.RBPoubelle.show()
83       self.connect(self.RBPoubelle,SIGNAL("clicked()"),self.aDetruire)
84
85   def setIconesSalome(self):
86        if not (hasattr(self,"RBSalome")): return
87        from Accas import SalomeEntry
88        mc = self.node.item.get_definition()
89        mctype = mc.type[0]
90        enable_salome_selection = self.editor.salome and \
91          (('grma' in repr(mctype)) or ('grno' in repr(mctype)) or ('SalomeEntry' in repr(mctype)) or \
92          (hasattr(mctype, "enable_salome_selection") and mctype.enable_salome_selection))
93        if enable_salome_selection:
94           self.connect(self.RBSalome,SIGNAL("pressed()"),self.BSalomePressed)
95           if not(('grma' in repr(mctype)) or ('grno' in repr(mctype))) or not(self.editor.salome): self.BView2D.close()
96           else : self.connect(self.RBSalomeVue,SIGNAL("clicked()"),self.BView2DPressed)
97        else:
98           self.RBSalome.close()
99           self.RBSalomeVue.close()
100
101      
102   def setIconesFichier(self):
103        if not ( hasattr(self,"BFichier")): return
104        mc = self.node.item.get_definition()
105        mctype = mc.type[0]
106        if mctype == "Repertoire":
107           self.BRepertoire=self.BFichier
108           self.connect(self.BRepertoire,SIGNAL("clicked()"),self.BRepertoirePressed)
109           self.BVisuFichier.close()
110        else :
111           self.connect(self.BFichier,SIGNAL("clicked()"),self.BFichierPressed)
112           self.connect(self.BVisuFichier,SIGNAL("clicked()"),self.BFichierVisu)
113
114
115
116
117   def setRun(self):
118       if hasattr(self.editor.appliEficas, 'mesScripts'):
119          if self.tree.currentItem().item.get_nom() in self.appliEficas.mesScripts.dict_commandes.keys() :
120                print 'il faut programmer le self.ajoutScript()'
121                print '#PNPNPNPN'
122                return
123       if hasattr(self,"RBRun"): self.RBRun.close()
124
125
126   def aDetruire(self):
127       self.node.delete()
128
129   def setValide(self):
130       #print " c est le moment de gerer le passage au suivant"
131       if not(hasattr (self,'RBValide')) : return
132       icon = QIcon()
133       repIcon=os.path.join(os.path.abspath(os.path.dirname(__file__)),'../Editeur/icons')
134       if self.node.item.object.isvalid() : 
135          icon=QIcon(repIcon+"/ast-green-ball.png")
136       else :
137          icon=QIcon(repIcon+"/ast-red-ball.png")
138       self.RBValide.setIcon(icon)
139
140   # il faut chercher la bonne fenetre
141   def rendVisible(self):
142       #print "je passe par rendVisible de FacultatifOuOptionnel"
143       #print self
144       #print self.node.fenetre
145       #print "return pour etre sure"
146       return
147       #PNPN
148       newNode=self.node.treeParent.chercheNoeudCorrespondant(self.node.item.object)
149       #print newNode
150       self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(newNode.fenetre)
151       #newNode.fenetre.setFocus()
152
153
154 class ContientIcones:
155
156   def BFichierVisu(self):
157        fichier=self.lineEditVal.text()
158        if fichier == None or str(fichier)=="" : return
159        from monViewTexte import ViewText
160        try :
161          if sys.platform[0:5]=="linux" :
162            cmd="xdg-open "+ str(fichier)
163            os.system(cmd)
164          else                          :
165            os.startfile(str(fichier)) 
166        except:
167          try :
168             fp=open(fichier)
169             txt=fp.read()
170             nomFichier=QFileInfo(fichier).baseName()
171             maVue=ViewText(self,entete=nomFichier)
172             maVue.setText(txt)
173             maVue.show()
174             fp.close()
175          except:
176             QMessageBox.warning( None,
177                        tr("Visualisation Fichier "),
178                        tr("Impossibilite d'afficher le Fichier"),)
179
180   def BFichierPressed(self):
181       mctype = self.node.item.get_definition().type
182       if len(mctype) > 1:
183           filters = mctype[1]
184       elif hasattr(mctype[0], "filters"):
185           filters = mctype[0].filters
186       else:
187           filters = QString()
188       if len(mctype) > 2 and mctype[2] == "Sauvegarde":
189           fichier = QFileDialog.getSaveFileName(self.appliEficas,
190                               tr('Sauvegarder Fichier'),
191                               self.appliEficas.CONFIGURATION.savedir,
192                               filters)
193       else:
194           fichier = QFileDialog.getOpenFileName(self.appliEficas,
195                               tr('Ouvrir Fichier'),
196                               self.appliEficas.CONFIGURATION.savedir,
197                               filters)
198
199       if not(fichier.isNull()):
200          ulfile = os.path.abspath(unicode(fichier))
201          self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
202          self.lineEditVal.setText(fichier)
203          self.editor.affiche_infos(tr("Fichier selectionne"))
204          self.LEValeurPressed()
205          if (QFileInfo(fichier).suffix() in listeSuffixe ):
206              self.image=fichier
207              if (not hasattr(self,"BSelectInFile")):
208                self.BSelectInFile = QPushButton(self.Widget8)
209                self.BSelectInFile.setMinimumSize(QSize(140,40))
210                self.BSelectInFile.setObjectName("BSelectInFile")
211                self.gridLayout.addWidget(self.BSelectInFile,1,1,1,1)
212                self.BSelectInFile.setText(tr("Selection"))
213                self.connect(self.BSelectInFile,SIGNAL("clicked()"),self.BSelectInFilePressed)
214              else :
215                self.BSelectInFile.setVisible(1)
216          elif hasattr(self, "BSelectInFile"):
217              self.BSelectInFile.setVisible(0)
218
219   def BRepertoirePressed(self):
220       directory = QFileDialog.getExistingDirectory(self.appliEficas,
221             directory = self.appliEficas.CONFIGURATION.savedir,
222             options = QFileDialog.ShowDirsOnly)
223
224       if not directory.isNull():
225          absdir = os.path.abspath(unicode(directory))
226          self.appliEficas.CONFIGURATION.savedir = os.path.dirname(absdir)
227          self.lineEditVal.setText(directory)
228          self.LEValeurPressed()
229
230   def BSelectInFilePressed(self):
231       from monSelectImage import MonSelectImage
232       MonSelectImage(file=self.image,parent=self).show()
233
234           
235
236   def BSalomePressed(self):
237         self.editor.affiche_infos(QString(""))
238         selection=[]
239         commentaire=""
240         genea=self.node.item.get_genealogie()
241         kwType = self.node.item.get_definition().type[0]
242         for e in genea:
243             if "GROUP_NO" in e: kwType = "GROUP_NO"
244             if "GROUP_MA" in e: kwType = "GROUP_MA"
245
246         if 'grno' in repr(kwType): kwType = "GROUP_NO"
247         if 'grma' in repr(kwType): kwType = "GROUP_NO"
248
249         if kwType in ("GROUP_NO","GROUP_MA"):
250            selection, commentaire = self.appliEficas.selectGroupFromSalome(kwType,editor=self.editor)
251
252         mc = self.node.item.get_definition()
253
254         if  (isinstance(mc.type,types.TupleType) and len(mc.type) > 1 and "(*.med)" in mc.type[1] ):
255            selection, commentaire = self.appliEficas.selectMeshFile(editor=self.editor)
256            print selection, commentaire
257            if commentaire != "" : 
258                   QMessageBox.warning( None,
259                   tr("Export Med vers Fichier "),
260                   tr("Impossibilite d exporter le Fichier"),)
261                   return
262            else :
263                   self.lineEditVal.setText(QString(selection))
264                   return
265
266         from Accas import SalomeEntry
267         if isinstance(kwType, types.ClassType) and issubclass(kwType, SalomeEntry):
268            selection, commentaire = self.appliEficas.selectEntryFromSalome(kwType,editor=self.editor)
269
270         if commentaire !="" :
271             self.editor.affiche_infos(tr(QString(commentaire)))
272         monTexte=""
273         if selection == [] : return
274         for geomElt in selection:
275             monTexte=geomElt+","
276         monTexte= monTexte[0:-1]
277         self.lineEditVal.setText(QString(monTexte))
278
279   def BView2DPressed(self):
280         valeur=self.lineEditVal.text()
281         if valeur == QString("") : return
282         valeur = str(valeur)
283         if valeur :
284            ok, msgError = self.appliEficas.displayShape(valeur)
285            if not ok:
286               self.appliEficas.affiche_infos(msgError,Qt.red)
287
288   def BParametresPressed(self):
289         liste=self.node.item.get_liste_param_possible()
290         from monListeParamPanel import MonListeParamPanel
291         MonListeParamPanel(liste=liste,parent=self).show()
292