1 # -*- coding: iso-8859-1 -*-
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
23 from PyQt4.QtGui import *
24 from PyQt4.QtCore import *
25 from myMain import Ui_Eficas
26 from viewManager import MyTabview
27 from getVersion import getEficasVersion
29 from Extensions.i18n import tr
30 from Extensions.eficas_exception import EficasException
32 from Editeur import session
35 class Appli(Ui_Eficas,QMainWindow):
37 Class implementing the main user interface.
39 def __init__(self,code=None,salome=0,parent=None,ssCode=None,multi=False,langue='fr',ssIhm=False):
43 QMainWindow.__init__(self,parent)
44 Ui_Eficas.__init__(self)
46 self.myQtab.removeTab(0)
47 self.blEntete= QBoxLayout(0,self.frameEntete)
48 self.blEntete.insertWidget(0,self.toolBar)
49 self.blEntete.insertWidget(0,self.menubar)
52 version=getEficasVersion()
53 self.VERSION_EFICAS="Eficas QT4 "+version
57 self.top = self #(pour CONFIGURATION)
58 self.QWParent=None #(Pour lancement sans IHM)
62 self.recent = QStringList()
65 self.ListeCode=['Aster','Carmel3D','Cuve2dg','Openturns_Study','Openturns_Wrapper','MAP','ZCracks', 'CarmelCND','MT']
66 self.repIcon=os.path.join( os.path.dirname(os.path.abspath(__file__)),'../Editeur/icons')
71 Accas.SalomeEntry = eficasSalome.SalomeEntry
75 if langue=='fr': self.langue=langue
76 else : self.langue="ang"
77 if self.multi == False :
78 self.definitCode(code,ssCode)
81 eficas_root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
83 self.viewmanager = MyTabview(self)
84 self.recentMenu=self.menuFichier.addMenu(tr('&Recents'))
85 self.connecterSignaux()
86 self.toolBar.addSeparator()
87 if self.code != None : self.construitMenu()
90 self.setWindowTitle(self.VERSION_EFICAS)
95 def definitCode(self,code,ssCode) :
100 from monChoixCode import MonChoixCode
101 widgetChoix = MonChoixCode(self)
102 ret=widgetChoix.exec_()
104 if self.code == None:return # pour le cancel de la fenetre choix code
105 name='prefs_'+self.code
106 prefsCode=__import__(name)
108 self.repIni=prefsCode.repIni
110 self.format_fichier= ssCode #par defaut
111 prefsCode.NAME_SCHEME=ssCode
113 self.format_fichier="python" #par defaut
115 nameConf='configuration_'+self.code
116 configuration=__import__(nameConf)
117 self.CONFIGURATION = configuration.make_config(self,prefsCode.repIni)
118 self.CONFIGStyle = None
119 if hasattr(configuration,'make_config_style'):
120 self.CONFIGStyle = configuration.make_config_style(self,prefsCode.repIni)
121 if hasattr(prefsCode,'encoding'):
124 sys.setdefaultencoding(prefsCode.encoding)
126 def construitMenu(self):
130 for intituleMenu in ("menuTraduction","menuOptions","menuMesh","menuExecution"):
131 if hasattr(self,intituleMenu):
132 menu=getattr(self,intituleMenu)
133 menu.setAttribute(Qt.WA_DeleteOnClose)
135 delattr(self,intituleMenu)
136 for intituleAction in ("actionExecution","actionSaveRun",):
137 if hasattr(self,intituleAction):
138 action=getattr(self,intituleAction)
139 self.toolBar.removeAction(action)
140 if self.code in Appli.__dict__.keys():
141 listeTexte=apply(Appli.__dict__[self.code],(self,))
145 repAide=os.path.dirname(os.path.abspath(__file__))
146 fileName='index.html'
147 self.docPath=repAide+"/../Aide"
148 if hasattr(self,'CONFIGURATION') and hasattr(self.CONFIGURATION,'docPath') : self.docPath=self.CONFIGURATION.docPath
149 if hasattr(self,'CONFIGURATION') and hasattr(self.CONFIGURATION,'fileName'):fileName=self.CONFIGURATION.fileName
150 self.fileDoc=os.path.join(self.docPath,fileName)
151 self.actionCode.setText(tr("Aide specifique ")+str(self.code))
152 if not os.path.isfile(self.fileDoc) :
155 self.actionCode.setEnabled(False)
158 self.actionCode.setEnabled(True)
159 self.menuAide.addAction(self.actionCode)
162 def ajoutExecution(self):
163 self.menuExecution = self.menubar.addMenu(QApplication.translate("Eficas", "Execution", None, QApplication.UnicodeUTF8))
164 self.actionExecution = QAction(self)
165 icon6 = QIcon(self.repIcon+"/roue.png")
166 self.actionExecution.setIcon(icon6)
167 self.actionExecution.setObjectName("actionExecution")
168 self.menuExecution.addAction(self.actionExecution)
169 if not(self.actionExecution in self.toolBar.actions()):
170 self.toolBar.addAction(self.actionExecution)
171 self.actionExecution.setText(QApplication.translate("Eficas", "Execution ", None, QApplication.UnicodeUTF8))
172 self.connect(self.actionExecution,SIGNAL("activated()"),self.run)
174 def ajoutSauveExecution(self):
175 self.actionSaveRun = QAction(self)
176 icon7 = QIcon(self.repIcon+"/export_MAP.png")
177 self.actionSaveRun.setIcon(icon7)
178 self.actionSaveRun.setObjectName("actionSaveRun")
179 self.menuExecution.addAction(self.actionSaveRun)
180 if not(self.actionSaveRun in self.toolBar.actions()):
181 self.toolBar.addAction(self.actionSaveRun)
182 self.actionSaveRun.setText(QApplication.translate("Eficas", "Save Run", None, QApplication.UnicodeUTF8))
183 self.connect(self.actionSaveRun,SIGNAL("activated()"),self.saveRun)
185 def griserActionsStructures(self):
186 self.actionCouper.setEnabled(False)
187 self.actionColler.setEnabled(False)
188 self.actionCopier.setEnabled(False)
189 self.actionSupprimer.setEnabled(False)
191 def enleverNewInclude(self):
192 self.actionNouvel_Include.setVisible(False)
194 def enleverRechercherDsCatalogue(self):
195 self.actionRechercherDsCatalogue.setVisible(False)
198 self.enleverNewInclude()
199 self.toolBar.addSeparator()
200 self.ajoutExecution()
202 self.menuOptions = self.menubar.addMenu("menuOptions")
203 self.menuOptions.addAction(self.actionParametres_Eficas)
204 self.menuOptions.setTitle(tr("Options"))
207 self.griserActionsStructures()
208 self.enleverNewInclude()
209 self.enleverRechercherDsCatalogue()
212 self.menuTraduction = self.menubar.addMenu("menuTraduction")
213 self.menuTraduction.addAction(self.actionTraduitV7V8)
214 self.menuTraduction.addAction(self.actionTraduitV8V9)
215 self.menuTraduction.addAction(self.actionTraduitV9V10)
216 self.menuTraduction.setTitle(tr("Traduction"))
218 self.menuOptions = self.menubar.addMenu("menuOptions")
219 self.menuOptions.addAction(self.actionParametres_Eficas)
220 self.menuOptions.addAction(self.actionLecteur_Pdf)
221 self.menuOptions.setTitle(tr("Options"))
224 #if self.salome == 0 : return
225 self.enleverNewInclude()
226 self.menuMesh = self.menubar.addMenu("menuMesh")
227 self.menuMesh.setObjectName("Mesh")
228 self.menuMesh.addAction(self.actionChercheGrpMaille)
229 self.griserActionsStructures()
232 self.enleverNewInclude()
233 self.enleverRechercherDsCatalogue()
234 self.ajoutExecution()
235 self.ajoutSauveExecution()
236 self.griserActionsStructures()
239 self.enleverNewInclude()
240 self.toolBar.addSeparator()
241 self.ajoutExecution()
242 self.ajoutSauveExecution()
243 self.menuOptions = self.menubar.addMenu("menuOptions")
244 self.menuOptions.addAction(self.actionParametres_Eficas)
245 self.menuOptions.setTitle(tr("Options"))
248 def ChercheGrpMesh(self):
249 Msg,listeGroup=self.ChercheGrpMeshInSalome()
251 self.viewmanager.handleAjoutGroup(listeGroup)
253 print "il faut gerer les erreurs"
255 def ChercheGrpMaille(self):
256 Msg,listeGroup=self.ChercheGrpMailleInSalome()
258 self.viewmanager.handleAjoutGroup(listeGroup)
260 print "il faut gerer les erreurs"
262 def ChercheGrp(self):
263 #Msg,listeGroup=self.ChercheGrpMailleInSalome()
265 # self.viewmanager.handleAjoutGroup(listeGroup)
267 print "il faut gerer "
270 def ajoutIcones(self) :
271 # Pour pallier les soucis de repertoire d icone
272 icon = QIcon(self.repIcon+"/New24.png")
273 self.action_Nouveau.setIcon(icon)
274 icon1 = QIcon(self.repIcon+"/Open24.png")
275 self.action_Ouvrir.setIcon(icon1)
276 icon2 = QIcon(self.repIcon+"/Save24.png")
277 self.actionEnregistrer.setIcon(icon2)
278 icon3 = QIcon(self.repIcon+"/Cut24.png")
279 self.actionCouper.setIcon(icon3)
280 icon4 = QIcon(self.repIcon+"/Copy24.png")
281 self.actionCopier.setIcon(icon4)
282 icon5 = QIcon(self.repIcon+"/Paste24.png")
283 self.actionColler.setIcon(icon5)
284 icon6 = QIcon(self.repIcon+"/Delete24.png")
285 self.actionSupprimer.setIcon(icon6)
289 def connecterSignaux(self) :
290 self.connect(self.recentMenu,SIGNAL('aboutToShow()'),self.handleShowRecentMenu)
292 self.connect(self.action_Nouveau,SIGNAL("activated()"),self.fileNew)
293 self.connect(self.actionNouvel_Include,SIGNAL("activated()"),self.NewInclude)
294 self.connect(self.action_Ouvrir,SIGNAL("activated()"),self.fileOpen)
295 self.connect(self.actionEnregistrer,SIGNAL("activated()"),self.fileSave)
296 self.connect(self.actionEnregistrer_sous,SIGNAL("activated()"),self.fileSaveAs)
297 self.connect(self.actionFermer,SIGNAL("activated()"),self.fileClose)
298 self.connect(self.actionFermer_tout,SIGNAL("activated()"),self.fileCloseAll)
299 self.connect(self.actionQuitter,SIGNAL("activated()"),self.fileExit)
301 self.connect(self.actionEficas,SIGNAL("activated()"),self.aidePPal)
302 self.connect(self.actionVersion,SIGNAL("activated()"),self.version)
303 self.connect(self.actionParametres,SIGNAL("activated()"),self.gestionParam)
305 self.connect(self.actionCouper,SIGNAL("activated()"),self.editCut)
306 self.connect(self.actionCopier,SIGNAL("activated()"),self.editCopy)
307 self.connect(self.actionColler,SIGNAL("activated()"),self.editPaste)
308 self.connect(self.actionSupprimer,SIGNAL("activated()"),self.supprimer)
309 self.connect(self.actionRechercher,SIGNAL("activated()"),self.rechercher)
310 self.connect(self.actionDeplier_replier,SIGNAL("activated()"),self.Deplier)
312 self.connect(self.actionRapport_de_Validation,SIGNAL("activated()"),self.jdcRapport)
313 self.connect(self.actionFichier_Source,SIGNAL("activated()"),self.jdcFichierSource)
314 self.connect(self.actionFichier_Resultat,SIGNAL("activated()"),self.visuJdcPy)
317 #self.connect(self.helpIndexAction,SIGNAL("activated()"),self.helpIndex)
318 #self.connect(self.helpContentsAction,SIGNAL("activated()"),self.helpContents)
321 self.actionTraduitV7V8 = QAction(self)
322 self.actionTraduitV7V8.setObjectName("actionTraduitV7V8")
323 self.actionTraduitV8V9 = QAction(self)
324 self.actionTraduitV8V9.setObjectName("actionTraduitV8V9")
325 self.actionTraduitV9V10 = QAction(self)
326 self.actionTraduitV9V10.setObjectName("actionTraduitV9V10")
327 self.actionTraduitV7V8.setText(tr("TraduitV7V8"))
328 self.actionTraduitV8V9.setText(tr("TraduitV8V9"))
329 self.actionTraduitV9V10.setText(tr("TraduitV9V10"))
330 self.connect(self.actionParametres_Eficas,SIGNAL("activated()"),self.optionEditeur)
331 self.connect(self.actionLecteur_Pdf,SIGNAL("activated()"),self.optionPdf)
332 self.connect(self.actionTraduitV7V8,SIGNAL("activated()"),self.traductionV7V8)
333 self.connect(self.actionTraduitV8V9,SIGNAL("activated()"),self.traductionV8V9)
334 self.connect(self.actionTraduitV9V10,SIGNAL("activated()"),self.traductionV9V10)
337 self.actionChercheGrpMaille = QAction(self)
338 self.actionChercheGrpMaille.setText(tr("Acquiert Groupe Maille"))
339 self.connect(self.actionChercheGrpMaille,SIGNAL("activated()"),self.ChercheGrpMaille)
342 self.actionChercheGrp = QAction(self)
343 self.actionChercheGrp.setText(tr("Accquisition Groupe Maille"))
344 self.connect(self.actionChercheGrp,SIGNAL("activated()"),self.ChercheGrp)
347 self.actionCode = QAction(self)
348 self.actionCode.setText(tr("Specificites Maille"))
349 self.connect(self.actionCode,SIGNAL("activated()"),self.aideCode)
352 self.viewmanager.handleDeplier()
354 def ouvreFichiers(self) :
355 # Ouverture des fichiers de commandes donnes sur la ligne de commande
358 for study in session.d_env.studies:
360 d=session.get_unit(study,self)
361 self.viewmanager.handleOpen(fichier=study["comm"],units=d)
364 def get_source(self,file):
365 # appele par Editeur/session.py
367 p=convert.plugins['python']()
369 texte=p.convert('execnoparseur')
372 def initPatrons(self) :
373 # Mise a jour du menu des fichiers recemment ouverts
374 from Editeur import listePatrons
375 if not(self.code in listePatrons.sous_menus.keys()) :
376 if hasattr(self,"menuPatrons"):
377 self.menuPatrons.setAttribute(Qt.WA_DeleteOnClose)
378 self.menuPatrons.close()
379 delattr(self,"menuPatrons")
381 if (not hasattr(self,"menuPatrons")):
382 self.menuPatrons = QMenu(self.menubar)
383 self.menuPatrons.setObjectName("menuPatrons")
384 self.menubar.addAction(self.menuPatrons.menuAction())
385 self.menuPatrons.setTitle(QApplication.translate("Eficas", "Patrons", None, QApplication.UnicodeUTF8))
387 self.menuPatrons.clear()
388 self.listePatrons = listePatrons.listePatrons(self.code)
390 for nomSsMenu in self.listePatrons.liste.keys():
391 ssmenu=self.menuPatrons.addMenu(nomSsMenu)
392 for fichier in self.listePatrons.liste[nomSsMenu]:
393 id = ssmenu.addAction(fichier)
394 self.ficPatrons[id]=fichier
395 self.connect(id, SIGNAL('triggered()'),self.handleOpenPatrons)
396 # self.Patrons.setItemParameter(id,idx)
399 def initRecents(self):
400 self.recent = QStringList()
403 rep=os.path.join(os.environ['HOME'],'.config/Eficas',self.code)
404 monFichier=rep+"/listefichiers_"+self.code
410 l=(ligne.split("\n"))[0]
411 self.recent.append(l)
420 def addToRecentList(self, fn):
422 Public slot to add a filename to the list of recently opened files.
424 @param fn name of the file to be added
426 self.recent.removeAll(fn)
427 self.recent.prepend(fn)
428 if len(self.recent) > 9:
429 self.recent = self.recent[:9]
431 def sauveRecents(self) :
433 rep=self.CONFIGURATION.rep_user
434 monFichier=rep+"/listefichiers_"+self.code
438 f=open(monFichier,'w')
439 if len(self.recent) == 0 : return
441 while ( index < len(self.recent)):
442 ligne=str(self.recent[index])+"\n"
454 def traductionV7V8(self):
455 from gereTraduction import traduction
456 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V7V8")
458 def traductionV8V9(self):
459 from gereTraduction import traduction
460 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V8V9")
462 def traductionV9V10(self):
463 from gereTraduction import traduction
464 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V9V10")
467 from monVisu import DVisu
468 titre = tr("version ")
469 monVisuDialg=DVisu(parent=self,fl=0)
470 monVisuDialg.setWindowTitle(titre)
471 monVisuDialg.TB.setText(self.VERSION_EFICAS +tr(" pour ") + self.code)
472 monVisuDialg.adjustSize()
476 if self.code==None : return
477 repAide=os.path.dirname(os.path.abspath(__file__))
478 maD=repAide+"/../Aide"
480 indexAide=maD+"/fichiers_EFICAS/index.html"
481 cmd="xdg-open "+indexAide
484 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
488 if self.code==None : return
491 cmd="xdg-open "+self.fileDoc
495 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
498 def optionEditeur(self) :
500 name='monOptions_'+self.code
502 QMessageBox.critical( self,tr( "Parametrage"),tr( "Veuillez d abord choisir un code"))
506 optionCode=__import__(name)
509 QMessageBox.critical( self, tr("Parametrage"), tr("Pas de possibilite de personnalisation de la configuration "))
511 monOption=optionCode.Options(parent=self,modal = 0 ,configuration=self.CONFIGURATION)
514 def optionPdf(self) :
515 from monOptionsPdf import OptionPdf
516 monOption=OptionPdf(parent=self,modal = 0 ,configuration=self.CONFIGURATION)
519 def handleShowRecentMenu(self):
521 Private method to set up recent files menu.
523 self.recentMenu.clear()
525 for rp in self.recent:
526 id = self.recentMenu.addAction(rp)
527 self.ficRecents[id]=rp
528 self.connect(id, SIGNAL('triggered()'),self.handleOpenRecent)
529 self.recentMenu.addSeparator()
530 self.recentMenu.addAction(tr('&Effacer'), self.handleClearRecent)
532 def handleOpenPatrons(self):
534 fichier=self.repIni+"/../Editeur/Patrons/"+self.code+"/"+self.ficPatrons[idx]
535 self.viewmanager.handleOpen(fichier=fichier, patron = 1)
537 def handleOpenRecent(self):
539 fichier=self.ficRecents[idx]
540 self.viewmanager.handleOpen(fichier=fichier, patron =0 )
542 def handleClearRecent(self):
543 self.recent = QStringList()
548 self.viewmanager.newEditor()
549 except EficasException, exc:
552 QMessageBox.warning(self, tr(u"Erreur"), msg)
556 self.viewmanager.handleOpen()
557 except EficasException, exc:
560 QMessageBox.warning(self, tr(u"Erreur"), msg)
563 return self.viewmanager.saveCurrentEditor()
565 def fileSaveAs(self):
566 return self.viewmanager.saveAsCurrentEditor()
569 self.viewmanager.handleClose(texte='&Fermer')
571 def fileCloseAll(self):
572 self.viewmanager.handleCloseAll(texte='&Fermer')
575 # On peut sortir sur Abort
576 res=self.viewmanager.handleCloseAll()
582 self.viewmanager.handleEditCopy()
585 self.viewmanager.handleEditCut()
588 self.viewmanager.handleEditPaste()
590 def rechercher(self):
591 self.viewmanager.handleRechercher()
594 self.viewmanager.run()
597 self.viewmanager.saveRun()
601 self.viewmanager.handleSupprimer()
603 def jdcFichierSource(self):
604 self.viewmanager.handleViewJdcFichierSource()
606 def jdcRapport(self):
607 self.viewmanager.handleViewJdcRapport()
609 def gestionParam(self):
610 self.viewmanager.handlegestionParam()
613 self.viewmanager.handleViewJdcPy()
616 def NewInclude(self):
617 self.viewmanager.newIncludeEditor()
620 for pathCode in self.ListeCode:
622 aEnlever=os.path.abspath(os.path.join(os.path.dirname(__file__),'..',pathCode))
623 sys.path.remove(aEnlever)
626 for pathCode in self.listeAEnlever:
628 sys.path.remove(aEnlever)
633 def closeEvent(self,event):
635 if res==2 : event.ignore()
637 if __name__=='__main__':
640 rep=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__),'..','ASTER')))
642 from Aster import prefsCode
643 if hasattr(prefsCode,'encoding'):
644 # Hack pour changer le codage par defaut des strings
647 sys.setdefaultencoding(prefsCode.encoding)
648 del sys.setdefaultencoding
651 from Editeur import import_code
652 from Editeur import session
654 # Analyse des arguments de la ligne de commande
655 options=session.parse(sys.argv)
659 app = QApplication(sys.argv)
660 #app.setMainWidget(mw) (qt3)
664 #app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))