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