1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 import string,types,os,re,sys
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27 from Extensions.i18n import tr
28 listeSuffixe=('bmp','png','jpg' ,'txt','med')
31 class FacultatifOuOptionnel:
33 def setReglesEtAide(self):
36 listeRegles = self.node.item.get_regles()
39 if hasattr(self,"RBRegle"):
40 if listeRegles==() : self.RBRegle.close()
42 icon3=QIcon(self.repIcon+"/lettreRblanc30.png")
43 self.RBRegle.setIcon(icon3)
44 self.connect( self.RBRegle,SIGNAL("clicked()"),self.viewRegles)
47 if not hasattr(self,"RBInfo"):return
48 icon=QIcon(self.repIcon+"/point-interrogation30.png")
49 self.RBInfo.setIcon(icon)
51 from monWidgetCommande import MonWidgetCommande
52 if isinstance(self,MonWidgetCommande) and self.editor.code =="MAP":
53 self.cle_doc = self.chercheDocMAP()
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)
60 def chercheDocMAP(self):
62 clef=self.editor.CONFIGURATION.adresse+"/"
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]:
69 clef+="/"+ self.obj.nom[0:-5].lower()+"/spec_"+self.obj.nom[0:-5].lower()+".html"
75 if sys.platform[0:5]=="linux" : cmd="xdg-open "+self.cle_doc
76 else : cmd="start "+self.cle_doc
79 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
82 self.node.AppelleBuildLBRegles()
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)
91 icon=QIcon(self.repIcon+"/deleteRond.png")
92 self.RBPoubelle.setIcon(icon)
93 self.connect(self.RBPoubelle,SIGNAL("clicked()"),self.aDetruire)
95 def setIconesSalome(self):
96 if not (hasattr(self,"RBSalome")): return
97 from Accas import SalomeEntry
98 mc = self.node.item.get_definition()
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))
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)
109 #PNPN --> Telemac A revoir surement
110 # cela ou le catalogue grpma ou salomeEntry
111 if not(('grma' in repr(mctype)) or ('grno' in repr(mctype))) or not(self.editor.salome):
112 if hasattr(self,"RBSalomeVue") : self.RBSalomeVue.close()
114 icon1=QIcon(self.repIcon+"/eye.png")
115 self.RBSalomeVue.setIcon(icon1)
116 self.connect(self.RBSalomeVue,SIGNAL("clicked()"),self.BView2DPressed)
118 self.RBSalome.close()
119 self.RBSalomeVue.close()
122 def setIconesFichier(self):
123 if not ( hasattr(self,"BFichier")): return
124 mc = self.node.item.get_definition()
126 if mctype == "Repertoire":
127 self.BRepertoire=self.BFichier
128 self.connect(self.BRepertoire,SIGNAL("clicked()"),self.BRepertoirePressed)
129 self.BVisuFichier.close()
131 self.connect(self.BFichier,SIGNAL("clicked()"),self.BFichierPressed)
132 self.connect(self.BVisuFichier,SIGNAL("clicked()"),self.BFichierVisu)
136 def setIconesGenerales(self):
137 repIcon=self.node.editor.appliEficas.repIcon
138 if hasattr(self,"BVisuListe") :
139 fichier=os.path.join(repIcon, 'plusnode.png')
140 icon = QIcon(fichier)
141 self.BVisuListe.setIcon(icon)
142 if hasattr(self,"RBDeplie") :
143 fichier=os.path.join(repIcon, 'plusnode.png')
144 icon = QIcon(fichier)
145 self.RBDeplie.setIcon(icon)
146 if hasattr(self,"RBPlie") :
147 fichier=os.path.join(repIcon, 'minusnode.png')
148 icon = QIcon(fichier)
149 self.RBPlie.setIcon(icon)
154 if hasattr(self.editor.appliEficas, 'mesScripts'):
155 if hasattr(self.editor,'tree') and self.editor.tree.currentItem().item.get_nom() in self.appliEficas.mesScripts.dict_commandes.keys() :
156 print 'il faut programmer le self.ajoutScript()'
159 if hasattr(self,"RBRun"): self.RBRun.close()
166 #print " c est le moment de gerer le passage au suivant"
167 if not(hasattr (self,'RBValide')) : return
169 if self.node.item.object.isvalid() :
170 icon=QIcon(self.repIcon+"/ast-green-ball.png")
172 icon=QIcon(self.repIcon+"/ast-red-ball.png")
173 self.RBValide.setIcon(icon)
175 # il faut chercher la bonne fenetre
176 def rendVisible(self):
177 #print "je passe par rendVisible de FacultatifOuOptionnel"
179 #print self.node.fenetre
180 #print "return pour etre sure"
183 newNode=self.node.treeParent.chercheNoeudCorrespondant(self.node.item.object)
185 self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(newNode.fenetre)
186 #newNode.fenetre.setFocus()
189 class ContientIcones:
191 def BFichierVisu(self):
192 fichier=self.lineEditVal.text()
193 if fichier == None or str(fichier)=="" : return
194 from monViewTexte import ViewText
196 if sys.platform[0:5]=="linux" :
197 cmd="xdg-open "+ str(fichier)
200 os.startfile(str(fichier))
205 nomFichier=QFileInfo(fichier).baseName()
206 maVue=ViewText(self,entete=nomFichier)
211 QMessageBox.warning( None,
212 tr("Visualisation Fichier "),
213 tr("Impossibilite d'afficher le Fichier"),)
215 def BFichierPressed(self):
216 mctype = self.node.item.get_definition().type
219 elif hasattr(mctype[0], "filters"):
220 filters = mctype[0].filters
223 if len(mctype) > 2 and mctype[2] == "Sauvegarde":
224 fichier = QFileDialog.getSaveFileName(self.appliEficas,
225 tr('Sauvegarder Fichier'),
226 self.appliEficas.CONFIGURATION.savedir,
229 fichier = QFileDialog.getOpenFileName(self.appliEficas,
230 tr('Ouvrir Fichier'),
231 self.appliEficas.CONFIGURATION.savedir,
234 if not(fichier.isNull()):
235 ulfile = os.path.abspath(unicode(fichier))
236 self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
237 self.lineEditVal.setText(fichier)
238 self.editor.affiche_commentaire(tr("Fichier selectionne"))
239 self.LEValeurPressed()
240 if (QFileInfo(fichier).suffix() in listeSuffixe ):
242 if (not hasattr(self,"BSelectInFile")):
243 self.BSelectInFile = QPushButton(self.Widget8)
244 self.BSelectInFile.setMinimumSize(QSize(140,40))
245 self.BSelectInFile.setObjectName("BSelectInFile")
246 self.gridLayout.addWidget(self.BSelectInFile,1,1,1,1)
247 self.BSelectInFile.setText(tr("Selection"))
248 self.connect(self.BSelectInFile,SIGNAL("clicked()"),self.BSelectInFilePressed)
250 self.BSelectInFile.setVisible(1)
251 elif hasattr(self, "BSelectInFile"):
252 self.BSelectInFile.setVisible(0)
254 def BRepertoirePressed(self):
255 directory = QFileDialog.getExistingDirectory(self.appliEficas,
256 directory = self.appliEficas.CONFIGURATION.savedir,
257 options = QFileDialog.ShowDirsOnly)
259 if not directory.isNull():
260 absdir = os.path.abspath(unicode(directory))
261 self.appliEficas.CONFIGURATION.savedir = os.path.dirname(absdir)
262 self.lineEditVal.setText(directory)
263 self.LEValeurPressed()
265 def BSelectInFilePressed(self):
266 from monSelectImage import MonSelectImage
267 MonSelectImage(file=self.image,parent=self).show()
271 def BSalomePressed(self):
272 self.editor.affiche_commentaire(QString(""))
275 genea=self.node.item.get_genealogie()
276 kwType = self.node.item.get_definition().type[0]
278 if "GROUP_NO" in e: kwType = "GROUP_NO"
279 if "GROUP_MA" in e: kwType = "GROUP_MA"
281 if 'grno' in repr(kwType): kwType = "GROUP_NO"
282 if 'grma' in repr(kwType): kwType = "GROUP_NO"
284 if kwType in ("GROUP_NO","GROUP_MA"):
285 selection, commentaire = self.appliEficas.selectGroupFromSalome(kwType,editor=self.editor)
287 mc = self.node.item.get_definition()
289 if (isinstance(mc.type,types.TupleType) and len(mc.type) > 1 and "(*.med)" in mc.type[1] ):
290 selection, commentaire = self.appliEficas.selectMeshFile(editor=self.editor)
291 print selection, commentaire
292 if commentaire != "" :
293 QMessageBox.warning( None,
294 tr("Export Med vers Fichier "),
295 tr("Impossibilite d exporter le Fichier"),)
298 self.lineEditVal.setText(QString(selection))
301 from Accas import SalomeEntry
302 if isinstance(kwType, types.ClassType) and issubclass(kwType, SalomeEntry):
303 selection, commentaire = self.appliEficas.selectEntryFromSalome(kwType,editor=self.editor)
305 if commentaire !="" :
306 self.editor.affiche_infos(QString(tr(str(commentaire))))
308 if selection == [] : return
309 for geomElt in selection:
311 monTexte= monTexte[0:-1]
312 self.lineEditVal.setText(QString(monTexte))
313 self.LEValeurPressed()
315 def BView2DPressed(self):
316 valeur=self.lineEditVal.text()
317 if valeur == QString("") : return
320 ok, msgError = self.appliEficas.displayShape(valeur)
322 self.editor.affiche_infos(msgError,Qt.red)
324 def BParametresPressed(self):
325 liste=self.node.item.get_liste_param_possible()
326 from monListeParamPanel import MonListeParamPanel
327 MonListeParamPanel(liste=liste,parent=self).show()