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()
41 else : self.connect( self.RBRegle,SIGNAL("clicked()"),self.viewRegles)
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()
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)
54 def chercheDocMAP(self):
56 clef=self.editor.CONFIGURATION.adresse+"/"
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]:
63 clef+="/"+ self.obj.nom[0:-5].lower()+"/spec_"+self.obj.nom[0:-5].lower()+".html"
69 if sys.platform[0:5]=="linux" : cmd="xdg-open "+self.cle_doc
70 else : cmd="start "+self.cle_doc
73 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
76 self.node.AppelleBuildLBRegles()
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)
85 icon=QIcon(self.repIcon+"/deleteRond.png")
86 self.RBPoubelle.setIcon(icon)
87 self.connect(self.RBPoubelle,SIGNAL("clicked()"),self.aDetruire)
89 def setIconesSalome(self):
90 if not (hasattr(self,"RBSalome")): return
91 from Accas import SalomeEntry
92 mc = self.node.item.get_definition()
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))
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)
103 if not(('grma' in repr(mctype)) or ('grno' in repr(mctype))) or not(self.editor.salome):
106 icon1=QIcon(self.repIcon+"/eye.png")
107 self.RBSalomeVue.setIcon(icon1)
108 self.connect(self.RBSalomeVue,SIGNAL("clicked()"),self.BView2DPressed)
110 self.RBSalome.close()
111 self.RBSalomeVue.close()
114 def setIconesFichier(self):
115 if not ( hasattr(self,"BFichier")): return
116 mc = self.node.item.get_definition()
118 if mctype == "Repertoire":
119 self.BRepertoire=self.BFichier
120 self.connect(self.BRepertoire,SIGNAL("clicked()"),self.BRepertoirePressed)
121 self.BVisuFichier.close()
123 self.connect(self.BFichier,SIGNAL("clicked()"),self.BFichierPressed)
124 self.connect(self.BVisuFichier,SIGNAL("clicked()"),self.BFichierVisu)
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)
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()'
143 if hasattr(self,"RBRun"): self.RBRun.close()
150 #print " c est le moment de gerer le passage au suivant"
151 if not(hasattr (self,'RBValide')) : return
153 if self.node.item.object.isvalid() :
154 icon=QIcon(self.repIcon+"/ast-green-ball.png")
156 icon=QIcon(self.repIcon+"/ast-red-ball.png")
157 self.RBValide.setIcon(icon)
159 # il faut chercher la bonne fenetre
160 def rendVisible(self):
161 #print "je passe par rendVisible de FacultatifOuOptionnel"
163 #print self.node.fenetre
164 #print "return pour etre sure"
167 newNode=self.node.treeParent.chercheNoeudCorrespondant(self.node.item.object)
169 self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(newNode.fenetre)
170 #newNode.fenetre.setFocus()
173 class ContientIcones:
175 def BFichierVisu(self):
176 fichier=self.lineEditVal.text()
177 if fichier == None or str(fichier)=="" : return
178 from monViewTexte import ViewText
180 if sys.platform[0:5]=="linux" :
181 cmd="xdg-open "+ str(fichier)
184 os.startfile(str(fichier))
189 nomFichier=QFileInfo(fichier).baseName()
190 maVue=ViewText(self,entete=nomFichier)
195 QMessageBox.warning( None,
196 tr("Visualisation Fichier "),
197 tr("Impossibilite d'afficher le Fichier"),)
199 def BFichierPressed(self):
200 mctype = self.node.item.get_definition().type
203 elif hasattr(mctype[0], "filters"):
204 filters = mctype[0].filters
207 if len(mctype) > 2 and mctype[2] == "Sauvegarde":
208 fichier = QFileDialog.getSaveFileName(self.appliEficas,
209 tr('Sauvegarder Fichier'),
210 self.appliEficas.CONFIGURATION.savedir,
213 fichier = QFileDialog.getOpenFileName(self.appliEficas,
214 tr('Ouvrir Fichier'),
215 self.appliEficas.CONFIGURATION.savedir,
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 ):
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)
234 self.BSelectInFile.setVisible(1)
235 elif hasattr(self, "BSelectInFile"):
236 self.BSelectInFile.setVisible(0)
238 def BRepertoirePressed(self):
239 directory = QFileDialog.getExistingDirectory(self.appliEficas,
240 directory = self.appliEficas.CONFIGURATION.savedir,
241 options = QFileDialog.ShowDirsOnly)
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()
249 def BSelectInFilePressed(self):
250 from monSelectImage import MonSelectImage
251 MonSelectImage(file=self.image,parent=self).show()
255 def BSalomePressed(self):
256 self.editor.affiche_commentaire(QString(""))
259 genea=self.node.item.get_genealogie()
260 kwType = self.node.item.get_definition().type[0]
262 if "GROUP_NO" in e: kwType = "GROUP_NO"
263 if "GROUP_MA" in e: kwType = "GROUP_MA"
265 if 'grno' in repr(kwType): kwType = "GROUP_NO"
266 if 'grma' in repr(kwType): kwType = "GROUP_NO"
268 if kwType in ("GROUP_NO","GROUP_MA"):
269 selection, commentaire = self.appliEficas.selectGroupFromSalome(kwType,editor=self.editor)
271 mc = self.node.item.get_definition()
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"),)
282 self.lineEditVal.setText(QString(selection))
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)
289 if commentaire !="" :
290 self.editor.affiche_infos(tr(QString(commentaire)))
292 if selection == [] : return
293 for geomElt in selection:
295 monTexte= monTexte[0:-1]
296 self.lineEditVal.setText(QString(monTexte))
298 def BView2DPressed(self):
299 valeur=self.lineEditVal.text()
300 if valeur == QString("") : return
303 ok, msgError = self.appliEficas.displayShape(valeur)
305 self.editor.affiche_infos(msgError,Qt.red)
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()