Salome HOME
bugs + translator
[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       listeRegles=()
35       try :
36          listeRegles     = self.node.item.get_regles()
37       except :
38          pass
39       if hasattr(self,"RBRegle"):
40         if listeRegles==() : self.RBRegle.close() 
41         else :
42            icon3=QIcon(self.repIcon+"/lettreRblanc30.png")
43            self.RBRegle.setIcon(icon3)
44            self.connect( self.RBRegle,SIGNAL("clicked()"),self.viewRegles)
45
46       cle_doc=None
47       if not hasattr(self,"RBInfo"):return
48       icon=QIcon(self.repIcon+"/point-interrogation30.png")
49       self.RBInfo.setIcon(icon)
50
51       from monWidgetCommande import MonWidgetCommande
52       if isinstance(self,MonWidgetCommande) and self.editor.code =="MAP":
53          self.cle_doc = self.chercheDocMAP()
54       else :
55          self.cle_doc = self.node.item.get_docu()
56       if self.cle_doc == None  : self.RBInfo.close()
57       else : self.connect (self.RBInfo,SIGNAL("clicked()"),self.viewDoc)
58
59
60   def chercheDocMAP(self):
61       try :
62         clef=self.editor.CONFIGURATION.adresse+"/"
63       except :
64         return None
65       for k in self.editor.readercata.cata[0].JdC.dict_groupes.keys():
66           if self.obj.nom in self.editor.readercata.cata[0].JdC.dict_groupes[k]:
67              clef+=k
68              break
69       clef+="/"+ self.obj.nom[0:-5].lower()+"/spec_"+self.obj.nom[0:-5].lower()+".html"
70
71       return clef
72  
73   def viewDoc(self):
74       try :
75           if sys.platform[0:5]=="linux" : cmd="xdg-open "+self.cle_doc
76           else                          : cmd="start "+self.cle_doc
77           os.system(cmd)
78       except:
79           QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
80
81   def viewRegles(self):
82       self.node.AppelleBuildLBRegles()
83
84
85   def setIconePoubelle(self):
86       if not(hasattr(self,"RBPoubelle")):return
87       if self.node.item.object.isoblig() : 
88          icon=QIcon(self.repIcon+"/deleteRondVide.png")
89          self.RBPoubelle.setIcon(icon)
90          return
91       icon=QIcon(self.repIcon+"/deleteRond.png")
92       self.RBPoubelle.setIcon(icon)
93       self.connect(self.RBPoubelle,SIGNAL("clicked()"),self.aDetruire)
94
95   def setIconesSalome(self):
96        if not (hasattr(self,"RBSalome")): return
97        from Accas import SalomeEntry
98        mc = self.node.item.get_definition()
99        mctype = mc.type[0]
100        enable_salome_selection = self.editor.salome and \
101          (('grma' in repr(mctype)) or ('grno' in repr(mctype)) or ('SalomeEntry' in repr(mctype)) or \
102          (hasattr(mctype, "enable_salome_selection") and mctype.enable_salome_selection))
103
104        if enable_salome_selection:
105           icon=QIcon(self.repIcon+"/flecheSalome.png")
106           self.RBSalome.setIcon(icon)
107           self.connect(self.RBSalome,SIGNAL("pressed()"),self.BSalomePressed)
108
109 #PNPN --> Telemac A revoir surement
110 # cela ou le catalogue grpma ou salomeEntry
111           if not(('grma' in repr(mctype)) or ('grno' in repr(mctype))) or not(self.editor.salome): 
112              if hasattr(self,"RBSalomeVue") : self.RBSalomeVue.close()
113           else : 
114              icon1=QIcon(self.repIcon+"/eye.png")
115              self.RBSalomeVue.setIcon(icon1)
116              self.connect(self.RBSalomeVue,SIGNAL("clicked()"),self.BView2DPressed)
117        else:
118           self.RBSalome.close()
119           self.RBSalomeVue.close()
120
121      
122   def setIconesFichier(self):
123        if not ( hasattr(self,"BFichier")): return
124        mc = self.node.item.get_definition()
125        mctype = mc.type[0]
126        if mctype == "Repertoire":
127           self.BRepertoire=self.BFichier
128           self.connect(self.BRepertoire,SIGNAL("clicked()"),self.BRepertoirePressed)
129           self.BVisuFichier.close()
130        else :
131           self.connect(self.BFichier,SIGNAL("clicked()"),self.BFichierPressed)
132           self.connect(self.BVisuFichier,SIGNAL("clicked()"),self.BFichierVisu)
133
134
135
136   def setIconesGenerales(self):
137       repIcon=self.node.editor.appliEficas.repIcon
138       if hasattr(self,"BVisuListe") :
139          fichier=os.path.join(repIcon, 'plusnode.png')
140          icon = QIcon(fichier)
141          self.BVisuListe.setIcon(icon)
142       if hasattr(self,"RBDeplie") :
143          fichier=os.path.join(repIcon, 'plusnode.png')
144          icon = QIcon(fichier)
145          self.RBDeplie.setIcon(icon)
146       if hasattr(self,"RBPlie") :
147          fichier=os.path.join(repIcon, 'minusnode.png')
148          icon = QIcon(fichier)
149          self.RBPlie.setIcon(icon)
150
151       
152
153   def setRun(self):
154       if hasattr(self.editor.appliEficas, 'mesScripts'):
155          if hasattr(self.editor,'tree') and self.editor.tree.currentItem().item.get_nom() in self.appliEficas.mesScripts.dict_commandes.keys() :
156                print 'il faut programmer le self.ajoutScript()'
157                print '#PNPNPNPN'
158                return
159       if hasattr(self,"RBRun"): self.RBRun.close()
160
161
162   def aDetruire(self):
163       self.node.delete()
164
165   def setValide(self):
166       #print " c est le moment de gerer le passage au suivant"
167       if not(hasattr (self,'RBValide')) : return
168       icon = QIcon()
169       if self.node.item.object.isvalid() : 
170          icon=QIcon(self.repIcon+"/ast-green-ball.png")
171       else :
172          icon=QIcon(self.repIcon+"/ast-red-ball.png")
173       self.RBValide.setIcon(icon)
174
175   # il faut chercher la bonne fenetre
176   def rendVisible(self):
177       #print "je passe par rendVisible de FacultatifOuOptionnel"
178       #print self
179       #print self.node.fenetre
180       #print "return pour etre sure"
181       return
182       #PNPN
183       newNode=self.node.treeParent.chercheNoeudCorrespondant(self.node.item.object)
184       #print newNode
185       self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(newNode.fenetre)
186       #newNode.fenetre.setFocus()
187
188
189 class ContientIcones:
190
191   def BFichierVisu(self):
192        fichier=self.lineEditVal.text()
193        if fichier == None or str(fichier)=="" : return
194        from monViewTexte import ViewText
195        try :
196          if sys.platform[0:5]=="linux" :
197            cmd="xdg-open "+ str(fichier)
198            os.system(cmd)
199          else                          :
200            os.startfile(str(fichier)) 
201        except:
202          try :
203             fp=open(fichier)
204             txt=fp.read()
205             nomFichier=QFileInfo(fichier).baseName()
206             maVue=ViewText(self,entete=nomFichier)
207             maVue.setText(txt)
208             maVue.show()
209             fp.close()
210          except:
211             QMessageBox.warning( None,
212                        tr("Visualisation Fichier "),
213                        tr("Impossibilite d'afficher le Fichier"),)
214
215   def BFichierPressed(self):
216       mctype = self.node.item.get_definition().type
217       if len(mctype) > 1:
218           filters = mctype[1]
219       elif hasattr(mctype[0], "filters"):
220           filters = mctype[0].filters
221       else:
222           filters = QString()
223       if len(mctype) > 2 and mctype[2] == "Sauvegarde":
224           fichier = QFileDialog.getSaveFileName(self.appliEficas,
225                               tr('Sauvegarder Fichier'),
226                               self.appliEficas.CONFIGURATION.savedir,
227                               filters)
228       else:
229           fichier = QFileDialog.getOpenFileName(self.appliEficas,
230                               tr('Ouvrir Fichier'),
231                               self.appliEficas.CONFIGURATION.savedir,
232                               filters)
233
234       if not(fichier.isNull()):
235          ulfile = os.path.abspath(unicode(fichier))
236          self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
237          self.lineEditVal.setText(fichier)
238          self.editor.affiche_commentaire(tr("Fichier selectionne"))
239          self.LEValeurPressed()
240          if (QFileInfo(fichier).suffix() in listeSuffixe ):
241              self.image=fichier
242              if (not hasattr(self,"BSelectInFile")):
243                self.BSelectInFile = QPushButton(self.Widget8)
244                self.BSelectInFile.setMinimumSize(QSize(140,40))
245                self.BSelectInFile.setObjectName("BSelectInFile")
246                self.gridLayout.addWidget(self.BSelectInFile,1,1,1,1)
247                self.BSelectInFile.setText(tr("Selection"))
248                self.connect(self.BSelectInFile,SIGNAL("clicked()"),self.BSelectInFilePressed)
249              else :
250                self.BSelectInFile.setVisible(1)
251          elif hasattr(self, "BSelectInFile"):
252              self.BSelectInFile.setVisible(0)
253
254   def BRepertoirePressed(self):
255       directory = QFileDialog.getExistingDirectory(self.appliEficas,
256             directory = self.appliEficas.CONFIGURATION.savedir,
257             options = QFileDialog.ShowDirsOnly)
258
259       if not directory.isNull():
260          absdir = os.path.abspath(unicode(directory))
261          self.appliEficas.CONFIGURATION.savedir = os.path.dirname(absdir)
262          self.lineEditVal.setText(directory)
263          self.LEValeurPressed()
264
265   def BSelectInFilePressed(self):
266       from monSelectImage import MonSelectImage
267       MonSelectImage(file=self.image,parent=self).show()
268
269           
270
271   def BSalomePressed(self):
272         self.editor.affiche_commentaire(QString(""))
273         selection=[]
274         commentaire=""
275         genea=self.node.item.get_genealogie()
276         kwType = self.node.item.get_definition().type[0]
277         for e in genea:
278             if "GROUP_NO" in e: kwType = "GROUP_NO"
279             if "GROUP_MA" in e: kwType = "GROUP_MA"
280
281         if 'grno' in repr(kwType): kwType = "GROUP_NO"
282         if 'grma' in repr(kwType): kwType = "GROUP_NO"
283
284         if kwType in ("GROUP_NO","GROUP_MA"):
285            selection, commentaire = self.appliEficas.selectGroupFromSalome(kwType,editor=self.editor)
286
287         mc = self.node.item.get_definition()
288
289         if  (isinstance(mc.type,types.TupleType) and len(mc.type) > 1 and "(*.med)" in mc.type[1] ):
290            selection, commentaire = self.appliEficas.selectMeshFile(editor=self.editor)
291            print selection, commentaire
292            if commentaire != "" : 
293                   QMessageBox.warning( None,
294                   tr("Export Med vers Fichier "),
295                   tr("Impossibilite d exporter le Fichier"),)
296                   return
297            else :
298                   self.lineEditVal.setText(QString(selection))
299                   return
300
301         from Accas import SalomeEntry
302         if isinstance(kwType, types.ClassType) and issubclass(kwType, SalomeEntry):
303            selection, commentaire = self.appliEficas.selectEntryFromSalome(kwType,editor=self.editor)
304
305         if commentaire !="" :
306             self.editor.affiche_infos(QString(tr(str(commentaire))))
307         monTexte=""
308         if selection == [] : return
309         for geomElt in selection:
310             monTexte=geomElt+","
311         monTexte= monTexte[0:-1]
312         self.lineEditVal.setText(QString(monTexte))
313         self.LEValeurPressed()
314
315   def BView2DPressed(self):
316         valeur=self.lineEditVal.text()
317         if valeur == QString("") : return
318         valeur = str(valeur)
319         if valeur :
320            ok, msgError = self.appliEficas.displayShape(valeur)
321            if not ok:
322               self.editor.affiche_infos(msgError,Qt.red)
323
324   def BParametresPressed(self):
325         liste=self.node.item.get_liste_param_possible()
326         from monListeParamPanel import MonListeParamPanel
327         MonListeParamPanel(liste=liste,parent=self).show()
328