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
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):
34 from monWidgetCommande import MonWidgetCommande
37 listeRegles = self.node.item.get_regles()
40 if listeRegles==() and hasattr(self,"RBRegle"): self.RBRegle.close()
42 if not hasattr(self,"RBInfo"):return
43 if isinstance(self,MonWidgetCommande) and self.editor.code =="MAP":
44 self.cle_doc = self.chercheDocMAP()
46 self.cle_doc = self.node.item.get_docu()
47 if self.cle_doc == None : self.RBInfo.close()
48 else : self.connect (self.RBInfo,SIGNAL("clicked()"),self.viewDoc)
51 def chercheDocMAP(self):
53 clef=self.editor.CONFIGURATION.adresse+"/"
56 for k in self.editor.readercata.cata[0].JdC.dict_groupes.keys():
57 if self.obj.nom in self.editor.readercata.cata[0].JdC.dict_groupes[k]:
60 clef+="/"+ self.obj.nom[0:-5].lower()+"/spec_"+self.obj.nom[0:-5].lower()+".html"
66 cmd="xdg-open "+self.cle_doc
69 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
72 def setIconePoubelle(self):
73 if not(hasattr(self,"RBPoubelle")):return
75 repIcon=os.path.join(os.path.abspath(os.path.dirname(__file__)),'../Editeur/icons')
76 if self.node.item.object.isoblig() :
77 icon1.addPixmap(QtGui.QPixmap(repIcon+"/deleteRondVide.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
78 self.RBPoubelle.setIcon(icon1)
80 icon1.addPixmap(QtGui.QPixmap(repIcon+"/deleteRond.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
81 self.RBPoubelle.show()
82 self.connect(self.RBPoubelle,SIGNAL("clicked()"),self.aDetruire)
84 def setIconesSalome(self):
85 if not (hasattr(self,"RBSalome")): return
86 from Accas import SalomeEntry
87 mc = self.node.item.get_definition()
89 enable_salome_selection = self.editor.salome and \
90 (('grma' in repr(mctype)) or ('grno' in repr(mctype)) or ('SalomeEntry' in repr(mctype)) or \
91 (hasattr(mctype, "enable_salome_selection") and mctype.enable_salome_selection))
92 if enable_salome_selection:
93 self.connect(self.RBSalome,SIGNAL("pressed()"),self.BSalomePressed)
94 if not(('grma' in repr(mctype)) or ('grno' in repr(mctype))) or not(self.editor.salome): self.BView2D.close()
95 else : self.connect(self.RBSalomeVue,SIGNAL("clicked()"),self.BView2DPressed)
98 self.RBSalomeVue.close()
101 def setIconesFichier(self):
102 if not ( hasattr(self,"BFichier")): return
103 mc = self.node.item.get_definition()
105 if mctype == "Repertoire":
106 self.BRepertoire=self.BFichier
107 self.connect(self.BRepertoire,SIGNAL("clicked()"),self.BRepertoirePressed)
108 self.BVisuFichier.close()
110 self.connect(self.BFichier,SIGNAL("clicked()"),self.BFichierPressed)
111 self.connect(self.BVisuFichier,SIGNAL("clicked()"),self.BFichierVisu)
117 if hasattr(self.editor.appliEficas, 'mesScripts'):
118 if self.tree.currentItem().item.get_nom() in self.appliEficas.mesScripts.dict_commandes.keys() :
119 print 'il faut programmer le self.ajoutScript()'
122 if hasattr(self,"RBRun"): self.RBRun.close()
129 #print " c est le moment de gerer le passage au suivant"
130 if not(hasattr (self,'RBValide')) : return
132 repIcon=os.path.join(os.path.abspath(os.path.dirname(__file__)),'../Editeur/icons')
133 if self.node.item.object.isvalid() :
134 icon=QIcon(repIcon+"/ast-green-ball.png")
136 icon=QIcon(repIcon+"/ast-red-ball.png")
137 self.RBValide.setIcon(icon)
139 # il faut chercher la bonne fenetre
140 def rendVisible(self):
141 #print "je passe par rendVisible de FacultatifOuOptionnel"
143 #print self.node.fenetre
144 #print "return pour etre sure"
147 newNode=self.node.treeParent.chercheNoeudCorrespondant(self.node.item.object)
149 self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(newNode.fenetre)
150 #newNode.fenetre.setFocus()
153 class ContientIcones:
155 def BFichierVisu(self):
156 fichier=self.lineEditVal.text()
157 if fichier == None or str(fichier)=="" : return
158 from qtCommun import ViewText
160 cmd="xdg-open "+str(fichier)
166 nomFichier=QFileInfo(fichier).baseName()
167 maVue=ViewText(self,entete=nomFichier)
172 QMessageBox.warning( None,
173 tr("Visualisation Fichier "),
174 tr("Impossibilite d'afficher le Fichier"),)
176 def BFichierPressed(self):
177 mctype = self.node.item.get_definition().type
180 elif hasattr(mctype[0], "filters"):
181 filters = mctype[0].filters
184 if len(mctype) > 2 and mctype[2] == "Sauvegarde":
185 fichier = QFileDialog.getSaveFileName(self.appliEficas,
186 tr('Sauvegarder Fichier'),
187 self.appliEficas.CONFIGURATION.savedir,
190 fichier = QFileDialog.getOpenFileName(self.appliEficas,
191 tr('Ouvrir Fichier'),
192 self.appliEficas.CONFIGURATION.savedir,
195 if not(fichier.isNull()):
196 ulfile = os.path.abspath(unicode(fichier))
197 self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
198 self.lineEditVal.setText(fichier)
199 self.editor.affiche_infos(tr("Fichier selectionne"))
200 self.LEValeurPressed()
201 if (QFileInfo(fichier).suffix() in listeSuffixe ):
203 if (not hasattr(self,"BSelectInFile")):
204 self.BSelectInFile = QPushButton(self.Widget8)
205 self.BSelectInFile.setMinimumSize(QSize(140,40))
206 self.BSelectInFile.setObjectName("BSelectInFile")
207 self.gridLayout.addWidget(self.BSelectInFile,1,1,1,1)
208 self.BSelectInFile.setText(tr("Selection"))
209 self.connect(self.BSelectInFile,SIGNAL("clicked()"),self.BSelectInFilePressed)
211 self.BSelectInFile.setVisible(1)
212 elif hasattr(self, "BSelectInFile"):
213 self.BSelectInFile.setVisible(0)
215 def BRepertoirePressed(self):
216 directory = QFileDialog.getExistingDirectory(self.appliEficas,
217 directory = self.appliEficas.CONFIGURATION.savedir,
218 options = QFileDialog.ShowDirsOnly)
220 if not directory.isNull():
221 absdir = os.path.abspath(unicode(directory))
222 self.appliEficas.CONFIGURATION.savedir = os.path.dirname(absdir)
223 self.lineEditVal.setText(directory)
224 self.LEValeurPressed()
226 def BSelectInFilePressed(self):
227 from monSelectImage import MonSelectImage
228 MonSelectImage(file=self.image,parent=self).show()
232 def BSalomePressed(self):
233 self.editor.affiche_infos(QString(""))
236 genea=self.node.item.get_genealogie()
237 kwType = self.node.item.get_definition().type[0]
239 if "GROUP_NO" in e: kwType = "GROUP_NO"
240 if "GROUP_MA" in e: kwType = "GROUP_MA"
242 if 'grno' in repr(kwType): kwType = "GROUP_NO"
243 if 'grma' in repr(kwType): kwType = "GROUP_NO"
245 if kwType in ("GROUP_NO","GROUP_MA"):
246 selection, commentaire = self.appliEficas.selectGroupFromSalome(kwType,editor=self.editor)
248 mc = self.node.item.get_definition()
250 if (isinstance(mc.type,types.TupleType) and len(mc.type) > 1 and "(*.med)" in mc.type[1] ):
251 selection, commentaire = self.appliEficas.selectMeshFile(editor=self.editor)
252 print selection, commentaire
253 if commentaire != "" :
254 QMessageBox.warning( None,
255 tr("Export Med vers Fichier "),
256 tr("Impossibilite d exporter le Fichier"),)
259 self.lineEditVal.setText(QString(selection))
262 from Accas import SalomeEntry
263 if isinstance(kwType, types.ClassType) and issubclass(kwType, SalomeEntry):
264 selection, commentaire = self.appliEficas.selectEntryFromSalome(kwType,editor=self.editor)
266 if commentaire !="" :
267 self.editor.affiche_infos(tr(QString(commentaire)))
269 if selection == [] : return
270 for geomElt in selection:
272 monTexte= monTexte[0:-1]
273 self.lineEditVal.setText(QString(monTexte))
275 def BView2DPressed(self):
276 valeur=self.lineEditVal.text()
277 if valeur == QString("") : return
280 ok, msgError = self.appliEficas.displayShape(valeur)
282 self.appliEficas.affiche_infos(msgError,Qt.red)
284 def BParametresPressed(self):
285 liste=self.node.item.get_liste_param_possible()
286 from monListeParamPanel import MonListeParamPanel
287 MonListeParamPanel(liste=liste,parent=self).show()