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