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.recentMenu=QMenu(tr('&Recents'))
86 #self.menuFichier.insertMenu(self.actionOuvrir,self.recentMenu)
87 # actionARemplacer ne sert que pour l insert Menu
88 self.menuFichier.insertMenu(self.actionARemplacer ,self.recentMenu)
89 self.menuFichier.removeAction(self.actionARemplacer)
90 self.connecterSignaux()
91 self.toolBar.addSeparator()
92 if self.code != None : self.construitMenu()
95 self.setWindowTitle(self.VERSION_EFICAS)
100 def definitCode(self,code,ssCode) :
105 from monChoixCode import MonChoixCode
106 widgetChoix = MonChoixCode(self)
107 ret=widgetChoix.exec_()
109 if self.code == None:return # pour le cancel de la fenetre choix code
110 name='prefs_'+self.code
111 prefsCode=__import__(name)
113 self.repIni=prefsCode.repIni
115 self.format_fichier= ssCode #par defaut
116 prefsCode.NAME_SCHEME=ssCode
118 self.format_fichier="python" #par defaut
120 nameConf='configuration_'+self.code
121 configuration=__import__(nameConf)
122 self.CONFIGURATION = configuration.make_config(self,prefsCode.repIni)
123 self.CONFIGStyle = None
124 if hasattr(configuration,'make_config_style'):
125 self.CONFIGStyle = configuration.make_config_style(self,prefsCode.repIni)
126 if hasattr(prefsCode,'encoding'):
129 sys.setdefaultencoding(prefsCode.encoding)
131 def construitMenu(self):
135 for intituleMenu in ("menuTraduction","menuOptions","menuMesh","menuExecution"):
136 if hasattr(self,intituleMenu):
137 menu=getattr(self,intituleMenu)
138 menu.setAttribute(Qt.WA_DeleteOnClose)
140 delattr(self,intituleMenu)
141 for intituleAction in ("actionExecution","actionSaveRun",):
142 if hasattr(self,intituleAction):
143 action=getattr(self,intituleAction)
144 self.toolBar.removeAction(action)
145 if self.code.upper() in Appli.__dict__.keys():
146 listeTexte=apply(Appli.__dict__[self.code.upper()],(self,))
150 repAide=os.path.dirname(os.path.abspath(__file__))
151 fileName='index.html'
152 self.docPath=repAide+"/../Aide"
153 if hasattr(self,'CONFIGURATION') and hasattr(self.CONFIGURATION,'docPath') : self.docPath=self.CONFIGURATION.docPath
154 if hasattr(self,'CONFIGURATION') and hasattr(self.CONFIGURATION,'fileName'):fileName=self.CONFIGURATION.fileName
155 self.fileDoc=os.path.join(self.docPath,fileName)
156 self.actionCode.setText(tr("Aide specifique ")+str(self.code))
157 if not os.path.isfile(self.fileDoc) :
160 self.actionCode.setEnabled(False)
163 self.actionCode.setEnabled(True)
164 self.menuAide.addAction(self.actionCode)
167 def ajoutExecution(self):
168 self.menuExecution = self.menubar.addMenu(QApplication.translate("Eficas", "Execution", None, QApplication.UnicodeUTF8))
169 self.actionExecution = QAction(self)
170 if sys.platform[0:5]=="linux":
171 icon6 = QIcon(self.repIcon+"/roue.png")
172 self.actionExecution.setIcon(icon6)
174 self.actionExecution.setText(QApplication.translate("Eficas", "Run", None))
175 self.actionExecution.setObjectName("actionExecution")
176 self.menuExecution.addAction(self.actionExecution)
177 if not(self.actionExecution in self.toolBar.actions()):
178 self.toolBar.addAction(self.actionExecution)
179 self.actionExecution.setText(QApplication.translate("Eficas", "Execution ", None, QApplication.UnicodeUTF8))
180 self.connect(self.actionExecution,SIGNAL("triggered()"),self.run)
182 def ajoutSauveExecution(self):
183 self.actionSaveRun = QAction(self)
184 icon7 = QIcon(self.repIcon+"/export_MAP.png")
185 self.actionSaveRun.setIcon(icon7)
186 self.actionSaveRun.setObjectName("actionSaveRun")
187 self.menuExecution.addAction(self.actionSaveRun)
188 if not(self.actionSaveRun in self.toolBar.actions()):
189 self.toolBar.addAction(self.actionSaveRun)
190 self.actionSaveRun.setText(QApplication.translate("Eficas", "Save Run", None, QApplication.UnicodeUTF8))
191 self.connect(self.actionSaveRun,SIGNAL("triggered()"),self.saveRun)
193 def griserActionsStructures(self):
194 self.actionCouper.setEnabled(False)
195 self.actionColler.setEnabled(False)
196 self.actionCopier.setEnabled(False)
197 self.actionSupprimer.setEnabled(False)
199 def enleverActionsStructures(self):
200 self.toolBar.removeAction(self.actionCopier)
201 self.toolBar.removeAction(self.actionColler)
202 self.toolBar.removeAction(self.actionCouper)
203 self.menuEdition.removeAction(self.actionCouper)
204 self.menuEdition.removeAction(self.actionCopier)
205 self.menuEdition.removeAction(self.actionColler)
208 def enleverParametres(self):
209 self.toolBar.removeAction(self.actionParametres)
210 self.menuJdC.removeAction(self.actionParametres)
213 def enleverNewInclude(self):
214 self.actionNouvel_Include.setVisible(False)
216 def enleverRechercherDsCatalogue(self):
217 self.actionRechercherDsCatalogue.setVisible(False)
220 self.enleverNewInclude()
221 self.toolBar.addSeparator()
222 self.ajoutExecution()
224 self.menuOptions = self.menubar.addMenu("menuOptions")
225 self.menuOptions.addAction(self.actionParametres_Eficas)
226 self.menuOptions.setTitle(tr("Options"))
229 self.enleverActionsStructures()
230 self.enleverNewInclude()
231 self.enleverRechercherDsCatalogue()
234 self.menuTraduction = self.menubar.addMenu("menuTraduction")
235 self.menuTraduction.addAction(self.actionTraduitV11V12)
236 self.menuTraduction.addAction(self.actionTraduitV10V11)
237 self.menuTraduction.addAction(self.actionTraduitV9V10)
238 self.menuTraduction.setTitle(tr("Traduction"))
240 self.menuFichier.addAction(self.actionSauveLigne)
242 self.menuOptions = self.menubar.addMenu("menuOptions")
243 self.menuOptions.addAction(self.actionParametres_Eficas)
244 self.menuOptions.addAction(self.actionLecteur_Pdf)
245 self.menuOptions.setTitle(tr("Options"))
248 #if self.salome == 0 : return
249 self.enleverNewInclude()
250 self.menuMesh = self.menubar.addMenu("menuMesh")
251 self.menuMesh.setObjectName("Mesh")
252 self.menuMesh.addAction(self.actionChercheGrpMaille)
253 self.griserActionsStructures()
256 self.enleverNewInclude()
257 self.enleverRechercherDsCatalogue()
258 self.ajoutExecution()
259 self.ajoutSauveExecution()
260 self.griserActionsStructures()
263 self.enleverNewInclude()
264 self.toolBar.addSeparator()
265 self.ajoutExecution()
266 self.ajoutSauveExecution()
267 self.menuOptions = self.menubar.addMenu("menuOptions")
268 self.menuOptions.addAction(self.actionParametres_Eficas)
269 self.menuOptions.setTitle(tr("Options"))
272 self.enleverActionsStructures()
273 self.enleverParametres()
274 self.enleverRechercherDsCatalogue()
275 self.enleverNewInclude()
276 self.ajoutExecution()
279 self.enleverActionsStructures()
280 self.enleverNewInclude()
282 def ChercheGrpMesh(self):
283 Msg,listeGroup=self.ChercheGrpMeshInSalome()
285 self.viewmanager.handleAjoutGroup(listeGroup)
287 print "il faut gerer les erreurs"
289 def ChercheGrpMaille(self):
290 # Normalement la variable self.salome permet de savoir si on est ou non dans Salome
292 Msg,listeGroup=self.ChercheGrpMailleInSalome() # recherche dans Salomé
293 #Msg = None; listeGroup = None # recherche manuelle, i.e., sans Salomé si ligne précédente commentée
295 raise ValueError('Salome non ouvert')
297 self.viewmanager.handleAjoutGroup(listeGroup)
299 print "il faut gerer les erreurs"
302 def ChercheGrp(self):
303 #Msg,listeGroup=self.ChercheGrpMailleInSalome()
305 # self.viewmanager.handleAjoutGroup(listeGroup)
307 print "il faut gerer "
310 def ajoutIcones(self) :
311 # Pour pallier les soucis de repertoire d icone
312 icon = QIcon(self.repIcon+"/New24.png")
313 self.action_Nouveau.setIcon(icon)
314 icon1 = QIcon(self.repIcon+"/Open24.png")
315 self.actionOuvrir.setIcon(icon1)
316 icon2 = QIcon(self.repIcon+"/Save24.png")
317 self.actionEnregistrer.setIcon(icon2)
318 icon3 = QIcon(self.repIcon+"/Cut24.png")
319 self.actionCouper.setIcon(icon3)
320 icon4 = QIcon(self.repIcon+"/Copy24.png")
321 self.actionCopier.setIcon(icon4)
322 icon5 = QIcon(self.repIcon+"/Paste24.png")
323 self.actionColler.setIcon(icon5)
324 icon6 = QIcon(self.repIcon+"/Delete24.png")
325 self.actionSupprimer.setIcon(icon6)
329 def connecterSignaux(self) :
330 self.connect(self.recentMenu,SIGNAL('aboutToShow()'),self.handleShowRecentMenu)
332 self.connect(self.action_Nouveau,SIGNAL("triggered()"),self.fileNew)
333 self.connect(self.actionNouvel_Include,SIGNAL("triggered()"),self.NewInclude)
334 self.connect(self.actionOuvrir,SIGNAL("triggered()"),self.fileOpen)
335 self.connect(self.actionEnregistrer,SIGNAL("triggered()"),self.fileSave)
336 self.connect(self.actionEnregistrer_sous,SIGNAL("triggered()"),self.fileSaveAs)
337 self.connect(self.actionFermer,SIGNAL("triggered()"),self.fileClose)
338 self.connect(self.actionFermer_tout,SIGNAL("triggered()"),self.fileCloseAll)
339 self.connect(self.actionQuitter,SIGNAL("triggered()"),self.fileExit)
341 self.connect(self.actionEficas,SIGNAL("triggered()"),self.aidePPal)
342 self.connect(self.actionVersion,SIGNAL("triggered()"),self.version)
343 self.connect(self.actionParametres,SIGNAL("triggered()"),self.gestionParam)
345 self.connect(self.actionCouper,SIGNAL("triggered()"),self.editCut)
346 self.connect(self.actionCopier,SIGNAL("triggered()"),self.editCopy)
347 self.connect(self.actionColler,SIGNAL("triggered()"),self.editPaste)
348 self.connect(self.actionSupprimer,SIGNAL("triggered()"),self.supprimer)
349 self.connect(self.actionRechercher,SIGNAL("triggered()"),self.rechercher)
350 self.connect(self.actionDeplier_replier,SIGNAL("triggered()"),self.Deplier)
352 self.connect(self.actionRapport_de_Validation,SIGNAL("triggered()"),self.jdcRapport)
353 self.connect(self.actionRegles_du_JdC,SIGNAL("triggered()"),self.jdcRegles)
354 self.connect(self.actionFichier_Source,SIGNAL("triggered()"),self.jdcFichierSource)
355 self.connect(self.actionFichier_Resultat,SIGNAL("triggered()"),self.visuJdcPy)
358 #self.connect(self.helpIndexAction,SIGNAL("triggered()"),self.helpIndex)
359 #self.connect(self.helpContentsAction,SIGNAL("triggered()"),self.helpContents)
362 self.actionTraduitV9V10 = QAction(self)
363 self.actionTraduitV9V10.setObjectName("actionTraduitV9V10")
364 self.actionTraduitV9V10.setText(tr("TraduitV9V10"))
365 self.actionTraduitV10V11 = QAction(self)
366 self.actionTraduitV10V11.setObjectName("actionTraduitV10V11")
367 self.actionTraduitV10V11.setText(tr("TraduitV10V11"))
368 self.actionTraduitV11V12 = QAction(self)
369 self.actionTraduitV11V12.setObjectName("actionTraduitV11V12")
370 self.actionTraduitV11V12.setText(tr("TraduitV11V12"))
371 self.actionSauveLigne = QAction(self)
372 self.actionSauveLigne.setText(tr("Sauve Format Ligne"))
374 self.connect(self.actionParametres_Eficas,SIGNAL("triggered()"),self.optionEditeur)
375 self.connect(self.actionLecteur_Pdf,SIGNAL("triggered()"),self.optionPdf)
376 self.connect(self.actionTraduitV9V10,SIGNAL("triggered()"),self.traductionV9V10)
377 self.connect(self.actionTraduitV10V11,SIGNAL("triggered()"),self.traductionV10V11)
378 self.connect(self.actionTraduitV11V12,SIGNAL("triggered()"),self.traductionV11V12)
379 self.connect(self.actionSauveLigne,SIGNAL("triggered()"),self.sauveLigne)
383 self.actionChercheGrpMaille = QAction(self)
384 self.actionChercheGrpMaille.setText(tr("Acquiert Groupe Maille"))
385 self.connect(self.actionChercheGrpMaille,SIGNAL("triggered()"),self.ChercheGrpMaille)
388 self.actionChercheGrp = QAction(self)
389 self.actionChercheGrp.setText(tr("Accquisition Groupe Maille"))
390 self.connect(self.actionChercheGrp,SIGNAL("triggered()"),self.ChercheGrp)
393 self.actionCode = QAction(self)
394 self.actionCode.setText(tr("Specificites Maille"))
395 self.connect(self.actionCode,SIGNAL("triggered()"),self.aideCode)
398 self.viewmanager.handleDeplier()
400 def ouvreFichiers(self) :
401 # Ouverture des fichiers de commandes donnes sur la ligne de commande
404 for study in session.d_env.studies:
406 d=session.get_unit(study,self)
407 self.viewmanager.handleOpen(fichier=study["comm"],units=d)
410 def get_source(self,file):
411 # appele par Editeur/session.py
413 p=convert.plugins['python']()
415 texte=p.convert('execnoparseur')
418 def initPatrons(self) :
419 # Mise a jour du menu des fichiers recemment ouverts
420 from Editeur import listePatrons
421 if not(self.code in listePatrons.sous_menus.keys()) :
422 if hasattr(self,"menuPatrons"):
423 self.menuPatrons.setAttribute(Qt.WA_DeleteOnClose)
424 self.menuPatrons.close()
425 delattr(self,"menuPatrons")
427 if (not hasattr(self,"menuPatrons")):
428 self.menuPatrons = QMenu(self.menubar)
429 self.menuPatrons.setObjectName("menuPatrons")
430 self.menubar.addAction(self.menuPatrons.menuAction())
431 self.menuPatrons.setTitle(QApplication.translate("Eficas", "Patrons", None, QApplication.UnicodeUTF8))
433 self.menuPatrons.clear()
434 self.listePatrons = listePatrons.listePatrons(self.code)
436 for nomSsMenu in self.listePatrons.liste.keys():
437 ssmenu=self.menuPatrons.addMenu(nomSsMenu)
438 for fichier in self.listePatrons.liste[nomSsMenu]:
439 id = ssmenu.addAction(fichier)
440 self.ficPatrons[id]=fichier
441 self.connect(id, SIGNAL('triggered()'),self.handleOpenPatrons)
442 # self.Patrons.setItemParameter(id,idx)
445 def initRecents(self):
446 self.recent = QStringList()
449 if sys.platform[0:5]=="linux" :
450 rep=os.path.join(os.environ['HOME'],'.config/Eficas',self.code)
452 rep=os.path.join('C:/','.config/Eficas',self.code)
453 monFichier=rep+"/listefichiers_"+self.code
459 l=(ligne.split("\n"))[0]
460 self.recent.append(l)
469 def addToRecentList(self, fn):
471 Public slot to add a filename to the list of recently opened files.
473 @param fn name of the file to be added
475 self.recent.removeAll(fn)
476 self.recent.prepend(fn)
477 if len(self.recent) > 9:
478 self.recent = self.recent[:9]
482 def sauveRecents(self) :
484 rep=self.CONFIGURATION.rep_user
485 monFichier=rep+"/listefichiers_"+self.code
489 f=open(monFichier,'w')
490 if len(self.recent) == 0 : return
492 while ( index < len(self.recent)):
493 ligne=str(self.recent[index])+"\n"
505 def traductionV11V12(self):
506 from gereTraduction import traduction
507 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V11V12")
509 def traductionV10V11(self):
510 from gereTraduction import traduction
511 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V10V11")
513 def traductionV9V10(self):
514 from gereTraduction import traduction
515 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V9V10")
518 from monVisu import DVisu
519 titre = tr("version ")
520 monVisuDialg=DVisu(parent=self,fl=0)
521 monVisuDialg.setWindowTitle(titre)
522 monVisuDialg.TB.setText(self.VERSION_EFICAS +tr(" pour ") + self.code)
523 monVisuDialg.adjustSize()
527 if self.code==None : return
528 repAide=os.path.dirname(os.path.abspath(__file__))
529 maD=repAide+"/../Aide"
531 indexAide=maD+"/fichiers_EFICAS/index.html"
532 if sys.platform[0:5]=="linux" : cmd="xdg-open "+indexAide
533 else : cmd="start "+indexAide
536 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
540 if self.code==None : return
543 if sys.platform[0:5]=="linux" : cmd="xdg-open "+self.fileDoc
544 else : cmd="start "+self.fileDoc
548 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
551 def optionEditeur(self) :
553 name='monOptions_'+self.code
555 QMessageBox.critical( self,tr( "Parametrage"),tr( "Veuillez d abord choisir un code"))
559 optionCode=__import__(name)
562 QMessageBox.critical( self, tr("Parametrage"), tr("Pas de possibilite de personnalisation de la configuration "))
564 monOption=optionCode.Options(parent=self,modal = 0 ,configuration=self.CONFIGURATION)
567 def optionPdf(self) :
568 from monOptionsPdf import OptionPdf
569 monOption=OptionPdf(parent=self,modal = 0 ,configuration=self.CONFIGURATION)
572 def handleShowRecentMenu(self):
574 Private method to set up recent files menu.
576 self.recentMenu.clear()
578 for rp in self.recent:
579 id = self.recentMenu.addAction(rp)
580 self.ficRecents[id]=rp
581 self.connect(id, SIGNAL('triggered()'),self.handleOpenRecent)
582 self.recentMenu.addSeparator()
583 self.recentMenu.addAction(tr('&Effacer'), self.handleClearRecent)
585 def handleOpenPatrons(self):
587 fichier=self.repIni+"/../Editeur/Patrons/"+self.code+"/"+self.ficPatrons[idx]
588 self.viewmanager.handleOpen(fichier=fichier, patron = 1)
590 def handleOpenRecent(self):
592 fichier=self.ficRecents[idx]
593 self.viewmanager.handleOpen(fichier=fichier, patron =0 )
595 def handleClearRecent(self):
596 self.recent = QStringList()
601 self.viewmanager.newEditor()
602 except EficasException, exc:
605 QMessageBox.warning(self, tr(u"Erreur"), msg)
609 self.viewmanager.handleOpen()
610 except EficasException, exc:
613 QMessageBox.warning(self, tr(u"Erreur"), msg)
615 def sauveLigne(self):
616 return self.viewmanager.sauveLigneCurrentEditor()
619 return self.viewmanager.saveCurrentEditor()
621 def fileSaveAs(self):
622 return self.viewmanager.saveAsCurrentEditor()
625 self.viewmanager.handleClose(texte='&Fermer')
627 def fileCloseAll(self):
628 self.viewmanager.handleCloseAll(texte='&Fermer')
631 # On peut sortir sur Abort
632 res=self.viewmanager.handleCloseAll()
638 self.viewmanager.handleEditCopy()
641 self.viewmanager.handleEditCut()
644 self.viewmanager.handleEditPaste()
646 def rechercher(self):
647 self.viewmanager.handleRechercher()
650 self.viewmanager.run()
653 self.viewmanager.saveRun()
657 self.viewmanager.handleSupprimer()
659 def jdcFichierSource(self):
660 self.viewmanager.handleViewJdcFichierSource()
662 def jdcRapport(self):
663 self.viewmanager.handleViewJdcRapport()
666 self.viewmanager.handleViewJdcRegles()
668 def gestionParam(self):
669 self.viewmanager.handlegestionParam()
672 self.viewmanager.handleViewJdcPy()
675 def NewInclude(self):
676 self.viewmanager.newIncludeEditor()
679 for pathCode in self.ListeCode:
681 aEnlever=os.path.abspath(os.path.join(os.path.dirname(__file__),'..',pathCode))
682 sys.path.remove(aEnlever)
685 for pathCode in self.listeAEnlever:
687 sys.path.remove(aEnlever)
692 def closeEvent(self,event):
694 if res==2 : event.ignore()
696 if __name__=='__main__':
699 rep=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__),'..','ASTER')))
701 from Aster import prefsCode
702 if hasattr(prefsCode,'encoding'):
703 # Hack pour changer le codage par defaut des strings
706 sys.setdefaultencoding(prefsCode.encoding)
707 del sys.setdefaultencoding
710 from Editeur import import_code
711 from Editeur import session
713 # Analyse des arguments de la ligne de commande
714 options=session.parse(sys.argv)
718 app = QApplication(sys.argv)
719 #app.setMainWidget(mw) (qt3)
723 #app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))