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.actionTraduitV11V12)
214 self.menuTraduction.addAction(self.actionTraduitV10V11)
215 self.menuTraduction.addAction(self.actionTraduitV9V10)
216 self.menuTraduction.setTitle(tr("Traduction"))
218 self.menuFichier.addAction(self.actionSauveLigne)
220 self.menuOptions = self.menubar.addMenu("menuOptions")
221 self.menuOptions.addAction(self.actionParametres_Eficas)
222 self.menuOptions.addAction(self.actionLecteur_Pdf)
223 self.menuOptions.setTitle(tr("Options"))
226 #if self.salome == 0 : return
227 self.enleverNewInclude()
228 self.menuMesh = self.menubar.addMenu("menuMesh")
229 self.menuMesh.setObjectName("Mesh")
230 self.menuMesh.addAction(self.actionChercheGrpMaille)
231 self.griserActionsStructures()
234 self.enleverNewInclude()
235 self.enleverRechercherDsCatalogue()
236 self.ajoutExecution()
237 self.ajoutSauveExecution()
238 self.griserActionsStructures()
241 self.enleverNewInclude()
242 self.toolBar.addSeparator()
243 self.ajoutExecution()
244 self.ajoutSauveExecution()
245 self.menuOptions = self.menubar.addMenu("menuOptions")
246 self.menuOptions.addAction(self.actionParametres_Eficas)
247 self.menuOptions.setTitle(tr("Options"))
250 def ChercheGrpMesh(self):
251 Msg,listeGroup=self.ChercheGrpMeshInSalome()
253 self.viewmanager.handleAjoutGroup(listeGroup)
255 print "il faut gerer les erreurs"
257 def ChercheGrpMaille(self):
258 Msg,listeGroup=self.ChercheGrpMailleInSalome()
260 self.viewmanager.handleAjoutGroup(listeGroup)
262 print "il faut gerer les erreurs"
264 def ChercheGrp(self):
265 #Msg,listeGroup=self.ChercheGrpMailleInSalome()
267 # self.viewmanager.handleAjoutGroup(listeGroup)
269 print "il faut gerer "
272 def ajoutIcones(self) :
273 # Pour pallier les soucis de repertoire d icone
274 icon = QIcon(self.repIcon+"/New24.png")
275 self.action_Nouveau.setIcon(icon)
276 icon1 = QIcon(self.repIcon+"/Open24.png")
277 self.action_Ouvrir.setIcon(icon1)
278 icon2 = QIcon(self.repIcon+"/Save24.png")
279 self.actionEnregistrer.setIcon(icon2)
280 icon3 = QIcon(self.repIcon+"/Cut24.png")
281 self.actionCouper.setIcon(icon3)
282 icon4 = QIcon(self.repIcon+"/Copy24.png")
283 self.actionCopier.setIcon(icon4)
284 icon5 = QIcon(self.repIcon+"/Paste24.png")
285 self.actionColler.setIcon(icon5)
286 icon6 = QIcon(self.repIcon+"/Delete24.png")
287 self.actionSupprimer.setIcon(icon6)
291 def connecterSignaux(self) :
292 self.connect(self.recentMenu,SIGNAL('aboutToShow()'),self.handleShowRecentMenu)
294 self.connect(self.action_Nouveau,SIGNAL("activated()"),self.fileNew)
295 self.connect(self.actionNouvel_Include,SIGNAL("activated()"),self.NewInclude)
296 self.connect(self.action_Ouvrir,SIGNAL("activated()"),self.fileOpen)
297 self.connect(self.actionEnregistrer,SIGNAL("activated()"),self.fileSave)
298 self.connect(self.actionEnregistrer_sous,SIGNAL("activated()"),self.fileSaveAs)
299 self.connect(self.actionFermer,SIGNAL("activated()"),self.fileClose)
300 self.connect(self.actionFermer_tout,SIGNAL("activated()"),self.fileCloseAll)
301 self.connect(self.actionQuitter,SIGNAL("activated()"),self.fileExit)
303 self.connect(self.actionEficas,SIGNAL("activated()"),self.aidePPal)
304 self.connect(self.actionVersion,SIGNAL("activated()"),self.version)
305 self.connect(self.actionParametres,SIGNAL("activated()"),self.gestionParam)
307 self.connect(self.actionCouper,SIGNAL("activated()"),self.editCut)
308 self.connect(self.actionCopier,SIGNAL("activated()"),self.editCopy)
309 self.connect(self.actionColler,SIGNAL("activated()"),self.editPaste)
310 self.connect(self.actionSupprimer,SIGNAL("activated()"),self.supprimer)
311 self.connect(self.actionRechercher,SIGNAL("activated()"),self.rechercher)
312 self.connect(self.actionDeplier_replier,SIGNAL("activated()"),self.Deplier)
314 self.connect(self.actionRapport_de_Validation,SIGNAL("activated()"),self.jdcRapport)
315 self.connect(self.actionFichier_Source,SIGNAL("activated()"),self.jdcFichierSource)
316 self.connect(self.actionFichier_Resultat,SIGNAL("activated()"),self.visuJdcPy)
319 #self.connect(self.helpIndexAction,SIGNAL("activated()"),self.helpIndex)
320 #self.connect(self.helpContentsAction,SIGNAL("activated()"),self.helpContents)
323 self.actionTraduitV9V10 = QAction(self)
324 self.actionTraduitV9V10.setObjectName("actionTraduitV9V10")
325 self.actionTraduitV9V10.setText(tr("TraduitV9V10"))
326 self.actionTraduitV10V11 = QAction(self)
327 self.actionTraduitV10V11.setObjectName("actionTraduitV10V11")
328 self.actionTraduitV10V11.setText(tr("TraduitV10V11"))
329 self.actionTraduitV11V12 = QAction(self)
330 self.actionTraduitV11V12.setObjectName("actionTraduitV11V12")
331 self.actionTraduitV11V12.setText(tr("TraduitV11V12"))
332 self.actionSauveLigne = QAction(self)
333 self.actionSauveLigne.setText(tr("Sauve Format Ligne"))
335 self.connect(self.actionParametres_Eficas,SIGNAL("activated()"),self.optionEditeur)
336 self.connect(self.actionLecteur_Pdf,SIGNAL("activated()"),self.optionPdf)
337 self.connect(self.actionTraduitV9V10,SIGNAL("activated()"),self.traductionV9V10)
338 self.connect(self.actionTraduitV10V11,SIGNAL("activated()"),self.traductionV10V11)
339 self.connect(self.actionTraduitV11V12,SIGNAL("activated()"),self.traductionV11V12)
340 self.connect(self.actionSauveLigne,SIGNAL("activated()"),self.sauveLigne)
344 self.actionChercheGrpMaille = QAction(self)
345 self.actionChercheGrpMaille.setText(tr("Acquiert Groupe Maille"))
346 self.connect(self.actionChercheGrpMaille,SIGNAL("activated()"),self.ChercheGrpMaille)
349 self.actionChercheGrp = QAction(self)
350 self.actionChercheGrp.setText(tr("Accquisition Groupe Maille"))
351 self.connect(self.actionChercheGrp,SIGNAL("activated()"),self.ChercheGrp)
354 self.actionCode = QAction(self)
355 self.actionCode.setText(tr("Specificites Maille"))
356 self.connect(self.actionCode,SIGNAL("activated()"),self.aideCode)
359 self.viewmanager.handleDeplier()
361 def ouvreFichiers(self) :
362 # Ouverture des fichiers de commandes donnes sur la ligne de commande
365 for study in session.d_env.studies:
367 d=session.get_unit(study,self)
368 self.viewmanager.handleOpen(fichier=study["comm"],units=d)
371 def get_source(self,file):
372 # appele par Editeur/session.py
374 p=convert.plugins['python']()
376 texte=p.convert('execnoparseur')
379 def initPatrons(self) :
380 # Mise a jour du menu des fichiers recemment ouverts
381 from Editeur import listePatrons
382 if not(self.code in listePatrons.sous_menus.keys()) :
383 if hasattr(self,"menuPatrons"):
384 self.menuPatrons.setAttribute(Qt.WA_DeleteOnClose)
385 self.menuPatrons.close()
386 delattr(self,"menuPatrons")
388 if (not hasattr(self,"menuPatrons")):
389 self.menuPatrons = QMenu(self.menubar)
390 self.menuPatrons.setObjectName("menuPatrons")
391 self.menubar.addAction(self.menuPatrons.menuAction())
392 self.menuPatrons.setTitle(QApplication.translate("Eficas", "Patrons", None, QApplication.UnicodeUTF8))
394 self.menuPatrons.clear()
395 self.listePatrons = listePatrons.listePatrons(self.code)
397 for nomSsMenu in self.listePatrons.liste.keys():
398 ssmenu=self.menuPatrons.addMenu(nomSsMenu)
399 for fichier in self.listePatrons.liste[nomSsMenu]:
400 id = ssmenu.addAction(fichier)
401 self.ficPatrons[id]=fichier
402 self.connect(id, SIGNAL('triggered()'),self.handleOpenPatrons)
403 # self.Patrons.setItemParameter(id,idx)
406 def initRecents(self):
407 self.recent = QStringList()
410 rep=os.path.join(os.environ['HOME'],'.config/Eficas',self.code)
411 monFichier=rep+"/listefichiers_"+self.code
417 l=(ligne.split("\n"))[0]
418 self.recent.append(l)
427 def addToRecentList(self, fn):
429 Public slot to add a filename to the list of recently opened files.
431 @param fn name of the file to be added
433 self.recent.removeAll(fn)
434 self.recent.prepend(fn)
435 if len(self.recent) > 9:
436 self.recent = self.recent[:9]
438 def sauveRecents(self) :
440 rep=self.CONFIGURATION.rep_user
441 monFichier=rep+"/listefichiers_"+self.code
445 f=open(monFichier,'w')
446 if len(self.recent) == 0 : return
448 while ( index < len(self.recent)):
449 ligne=str(self.recent[index])+"\n"
461 def traductionV11V12(self):
462 from gereTraduction import traduction
463 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V11V12")
465 def traductionV10V11(self):
466 from gereTraduction import traduction
467 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V10V11")
469 def traductionV9V10(self):
470 from gereTraduction import traduction
471 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V9V10")
474 from monVisu import DVisu
475 titre = tr("version ")
476 monVisuDialg=DVisu(parent=self,fl=0)
477 monVisuDialg.setWindowTitle(titre)
478 monVisuDialg.TB.setText(self.VERSION_EFICAS +tr(" pour ") + self.code)
479 monVisuDialg.adjustSize()
483 if self.code==None : return
484 repAide=os.path.dirname(os.path.abspath(__file__))
485 maD=repAide+"/../Aide"
487 indexAide=maD+"/fichiers_EFICAS/index.html"
488 cmd="xdg-open "+indexAide
491 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
495 if self.code==None : return
498 cmd="xdg-open "+self.fileDoc
502 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
505 def optionEditeur(self) :
507 name='monOptions_'+self.code
509 QMessageBox.critical( self,tr( "Parametrage"),tr( "Veuillez d abord choisir un code"))
513 optionCode=__import__(name)
516 QMessageBox.critical( self, tr("Parametrage"), tr("Pas de possibilite de personnalisation de la configuration "))
518 monOption=optionCode.Options(parent=self,modal = 0 ,configuration=self.CONFIGURATION)
521 def optionPdf(self) :
522 from monOptionsPdf import OptionPdf
523 monOption=OptionPdf(parent=self,modal = 0 ,configuration=self.CONFIGURATION)
526 def handleShowRecentMenu(self):
528 Private method to set up recent files menu.
530 self.recentMenu.clear()
532 for rp in self.recent:
533 id = self.recentMenu.addAction(rp)
534 self.ficRecents[id]=rp
535 self.connect(id, SIGNAL('triggered()'),self.handleOpenRecent)
536 self.recentMenu.addSeparator()
537 self.recentMenu.addAction(tr('&Effacer'), self.handleClearRecent)
539 def handleOpenPatrons(self):
541 fichier=self.repIni+"/../Editeur/Patrons/"+self.code+"/"+self.ficPatrons[idx]
542 self.viewmanager.handleOpen(fichier=fichier, patron = 1)
544 def handleOpenRecent(self):
546 fichier=self.ficRecents[idx]
547 self.viewmanager.handleOpen(fichier=fichier, patron =0 )
549 def handleClearRecent(self):
550 self.recent = QStringList()
555 self.viewmanager.newEditor()
556 except EficasException, exc:
559 QMessageBox.warning(self, tr(u"Erreur"), msg)
563 self.viewmanager.handleOpen()
564 except EficasException, exc:
567 QMessageBox.warning(self, tr(u"Erreur"), msg)
569 def sauveLigne(self):
570 return self.viewmanager.sauveLigneCurrentEditor()
573 return self.viewmanager.saveCurrentEditor()
575 def fileSaveAs(self):
576 return self.viewmanager.saveAsCurrentEditor()
579 self.viewmanager.handleClose(texte='&Fermer')
581 def fileCloseAll(self):
582 self.viewmanager.handleCloseAll(texte='&Fermer')
585 # On peut sortir sur Abort
586 res=self.viewmanager.handleCloseAll()
592 self.viewmanager.handleEditCopy()
595 self.viewmanager.handleEditCut()
598 self.viewmanager.handleEditPaste()
600 def rechercher(self):
601 self.viewmanager.handleRechercher()
604 self.viewmanager.run()
607 self.viewmanager.saveRun()
611 self.viewmanager.handleSupprimer()
613 def jdcFichierSource(self):
614 self.viewmanager.handleViewJdcFichierSource()
616 def jdcRapport(self):
617 self.viewmanager.handleViewJdcRapport()
619 def gestionParam(self):
620 self.viewmanager.handlegestionParam()
623 self.viewmanager.handleViewJdcPy()
626 def NewInclude(self):
627 self.viewmanager.newIncludeEditor()
630 for pathCode in self.ListeCode:
632 aEnlever=os.path.abspath(os.path.join(os.path.dirname(__file__),'..',pathCode))
633 sys.path.remove(aEnlever)
636 for pathCode in self.listeAEnlever:
638 sys.path.remove(aEnlever)
643 def closeEvent(self,event):
645 if res==2 : event.ignore()
647 if __name__=='__main__':
650 rep=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__),'..','ASTER')))
652 from Aster import prefsCode
653 if hasattr(prefsCode,'encoding'):
654 # Hack pour changer le codage par defaut des strings
657 sys.setdefaultencoding(prefsCode.encoding)
658 del sys.setdefaultencoding
661 from Editeur import import_code
662 from Editeur import session
664 # Analyse des arguments de la ligne de commande
665 options=session.parse(sys.argv)
669 app = QApplication(sys.argv)
670 #app.setMainWidget(mw) (qt3)
674 #app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))