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 if not(('grma' in repr(mctype)) or ('grno' in repr(mctype))) or not(self.editor.salome):
112 icon1=QIcon(self.repIcon+"/eye.png")
113 self.RBSalomeVue.setIcon(icon1)
114 self.connect(self.RBSalomeVue,SIGNAL("clicked()"),self.BView2DPressed)
116 self.RBSalome.close()
117 self.RBSalomeVue.close()
120 def setIconesFichier(self):
121 if not ( hasattr(self,"BFichier")): return
122 mc = self.node.item.get_definition()
124 if mctype == "Repertoire":
125 self.BRepertoire=self.BFichier
126 self.connect(self.BRepertoire,SIGNAL("clicked()"),self.BRepertoirePressed)
127 self.BVisuFichier.close()
129 self.connect(self.BFichier,SIGNAL("clicked()"),self.BFichierPressed)
130 self.connect(self.BVisuFichier,SIGNAL("clicked()"),self.BFichierVisu)
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)
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()'
157 if hasattr(self,"RBRun"): self.RBRun.close()
164 #print " c est le moment de gerer le passage au suivant"
165 if not(hasattr (self,'RBValide')) : return
167 if self.node.item.object.isvalid() :
168 icon=QIcon(self.repIcon+"/ast-green-ball.png")
170 icon=QIcon(self.repIcon+"/ast-red-ball.png")
171 print "lllllllllllllllllllllllllllllllll"
172 self.RBValide.setIcon(icon)
174 # il faut chercher la bonne fenetre
175 def rendVisible(self):
176 #print "je passe par rendVisible de FacultatifOuOptionnel"
178 #print self.node.fenetre
179 #print "return pour etre sure"
182 newNode=self.node.treeParent.chercheNoeudCorrespondant(self.node.item.object)
184 self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(newNode.fenetre)
185 #newNode.fenetre.setFocus()
188 class ContientIcones:
190 def BFichierVisu(self):
191 fichier=self.lineEditVal.text()
192 if fichier == None or str(fichier)=="" : return
193 from monViewTexte import ViewText
195 if sys.platform[0:5]=="linux" :
196 cmd="xdg-open "+ str(fichier)
199 os.startfile(str(fichier))
204 nomFichier=QFileInfo(fichier).baseName()
205 maVue=ViewText(self,entete=nomFichier)
210 QMessageBox.warning( None,
211 tr("Visualisation Fichier "),
212 tr("Impossibilite d'afficher le Fichier"),)
214 def BFichierPressed(self):
215 mctype = self.node.item.get_definition().type
218 elif hasattr(mctype[0], "filters"):
219 filters = mctype[0].filters
222 if len(mctype) > 2 and mctype[2] == "Sauvegarde":
223 fichier = QFileDialog.getSaveFileName(self.appliEficas,
224 tr('Sauvegarder Fichier'),
225 self.appliEficas.CONFIGURATION.savedir,
228 fichier = QFileDialog.getOpenFileName(self.appliEficas,
229 tr('Ouvrir Fichier'),
230 self.appliEficas.CONFIGURATION.savedir,
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 ):
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)
249 self.BSelectInFile.setVisible(1)
250 elif hasattr(self, "BSelectInFile"):
251 self.BSelectInFile.setVisible(0)
253 def BRepertoirePressed(self):
254 directory = QFileDialog.getExistingDirectory(self.appliEficas,
255 directory = self.appliEficas.CONFIGURATION.savedir,
256 options = QFileDialog.ShowDirsOnly)
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()
264 def BSelectInFilePressed(self):
265 from monSelectImage import MonSelectImage
266 MonSelectImage(file=self.image,parent=self).show()
270 def BSalomePressed(self):
271 self.editor.affiche_commentaire(QString(""))
274 genea=self.node.item.get_genealogie()
275 kwType = self.node.item.get_definition().type[0]
277 if "GROUP_NO" in e: kwType = "GROUP_NO"
278 if "GROUP_MA" in e: kwType = "GROUP_MA"
280 if 'grno' in repr(kwType): kwType = "GROUP_NO"
281 if 'grma' in repr(kwType): kwType = "GROUP_NO"
283 if kwType in ("GROUP_NO","GROUP_MA"):
284 selection, commentaire = self.appliEficas.selectGroupFromSalome(kwType,editor=self.editor)
286 mc = self.node.item.get_definition()
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"),)
297 self.lineEditVal.setText(QString(selection))
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)
304 if commentaire !="" :
305 self.editor.affiche_infos(tr(QString(commentaire)))
307 if selection == [] : return
308 for geomElt in selection:
310 monTexte= monTexte[0:-1]
311 self.lineEditVal.setText(QString(monTexte))
313 def BView2DPressed(self):
314 valeur=self.lineEditVal.text()
315 if valeur == QString("") : return
318 ok, msgError = self.appliEficas.displayShape(valeur)
320 self.editor.affiche_infos(msgError,Qt.red)
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()