]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/gereIcones.py
Salome HOME
merge Nizhny
[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           if not(('grma' in repr(mctype)) or ('grno' in repr(mctype))) or not(self.editor.salome): 
110              self.BView2D.close()
111           else : 
112              icon1=QIcon(self.repIcon+"/eye.png")
113              self.RBSalomeVue.setIcon(icon1)
114              self.connect(self.RBSalomeVue,SIGNAL("clicked()"),self.BView2DPressed)
115        else:
116           self.RBSalome.close()
117           self.RBSalomeVue.close()
118
119      
120   def setIconesFichier(self):
121        if not ( hasattr(self,"BFichier")): return
122        mc = self.node.item.get_definition()
123        mctype = mc.type[0]
124        if mctype == "Repertoire":
125           self.BRepertoire=self.BFichier
126           self.connect(self.BRepertoire,SIGNAL("clicked()"),self.BRepertoirePressed)
127           self.BVisuFichier.close()
128        else :
129           self.connect(self.BFichier,SIGNAL("clicked()"),self.BFichierPressed)
130           self.connect(self.BVisuFichier,SIGNAL("clicked()"),self.BFichierVisu)
131
132
133
134   def setIconesGenerales(self):
135       repIcon=self.node.editor.appliEficas.repIcon
136       if hasattr(self,"BVisuListe") :
137          fichier=os.path.join(repIcon, 'plusnode.png')
138          icon = QIcon(fichier)
139          self.BVisuListe.setIcon(icon)
140       if hasattr(self,"RBDeplie") :
141          fichier=os.path.join(repIcon, 'plusnode.png')
142          icon = QIcon(fichier)
143          self.RBDeplie.setIcon(icon)
144       if hasattr(self,"RBPlie") :
145          fichier=os.path.join(repIcon, 'minusnode.png')
146          icon = QIcon(fichier)
147          self.RBPlie.setIcon(icon)
148
149       
150
151   def setRun(self):
152       if hasattr(self.editor.appliEficas, 'mesScripts'):
153          if hasattr(self.editor,'tree') and self.editor.tree.currentItem().item.get_nom() in self.appliEficas.mesScripts.dict_commandes.keys() :
154                print 'il faut programmer le self.ajoutScript()'
155                print '#PNPNPNPN'
156                return
157       if hasattr(self,"RBRun"): self.RBRun.close()
158
159
160   def aDetruire(self):
161       self.node.delete()
162
163   def setValide(self):
164       #print " c est le moment de gerer le passage au suivant"
165       if not(hasattr (self,'RBValide')) : return
166       icon = QIcon()
167       if self.node.item.object.isvalid() : 
168          icon=QIcon(self.repIcon+"/ast-green-ball.png")
169       else :
170          icon=QIcon(self.repIcon+"/ast-red-ball.png")
171       print "lllllllllllllllllllllllllllllllll"
172       self.RBValide.setIcon(icon)
173
174   # il faut chercher la bonne fenetre
175   def rendVisible(self):
176       #print "je passe par rendVisible de FacultatifOuOptionnel"
177       #print self
178       #print self.node.fenetre
179       #print "return pour etre sure"
180       return
181       #PNPN
182       newNode=self.node.treeParent.chercheNoeudCorrespondant(self.node.item.object)
183       #print newNode
184       self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(newNode.fenetre)
185       #newNode.fenetre.setFocus()
186
187
188 class ContientIcones:
189
190   def BFichierVisu(self):
191        fichier=self.lineEditVal.text()
192        if fichier == None or str(fichier)=="" : return
193        from monViewTexte import ViewText
194        try :
195          if sys.platform[0:5]=="linux" :
196            cmd="xdg-open "+ str(fichier)
197            os.system(cmd)
198          else                          :
199            os.startfile(str(fichier)) 
200        except:
201          try :
202             fp=open(fichier)
203             txt=fp.read()
204             nomFichier=QFileInfo(fichier).baseName()
205             maVue=ViewText(self,entete=nomFichier)
206             maVue.setText(txt)
207             maVue.show()
208             fp.close()
209          except:
210             QMessageBox.warning( None,
211                        tr("Visualisation Fichier "),
212                        tr("Impossibilite d'afficher le Fichier"),)
213
214   def BFichierPressed(self):
215       mctype = self.node.item.get_definition().type
216       if len(mctype) > 1:
217           filters = mctype[1]
218       elif hasattr(mctype[0], "filters"):
219           filters = mctype[0].filters
220       else:
221           filters = QString()
222       if len(mctype) > 2 and mctype[2] == "Sauvegarde":
223           fichier = QFileDialog.getSaveFileName(self.appliEficas,
224                               tr('Sauvegarder Fichier'),
225                               self.appliEficas.CONFIGURATION.savedir,
226                               filters)
227       else:
228           fichier = QFileDialog.getOpenFileName(self.appliEficas,
229                               tr('Ouvrir Fichier'),
230                               self.appliEficas.CONFIGURATION.savedir,
231                               filters)
232
233       if not(fichier.isNull()):
234          ulfile = os.path.abspath(unicode(fichier))
235          self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
236          self.lineEditVal.setText(fichier)
237          self.editor.affiche_commentaire(tr("Fichier selectionne"))
238          self.LEValeurPressed()
239          if (QFileInfo(fichier).suffix() in listeSuffixe ):
240              self.image=fichier
241              if (not hasattr(self,"BSelectInFile")):
242                self.BSelectInFile = QPushButton(self.Widget8)
243                self.BSelectInFile.setMinimumSize(QSize(140,40))
244                self.BSelectInFile.setObjectName("BSelectInFile")
245                self.gridLayout.addWidget(self.BSelectInFile,1,1,1,1)
246                self.BSelectInFile.setText(tr("Selection"))
247                self.connect(self.BSelectInFile,SIGNAL("clicked()"),self.BSelectInFilePressed)
248              else :
249                self.BSelectInFile.setVisible(1)
250          elif hasattr(self, "BSelectInFile"):
251              self.BSelectInFile.setVisible(0)
252
253   def BRepertoirePressed(self):
254       directory = QFileDialog.getExistingDirectory(self.appliEficas,
255             directory = self.appliEficas.CONFIGURATION.savedir,
256             options = QFileDialog.ShowDirsOnly)
257
258       if not directory.isNull():
259          absdir = os.path.abspath(unicode(directory))
260          self.appliEficas.CONFIGURATION.savedir = os.path.dirname(absdir)
261          self.lineEditVal.setText(directory)
262          self.LEValeurPressed()
263
264   def BSelectInFilePressed(self):
265       from monSelectImage import MonSelectImage
266       MonSelectImage(file=self.image,parent=self).show()
267
268           
269
270   def BSalomePressed(self):
271         self.editor.affiche_commentaire(QString(""))
272         selection=[]
273         commentaire=""
274         genea=self.node.item.get_genealogie()
275         kwType = self.node.item.get_definition().type[0]
276         for e in genea:
277             if "GROUP_NO" in e: kwType = "GROUP_NO"
278             if "GROUP_MA" in e: kwType = "GROUP_MA"
279
280         if 'grno' in repr(kwType): kwType = "GROUP_NO"
281         if 'grma' in repr(kwType): kwType = "GROUP_NO"
282
283         if kwType in ("GROUP_NO","GROUP_MA"):
284            selection, commentaire = self.appliEficas.selectGroupFromSalome(kwType,editor=self.editor)
285
286         mc = self.node.item.get_definition()
287
288         if  (isinstance(mc.type,types.TupleType) and len(mc.type) > 1 and "(*.med)" in mc.type[1] ):
289            selection, commentaire = self.appliEficas.selectMeshFile(editor=self.editor)
290            print selection, commentaire
291            if commentaire != "" : 
292                   QMessageBox.warning( None,
293                   tr("Export Med vers Fichier "),
294                   tr("Impossibilite d exporter le Fichier"),)
295                   return
296            else :
297                   self.lineEditVal.setText(QString(selection))
298                   return
299
300         from Accas import SalomeEntry
301         if isinstance(kwType, types.ClassType) and issubclass(kwType, SalomeEntry):
302            selection, commentaire = self.appliEficas.selectEntryFromSalome(kwType,editor=self.editor)
303
304         if commentaire !="" :
305             self.editor.affiche_infos(tr(QString(commentaire)))
306         monTexte=""
307         if selection == [] : return
308         for geomElt in selection:
309             monTexte=geomElt+","
310         monTexte= monTexte[0:-1]
311         self.lineEditVal.setText(QString(monTexte))
312
313   def BView2DPressed(self):
314         valeur=self.lineEditVal.text()
315         if valeur == QString("") : return
316         valeur = str(valeur)
317         if valeur :
318            ok, msgError = self.appliEficas.displayShape(valeur)
319            if not ok:
320               self.editor.affiche_infos(msgError,Qt.red)
321
322   def BParametresPressed(self):
323         liste=self.node.item.get_liste_param_possible()
324         from monListeParamPanel import MonListeParamPanel
325         MonListeParamPanel(liste=liste,parent=self).show()
326