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