Salome HOME
80316865f4e7f6a7acb098ca1afb96bc0e9962be
[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       if self.node.item.object.isoblig() : 
97          icon=QIcon(self.repIcon+"/deleteRondVide.png")
98          self.RBPoubelle.setIcon(icon)
99          return
100       icon=QIcon(self.repIcon+"/deleteRond.png")
101       self.RBPoubelle.setIcon(icon)
102       if monEnvQT5 : self.RBPoubelle.clicked.connect(self.aDetruire)
103       else : self.connect(self.RBPoubelle,SIGNAL("clicked()"),self.aDetruire)
104
105   def setIconesSalome(self):
106        if not (hasattr(self,"RBSalome")): return
107        from Accas import SalomeEntry
108        mc = self.node.item.get_definition()
109        mctype = mc.type[0]
110        enable_salome_selection = self.editor.salome and \
111          (('grma' in repr(mctype)) or ('grno' in repr(mctype)) or ('SalomeEntry' in repr(mctype)) or \
112          (hasattr(mctype, "enable_salome_selection") and mctype.enable_salome_selection))
113
114        if enable_salome_selection:
115           icon=QIcon(self.repIcon+"/flecheSalome.png")
116           self.RBSalome.setIcon(icon)
117           if monEnvQT5 : self.RBSalome.pressed.connect(self.BSalomePressed)
118           else : self.connect(self.RBSalome,SIGNAL("pressed()"),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              if monEnvQT5 : self.RBSalomeVue.clicked.connect(self.BView2DPressed)
128              else : self.connect(self.RBSalomeVue,SIGNAL("clicked()"),self.BView2DPressed)
129        else:
130           self.RBSalome.close()
131           self.RBSalomeVue.close()
132
133      
134   def setIconesFichier(self):
135        if not ( hasattr(self,"BFichier")): return
136        mc = self.node.item.get_definition()
137        mctype = mc.type[0]
138        if mctype == "Repertoire":
139           self.BRepertoire=self.BFichier
140           if monEnvQT5 : self.BRepertoire.clicked.connect(self.BRepertoirePressed)
141           else : self.connect(self.BRepertoire,SIGNAL("clicked()"),self.BRepertoirePressed)
142           self.BVisuFichier.close()
143        else :
144           if monEnvQT5 : self.BFichier.clicked.connect(self.BFichierPressed)
145           else : self.connect(self.BFichier,SIGNAL("clicked()"),self.BFichierPressed)
146           if monEnvQT5 : self.BVisuFichier.clicked.connect(self.BFichierVisu)
147           else : self.connect(self.BVisuFichier,SIGNAL("clicked()"),self.BFichierVisu)
148
149
150
151   def setIconesGenerales(self):
152       repIcon=self.node.editor.appliEficas.repIcon
153       if hasattr(self,"BVisuListe") :
154          fichier=os.path.join(repIcon, 'plusnode.png')
155          icon = QIcon(fichier)
156          self.BVisuListe.setIcon(icon)
157       if hasattr(self,"RBDeplie") :
158          fichier=os.path.join(repIcon, 'plusnode.png')
159          icon = QIcon(fichier)
160          self.RBDeplie.setIcon(icon)
161       if hasattr(self,"RBPlie") :
162          fichier=os.path.join(repIcon, 'minusnode.png')
163          icon = QIcon(fichier)
164          self.RBPlie.setIcon(icon)
165
166       
167
168   def setRun(self):
169       if hasattr(self.editor.appliEficas, 'mesScripts'):
170          if hasattr(self.editor,'tree') and self.editor.tree.currentItem().item.get_nom() in self.appliEficas.mesScripts.dict_commandes.keys() :
171                self.ajoutScript()
172                return
173       if hasattr(self,"RBRun"): self.RBRun.close()
174       if hasattr(self,"CBScripts"): self.CBScripts.close()
175
176
177   def aDetruire(self):
178       self.node.delete()
179
180   def setValide(self):
181       #print " c est le moment de gerer le passage au suivant"
182       if not(hasattr (self,'RBValide')) : return
183       icon = QIcon()
184       if self.node.item.object.isvalid() : 
185          icon=QIcon(self.repIcon+"/ast-green-ball.png")
186       else :
187          icon=QIcon(self.repIcon+"/ast-red-ball.png")
188       self.RBValide.setIcon(icon)
189
190   # il faut chercher la bonne fenetre
191   def rendVisible(self):
192       #print "je passe par rendVisible de FacultatifOuOptionnel"
193       #print self
194       #print self.node.fenetre
195       #print "return pour etre sure"
196       return
197       #PNPN
198       newNode=self.node.treeParent.chercheNoeudCorrespondant(self.node.item.object)
199       #print newNode
200       self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(newNode.fenetre)
201       #newNode.fenetre.setFocus()
202
203
204   def ajoutScript(self):
205     # cochon mais je n arrive pas a faire mieux avec le mecanisme de plugin
206         listeCommandes=self.appliEficas.mesScripts.dict_commandes[self.node.item.get_nom()]
207         if type(listeCommandes) != types.TupleType: listeCommandes=(listeCommandes,)
208         numero=-1
209         for commande in listeCommandes :
210           numero+=1
211           conditionSalome=commande[3]
212           if (self.appliEficas.salome == 0 and conditionSalome == True): continue
213           self.CBScripts.addItem(commande[1])
214           #self.CBScripts.addItem(commande[1],QVariant((numero)))
215         return
216         if 1 :
217            label=commande[1]
218            tip=commande[5]
219            self.action=QAction(label,self.tree)
220            self.action.setStatusTip(tip)
221            if monEnvQT5 :
222               if numero==4:
223                  self.action.triggered.connect(self.AppelleFonction4)
224               if numero==3:
225                  self.action.triggered.connect(self.AppelleFonction3)
226                  numero=4
227               if numero==2:
228                  self.action.triggered.connect(self.AppelleFonction2)
229                  numero=3
230               if numero==1:
231                  self.action.triggered.connect(self.AppelleFonction1)
232                  numero=2
233               if numero==0:
234                  self.action.triggered.connect(self.AppelleFonction0)
235                  numero=1
236            else:
237               if numero==4:
238                  self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction4)
239               if numero==3:
240                  self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction3)
241                  numero=4
242               if numero==2:
243                  self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction2)
244                  numero=3
245               if numero==1:
246                  self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction1)
247                  numero=2
248               if numero==0:
249                  self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction0)
250                  numero=1
251            self.menu.addAction(self.action)
252
253 class ContientIcones:
254
255   def BFichierVisu(self):
256        fichier=self.lineEditVal.text()
257        if fichier == None or str(fichier)=="" : return
258        from monViewTexte import ViewText
259        try :
260          if sys.platform[0:5]=="linux" :
261            cmd="xdg-open "+ str(fichier)
262            os.system(cmd)
263          else                          :
264            os.startfile(str(fichier)) 
265        except:
266          try :
267             fp=open(fichier)
268             txt=fp.read()
269             nomFichier=QFileInfo(fichier).baseName()
270             maVue=ViewText(self,entete=nomFichier)
271             maVue.setText(txt)
272             maVue.show()
273             fp.close()
274          except:
275             QMessageBox.warning( None,
276                        tr("Visualisation Fichier "),
277                        tr("Impossibilite d'afficher le Fichier"),)
278
279   def BFichierPressed(self):
280       mctype = self.node.item.get_definition().type
281       if len(mctype) > 1:
282           filters = mctype[1]
283       elif hasattr(mctype[0], "filters"):
284           filters = mctype[0].filters
285       else:
286           filters = None
287       if len(mctype) > 2 and mctype[2] == "Sauvegarde":
288           fichier = QFileDialog.getSaveFileName(self.appliEficas,
289                               tr('Sauvegarder Fichier'),
290                               self.appliEficas.CONFIGURATION.savedir,
291                               filters)
292       else:
293           fichier = QFileDialog.getOpenFileName(self.appliEficas,
294                               tr('Ouvrir Fichier'),
295                               self.appliEficas.CONFIGURATION.savedir,
296                               filters)
297
298       if monEnvQT5 : fichier=fichier[0]
299       if not(fichier):
300          ulfile = os.path.abspath(unicode(fichier))
301          self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
302          self.lineEditVal.setText(fichier)
303          self.editor.affiche_commentaire(tr("Fichier selectionne"))
304          self.LEValeurPressed()
305          if (QFileInfo(fichier).suffix() in listeSuffixe ):
306              self.image=fichier
307              if (not hasattr(self,"BSelectInFile")):
308                self.BSelectInFile = QPushButton(self.Widget8)
309                self.BSelectInFile.setMinimumSize(QSize(140,40))
310                self.BSelectInFile.setObjectName("BSelectInFile")
311                self.gridLayout.addWidget(self.BSelectInFile,1,1,1,1)
312                self.BSelectInFile.setText(tr("Selection"))
313                if monEnvQT5 : self.BSelectInFile.clicked.connect(self.BSelectInFilePressed)
314                else : self.connect(self.BSelectInFile,SIGNAL("clicked()"),self.BSelectInFilePressed)
315              else :
316                self.BSelectInFile.setVisible(1)
317          elif hasattr(self, "BSelectInFile"):
318              self.BSelectInFile.setVisible(0)
319
320   def BRepertoirePressed(self):
321       directory = QFileDialog.getExistingDirectory(self.appliEficas,
322             directory = self.appliEficas.CONFIGURATION.savedir,
323             options = QFileDialog.ShowDirsOnly)
324
325       if not directory.isNull():
326          absdir = os.path.abspath(unicode(directory))
327          self.appliEficas.CONFIGURATION.savedir = os.path.dirname(absdir)
328          self.lineEditVal.setText(directory)
329          self.LEValeurPressed()
330
331   def BSelectInFilePressed(self):
332       from monSelectImage import MonSelectImage
333       MonSelectImage(file=self.image,parent=self).show()
334
335           
336
337   def BSalomePressed(self):
338         self.editor.affiche_commentaire(QString(""))
339         selection=[]
340         commentaire=""
341         genea=self.node.item.get_genealogie()
342         kwType = self.node.item.get_definition().type[0]
343         for e in genea:
344             if "GROUP_NO" in e: kwType = "GROUP_NO"
345             if "GROUP_MA" in e: kwType = "GROUP_MA"
346
347         if 'grno' in repr(kwType): kwType = "GROUP_NO"
348         if 'grma' in repr(kwType): kwType = "GROUP_NO"
349
350         if kwType in ("GROUP_NO","GROUP_MA"):
351            selection, commentaire = self.appliEficas.selectGroupFromSalome(kwType,editor=self.editor)
352
353         mc = self.node.item.get_definition()
354
355         if  (isinstance(mc.type,types.TupleType) and len(mc.type) > 1 and "(*.med)" in mc.type[1] ):
356            selection, commentaire = self.appliEficas.selectMeshFile(editor=self.editor)
357            print selection, commentaire
358            if commentaire != "" : 
359                   QMessageBox.warning( None,
360                   tr("Export Med vers Fichier "),
361                   tr("Impossibilite d exporter le Fichier"),)
362                   return
363            else :
364                   self.lineEditVal.setText(QString(selection))
365                   return
366
367         from Accas import SalomeEntry
368         if isinstance(kwType, types.ClassType) and issubclass(kwType, SalomeEntry):
369            selection, commentaire = self.appliEficas.selectEntryFromSalome(kwType,editor=self.editor)
370
371         if commentaire !="" :
372             self.editor.affiche_infos(QString(tr(str(commentaire))))
373         monTexte=""
374         if selection == [] : return
375         for geomElt in selection:
376             monTexte=geomElt+","
377         monTexte= monTexte[0:-1]
378         self.lineEditVal.setText(QString(monTexte))
379         self.LEValeurPressed()
380
381   def BView2DPressed(self):
382         valeur=self.lineEditVal.text()
383         valeur = str(valeur)
384         if valeur == str("") : return
385         if valeur :
386            ok, msgError = self.appliEficas.displayShape(valeur)
387            if not ok:
388               self.editor.affiche_infos(msgError,Qt.red)
389
390   def BParametresPressed(self):
391         liste=self.node.item.get_liste_param_possible()
392         from monListeParamPanel import MonListeParamPanel
393         MonListeParamPanel(liste=liste,parent=self).show()
394