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)
94 #def eventFilter(QObject watched, QEvent e) :
95 #def eventFilter(watched, e) :
96 # print "hhhhhhhhhhhhhhhhhhhhhh"
97 # return QMainWindow.eventFilter(watched, e)
101 def definitCode(self,code,ssCode) :
106 from monChoixCode import MonChoixCode
107 widgetChoix = MonChoixCode(self)
108 ret=widgetChoix.exec_()
110 if self.code == None:return # pour le cancel de la fenetre choix code
111 name='prefs_'+self.code
112 prefsCode=__import__(name)
114 self.repIni=prefsCode.repIni
116 self.format_fichier= ssCode #par defaut
117 prefsCode.NAME_SCHEME=ssCode
119 self.format_fichier="python" #par defaut
121 nameConf='configuration_'+self.code
122 configuration=__import__(nameConf)
123 self.CONFIGURATION = configuration.make_config(self,prefsCode.repIni)
124 self.CONFIGStyle = None
125 if hasattr(configuration,'make_config_style'):
126 self.CONFIGStyle = configuration.make_config_style(self,prefsCode.repIni)
127 if hasattr(prefsCode,'encoding'):
130 sys.setdefaultencoding(prefsCode.encoding)
132 def construitMenu(self):
136 for intituleMenu in ("menuTraduction","menuOptions","menuMesh","menuExecution"):
137 if hasattr(self,intituleMenu):
138 menu=getattr(self,intituleMenu)
139 menu.setAttribute(Qt.WA_DeleteOnClose)
141 delattr(self,intituleMenu)
142 for intituleAction in ("actionExecution","actionSaveRun",):
143 if hasattr(self,intituleAction):
144 action=getattr(self,intituleAction)
145 self.toolBar.removeAction(action)
146 if self.code in Appli.__dict__.keys():
147 listeTexte=apply(Appli.__dict__[self.code],(self,))
151 repAide=os.path.dirname(os.path.abspath(__file__))
152 fileName='index.html'
153 self.docPath=repAide+"/../Aide"
154 if hasattr(self,'CONFIGURATION') and hasattr(self.CONFIGURATION,'docPath') : self.docPath=self.CONFIGURATION.docPath
155 if hasattr(self,'CONFIGURATION') and hasattr(self.CONFIGURATION,'fileName'):fileName=self.CONFIGURATION.fileName
156 self.fileDoc=os.path.join(self.docPath,fileName)
157 self.actionCode.setText(tr("Aide specifique ")+str(self.code))
158 if not os.path.isfile(self.fileDoc) :
161 self.actionCode.setEnabled(False)
164 self.actionCode.setEnabled(True)
165 self.menuAide.addAction(self.actionCode)
168 self.menuExecution = self.menubar.addMenu(QApplication.translate("Eficas", "Execution", None, QApplication.UnicodeUTF8))
169 self.actionExecution = QAction(self)
170 icon6 = QIcon(self.repIcon+"/roue.png")
171 self.actionExecution.setIcon(icon6)
172 self.actionExecution.setObjectName("actionExecution")
173 self.menuExecution.addAction(self.actionExecution)
174 if not(self.actionExecution in self.toolBar.actions()):
175 self.toolBar.addAction(self.actionExecution)
176 self.actionExecution.setText(QApplication.translate("Eficas", "Execution ", None, QApplication.UnicodeUTF8))
177 self.connect(self.actionExecution,SIGNAL("activated()"),self.run)
179 self.actionSaveRun = QAction(self)
180 icon7 = QIcon(self.repIcon+"/export_MAP.png")
181 #icon7 = QIcon(self.repIcon+"/saveRun.png")
182 self.actionSaveRun.setIcon(icon7)
183 self.actionSaveRun.setObjectName("actionSaveRun")
184 self.menuExecution.addAction(self.actionSaveRun)
185 if not(self.actionSaveRun in self.toolBar.actions()):
186 self.toolBar.addAction(self.actionSaveRun)
187 self.actionSaveRun.setText(QApplication.translate("Eficas", "Save Run", None, QApplication.UnicodeUTF8))
188 self.connect(self.actionSaveRun,SIGNAL("activated()"),self.saveRun)
190 self.menuOptions = self.menubar.addMenu("menuOptions")
191 self.menuOptions.addAction(self.actionParametres_Eficas)
192 self.menuOptions.setTitle(tr("Options"))
195 self.toolBar.addSeparator()
196 self.menuExecution = self.menubar.addMenu(QApplication.translate("Eficas", "Execution", None, QApplication.UnicodeUTF8))
197 self.actionExecution = QAction(self)
198 icon6 = QIcon(self.repIcon+"/compute.png")
199 self.actionExecution.setIcon(icon6)
200 self.actionExecution.setObjectName("actionExecution")
201 self.menuExecution.addAction(self.actionExecution)
202 if not(self.actionExecution in self.toolBar.actions()):
203 self.toolBar.addAction(self.actionExecution)
204 self.actionExecution.setText(QApplication.translate("Eficas", "Execution ", None, QApplication.UnicodeUTF8))
205 self.connect(self.actionExecution,SIGNAL("activated()"),self.run)
207 self.menuOptions = self.menubar.addMenu("menuOptions")
208 self.menuOptions.addAction(self.actionParametres_Eficas)
209 self.menuOptions.setTitle(tr("Options"))
213 self.menuTraduction = self.menubar.addMenu("menuTraduction")
214 self.menuTraduction.addAction(self.actionTraduitV7V8)
215 self.menuTraduction.addAction(self.actionTraduitV8V9)
216 self.menuTraduction.addAction(self.actionTraduitV9V10)
217 self.menuTraduction.setTitle(tr("Traduction"))
219 self.menuOptions = self.menubar.addMenu("menuOptions")
220 self.menuOptions.addAction(self.actionParametres_Eficas)
221 self.menuOptions.addAction(self.actionLecteur_Pdf)
222 self.menuOptions.setTitle(tr("Options"))
225 #if self.salome == 0 : return
226 self.menuMesh = self.menubar.addMenu("menuMesh")
227 self.menuMesh.setObjectName("Mesh")
228 self.menuMesh.addAction(self.actionChercheGrpMaille)
231 self.menuMesh = self.menubar.addMenu("Maillage")
232 self.menuMesh.setObjectName("Mesh")
233 self.menuMesh.addAction(self.actionChercheGrp)
234 self.menuExecution = self.menubar.addMenu(QApplication.translate("Eficas", "Execution", None, QApplication.UnicodeUTF8))
235 self.actionExecution = QAction(self)
236 icon6 = QIcon(self.repIcon+"/compute.png")
237 self.actionExecution.setIcon(icon6)
238 self.actionExecution.setObjectName("actionExecution")
239 self.menuExecution.addAction(self.actionExecution)
240 if not(self.actionExecution in self.toolBar.actions()):
241 self.toolBar.addAction(self.actionExecution)
242 self.actionExecution.setText(QApplication.translate("Eficas", "Execution ", None, QApplication.UnicodeUTF8))
243 self.connect(self.actionExecution,SIGNAL("activated()"),self.run)
246 def ChercheGrpMesh(self):
247 Msg,listeGroup=self.ChercheGrpMeshInSalome()
249 self.viewmanager.handleAjoutGroup(listeGroup)
251 print "il faut gerer les erreurs"
253 def ChercheGrpMaille(self):
254 Msg,listeGroup=self.ChercheGrpMailleInSalome()
256 self.viewmanager.handleAjoutGroup(listeGroup)
258 print "il faut gerer les erreurs"
260 def ChercheGrp(self):
261 #Msg,listeGroup=self.ChercheGrpMailleInSalome()
263 # self.viewmanager.handleAjoutGroup(listeGroup)
265 print "il faut gerer "
268 def ajoutIcones(self) :
269 # Pour pallier les soucis de repertoire d icone
270 icon = QIcon(self.repIcon+"/New24.png")
271 self.action_Nouveau.setIcon(icon)
272 icon1 = QIcon(self.repIcon+"/Open24.png")
273 self.action_Ouvrir.setIcon(icon1)
274 icon2 = QIcon(self.repIcon+"/Save24.png")
275 self.actionEnregistrer.setIcon(icon2)
276 icon3 = QIcon(self.repIcon+"/Cut24.png")
277 self.actionCouper.setIcon(icon3)
278 icon4 = QIcon(self.repIcon+"/Copy24.png")
279 self.actionCopier.setIcon(icon4)
280 icon5 = QIcon(self.repIcon+"/Paste24.png")
281 self.actionColler.setIcon(icon5)
282 icon6 = QIcon(self.repIcon+"/Delete24.png")
283 self.actionSupprimer.setIcon(icon6)
287 def connecterSignaux(self) :
288 self.connect(self.recentMenu,SIGNAL('aboutToShow()'),self.handleShowRecentMenu)
290 self.connect(self.action_Nouveau,SIGNAL("activated()"),self.fileNew)
291 self.connect(self.actionNouvel_Include,SIGNAL("activated()"),self.NewInclude)
292 self.connect(self.action_Ouvrir,SIGNAL("activated()"),self.fileOpen)
293 self.connect(self.actionEnregistrer,SIGNAL("activated()"),self.fileSave)
294 self.connect(self.actionEnregistrer_sous,SIGNAL("activated()"),self.fileSaveAs)
295 self.connect(self.actionFermer,SIGNAL("activated()"),self.fileClose)
296 self.connect(self.actionFermer_tout,SIGNAL("activated()"),self.fileCloseAll)
297 self.connect(self.actionQuitter,SIGNAL("activated()"),self.fileExit)
299 self.connect(self.actionEficas,SIGNAL("activated()"),self.aidePPal)
300 self.connect(self.actionVersion,SIGNAL("activated()"),self.version)
302 self.connect(self.actionCouper,SIGNAL("activated()"),self.editCut)
303 self.connect(self.actionCopier,SIGNAL("activated()"),self.editCopy)
304 self.connect(self.actionColler,SIGNAL("activated()"),self.editPaste)
305 self.connect(self.actionSupprimer,SIGNAL("activated()"),self.supprimer)
306 self.connect(self.actionRechercher,SIGNAL("activated()"),self.rechercher)
307 self.connect(self.actionDeplier_replier,SIGNAL("activated()"),self.Deplier)
309 self.connect(self.actionRapport_de_Validation,SIGNAL("activated()"),self.jdcRapport)
310 self.connect(self.actionFichier_Source,SIGNAL("activated()"),self.jdcFichierSource)
311 self.connect(self.actionFichier_Resultat,SIGNAL("activated()"),self.visuJdcPy)
314 #self.connect(self.helpIndexAction,SIGNAL("activated()"),self.helpIndex)
315 #self.connect(self.helpContentsAction,SIGNAL("activated()"),self.helpContents)
318 self.actionTraduitV7V8 = QAction(self)
319 self.actionTraduitV7V8.setObjectName("actionTraduitV7V8")
320 self.actionTraduitV8V9 = QAction(self)
321 self.actionTraduitV8V9.setObjectName("actionTraduitV8V9")
322 self.actionTraduitV9V10 = QAction(self)
323 self.actionTraduitV9V10.setObjectName("actionTraduitV9V10")
324 self.actionTraduitV7V8.setText(tr("TraduitV7V8"))
325 self.actionTraduitV8V9.setText(tr("TraduitV8V9"))
326 self.actionTraduitV9V10.setText(tr("TraduitV9V10"))
327 self.connect(self.actionParametres_Eficas,SIGNAL("activated()"),self.optionEditeur)
328 self.connect(self.actionLecteur_Pdf,SIGNAL("activated()"),self.optionPdf)
329 self.connect(self.actionTraduitV7V8,SIGNAL("activated()"),self.traductionV7V8)
330 self.connect(self.actionTraduitV8V9,SIGNAL("activated()"),self.traductionV8V9)
331 self.connect(self.actionTraduitV9V10,SIGNAL("activated()"),self.traductionV9V10)
334 self.actionChercheGrpMaille = QAction(self)
335 self.actionChercheGrpMaille.setText(tr("Acquiert Groupe Maille"))
336 self.connect(self.actionChercheGrpMaille,SIGNAL("activated()"),self.ChercheGrpMaille)
339 self.actionChercheGrp = QAction(self)
340 self.actionChercheGrp.setText(tr("Accquisition Groupe Maille"))
341 self.connect(self.actionChercheGrp,SIGNAL("activated()"),self.ChercheGrp)
344 self.actionCode = QAction(self)
345 self.actionCode.setText(tr("Specificites Maille"))
346 self.connect(self.actionCode,SIGNAL("activated()"),self.aideCode)
349 self.viewmanager.handleDeplier()
351 def ouvreFichiers(self) :
352 # Ouverture des fichiers de commandes donnes sur la ligne de commande
355 for study in session.d_env.studies:
357 d=session.get_unit(study,self)
358 self.viewmanager.handleOpen(fichier=study["comm"],units=d)
361 def get_source(self,file):
362 # appele par Editeur/session.py
364 p=convert.plugins['python']()
366 texte=p.convert('execnoparseur')
369 def initPatrons(self) :
370 # Mise a jour du menu des fichiers recemment ouverts
371 from Editeur import listePatrons
372 if not(self.code in listePatrons.sous_menus.keys()) :
373 if hasattr(self,"menuPatrons"):
374 self.menuPatrons.setAttribute(Qt.WA_DeleteOnClose)
375 self.menuPatrons.close()
376 delattr(self,"menuPatrons")
378 if (not hasattr(self,"menuPatrons")):
379 self.menuPatrons = QMenu(self.menubar)
380 self.menuPatrons.setObjectName("menuPatrons")
381 self.menubar.addAction(self.menuPatrons.menuAction())
382 self.menuPatrons.setTitle(QApplication.translate("Eficas", "Patrons", None, QApplication.UnicodeUTF8))
384 self.menuPatrons.clear()
385 self.listePatrons = listePatrons.listePatrons(self.code)
387 for nomSsMenu in self.listePatrons.liste.keys():
388 ssmenu=self.menuPatrons.addMenu(nomSsMenu)
389 for fichier in self.listePatrons.liste[nomSsMenu]:
390 id = ssmenu.addAction(fichier)
391 self.ficPatrons[id]=fichier
392 self.connect(id, SIGNAL('triggered()'),self.handleOpenPatrons)
393 # self.Patrons.setItemParameter(id,idx)
396 def initRecents(self):
397 self.recent = QStringList()
400 rep=os.path.join(os.environ['HOME'],'.config/Eficas',self.code)
401 monFichier=rep+"/listefichiers_"+self.code
407 l=(ligne.split("\n"))[0]
408 self.recent.append(l)
417 def addToRecentList(self, fn):
419 Public slot to add a filename to the list of recently opened files.
421 @param fn name of the file to be added
423 self.recent.removeAll(fn)
424 self.recent.prepend(fn)
425 if len(self.recent) > 9:
426 self.recent = self.recent[:9]
428 def sauveRecents(self) :
430 rep=self.CONFIGURATION.rep_user
431 monFichier=rep+"/listefichiers_"+self.code
435 f=open(monFichier,'w')
436 if len(self.recent) == 0 : return
438 while ( index < len(self.recent)):
439 ligne=str(self.recent[index])+"\n"
451 def traductionV7V8(self):
452 from gereTraduction import traduction
453 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V7V8")
455 def traductionV8V9(self):
456 from gereTraduction import traduction
457 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V8V9")
459 def traductionV9V10(self):
460 from gereTraduction import traduction
461 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V9V10")
464 from monVisu import DVisu
465 titre = tr("version ")
466 monVisuDialg=DVisu(parent=self,fl=0)
467 monVisuDialg.setWindowTitle(titre)
468 monVisuDialg.TB.setText(self.VERSION_EFICAS +tr(" pour ") + self.code)
469 monVisuDialg.adjustSize()
473 if self.code==None : return
474 repAide=os.path.dirname(os.path.abspath(__file__))
475 maD=repAide+"/../Aide"
477 indexAide=maD+"/fichiers_EFICAS/index.html"
478 cmd="xdg-open "+indexAide
481 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
485 if self.code==None : return
488 cmd="xdg-open "+self.fileDoc
492 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
495 def optionEditeur(self) :
497 name='monOptions_'+self.code
499 QMessageBox.critical( self,tr( "Parametrage"),tr( "Veuillez d abord choisir un code"))
503 optionCode=__import__(name)
506 QMessageBox.critical( self, tr("Parametrage"), tr("Pas de possibilite de personnalisation de la configuration "))
508 monOption=optionCode.Options(parent=self,modal = 0 ,configuration=self.CONFIGURATION)
511 def optionPdf(self) :
512 from monOptionsPdf import OptionPdf
513 monOption=OptionPdf(parent=self,modal = 0 ,configuration=self.CONFIGURATION)
516 def handleShowRecentMenu(self):
518 Private method to set up recent files menu.
520 self.recentMenu.clear()
522 for rp in self.recent:
523 id = self.recentMenu.addAction(rp)
524 self.ficRecents[id]=rp
525 self.connect(id, SIGNAL('triggered()'),self.handleOpenRecent)
526 self.recentMenu.addSeparator()
527 self.recentMenu.addAction(tr('&Effacer'), self.handleClearRecent)
529 def handleOpenPatrons(self):
531 fichier=self.repIni+"/../Editeur/Patrons/"+self.code+"/"+self.ficPatrons[idx]
532 self.viewmanager.handleOpen(fichier=fichier, patron = 1)
534 def handleOpenRecent(self):
536 fichier=self.ficRecents[idx]
537 self.viewmanager.handleOpen(fichier=fichier, patron =0 )
539 def handleClearRecent(self):
540 self.recent = QStringList()
545 self.viewmanager.newEditor()
546 except EficasException, exc:
549 QMessageBox.warning(self, tr(u"Erreur"), msg)
553 self.viewmanager.handleOpen()
554 except EficasException, exc:
557 QMessageBox.warning(self, tr(u"Erreur"), msg)
560 return self.viewmanager.saveCurrentEditor()
562 def fileSaveAs(self):
563 return self.viewmanager.saveAsCurrentEditor()
566 self.viewmanager.handleClose(texte='&Fermer')
568 def fileCloseAll(self):
569 self.viewmanager.handleCloseAll(texte='&Fermer')
572 # On peut sortir sur Abort
573 res=self.viewmanager.handleCloseAll()
579 self.viewmanager.handleEditCopy()
582 self.viewmanager.handleEditCut()
585 self.viewmanager.handleEditPaste()
587 def rechercher(self):
588 self.viewmanager.handleRechercher()
591 self.viewmanager.run()
594 self.viewmanager.saveRun()
598 self.viewmanager.handleSupprimer()
600 def jdcFichierSource(self):
601 self.viewmanager.handleViewJdcFichierSource()
603 def jdcRapport(self):
604 self.viewmanager.handleViewJdcRapport()
607 self.viewmanager.handleViewJdcPy()
610 def NewInclude(self):
611 self.viewmanager.newIncludeEditor()
614 for pathCode in self.ListeCode:
616 aEnlever=os.path.abspath(os.path.join(os.path.dirname(__file__),'..',pathCode))
617 sys.path.remove(aEnlever)
620 for pathCode in self.listeAEnlever:
622 sys.path.remove(aEnlever)
627 def closeEvent(self,event):
629 if res==2 : event.ignore()
631 if __name__=='__main__':
634 rep=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__),'..','ASTER')))
636 from Aster import prefsCode
637 if hasattr(prefsCode,'encoding'):
638 # Hack pour changer le codage par defaut des strings
641 sys.setdefaultencoding(prefsCode.encoding)
642 del sys.setdefaultencoding
645 from Editeur import import_code
646 from Editeur import session
648 # Analyse des arguments de la ligne de commande
649 options=session.parse(sys.argv)
653 app = QApplication(sys.argv)
654 #app.setMainWidget(mw) (qt3)
658 #app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))