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 def ajoutExecution(self):
169 self.menuExecution = self.menubar.addMenu(QApplication.translate("Eficas", "Execution", None, QApplication.UnicodeUTF8))
170 self.actionExecution = QAction(self)
171 icon6 = QIcon(self.repIcon+"/roue.png")
172 self.actionExecution.setIcon(icon6)
173 self.actionExecution.setObjectName("actionExecution")
174 self.menuExecution.addAction(self.actionExecution)
175 if not(self.actionExecution in self.toolBar.actions()):
176 self.toolBar.addAction(self.actionExecution)
177 self.actionExecution.setText(QApplication.translate("Eficas", "Execution ", None, QApplication.UnicodeUTF8))
178 self.connect(self.actionExecution,SIGNAL("activated()"),self.run)
180 def ajoutSauveExecution(self):
181 self.actionSaveRun = QAction(self)
182 icon7 = QIcon(self.repIcon+"/export_MAP.png")
183 self.actionSaveRun.setIcon(icon7)
184 self.actionSaveRun.setObjectName("actionSaveRun")
185 self.menuExecution.addAction(self.actionSaveRun)
186 if not(self.actionSaveRun in self.toolBar.actions()):
187 self.toolBar.addAction(self.actionSaveRun)
188 self.actionSaveRun.setText(QApplication.translate("Eficas", "Save Run", None, QApplication.UnicodeUTF8))
189 self.connect(self.actionSaveRun,SIGNAL("activated()"),self.saveRun)
191 def griserActionsStructures(self):
192 self.actionCouper.setEnabled(False)
193 self.actionColler.setEnabled(False)
194 self.actionCopier.setEnabled(False)
195 self.actionSupprimer.setEnabled(False)
197 def enleverNewInclude(self):
198 self.actionNouvel_Include.setVisible(False)
200 def enleverRechercherDsCatalogue(self):
201 self.actionRechercherDsCatalogue.setVisible(False)
204 self.enleverNewInclude()
205 self.toolBar.addSeparator()
206 self.ajoutExecution()
208 self.menuOptions = self.menubar.addMenu("menuOptions")
209 self.menuOptions.addAction(self.actionParametres_Eficas)
210 self.menuOptions.setTitle(tr("Options"))
213 self.griserActionsStructures()
214 self.enleverNewInclude()
215 self.enleverRechercherDsCatalogue()
218 self.menuTraduction = self.menubar.addMenu("menuTraduction")
219 self.menuTraduction.addAction(self.actionTraduitV7V8)
220 self.menuTraduction.addAction(self.actionTraduitV8V9)
221 self.menuTraduction.addAction(self.actionTraduitV9V10)
222 self.menuTraduction.setTitle(tr("Traduction"))
224 self.menuOptions = self.menubar.addMenu("menuOptions")
225 self.menuOptions.addAction(self.actionParametres_Eficas)
226 self.menuOptions.addAction(self.actionLecteur_Pdf)
227 self.menuOptions.setTitle(tr("Options"))
230 #if self.salome == 0 : return
231 self.enleverNewInclude()
232 self.menuMesh = self.menubar.addMenu("menuMesh")
233 self.menuMesh.setObjectName("Mesh")
234 self.menuMesh.addAction(self.actionChercheGrpMaille)
235 self.griserActionsStructures()
238 self.enleverNewInclude()
239 self.enleverRechercherDsCatalogue()
240 self.ajoutExecution()
241 self.ajoutSauveExecution()
242 self.griserActionsStructures()
245 self.enleverNewInclude()
246 self.toolBar.addSeparator()
247 self.ajoutExecution()
248 self.ajoutSauveExecution()
249 self.menuOptions = self.menubar.addMenu("menuOptions")
250 self.menuOptions.addAction(self.actionParametres_Eficas)
251 self.menuOptions.setTitle(tr("Options"))
254 def ChercheGrpMesh(self):
255 Msg,listeGroup=self.ChercheGrpMeshInSalome()
257 self.viewmanager.handleAjoutGroup(listeGroup)
259 print "il faut gerer les erreurs"
261 def ChercheGrpMaille(self):
262 Msg,listeGroup=self.ChercheGrpMailleInSalome()
264 self.viewmanager.handleAjoutGroup(listeGroup)
266 print "il faut gerer les erreurs"
268 def ChercheGrp(self):
269 #Msg,listeGroup=self.ChercheGrpMailleInSalome()
271 # self.viewmanager.handleAjoutGroup(listeGroup)
273 print "il faut gerer "
276 def ajoutIcones(self) :
277 # Pour pallier les soucis de repertoire d icone
278 icon = QIcon(self.repIcon+"/New24.png")
279 self.action_Nouveau.setIcon(icon)
280 icon1 = QIcon(self.repIcon+"/Open24.png")
281 self.action_Ouvrir.setIcon(icon1)
282 icon2 = QIcon(self.repIcon+"/Save24.png")
283 self.actionEnregistrer.setIcon(icon2)
284 icon3 = QIcon(self.repIcon+"/Cut24.png")
285 self.actionCouper.setIcon(icon3)
286 icon4 = QIcon(self.repIcon+"/Copy24.png")
287 self.actionCopier.setIcon(icon4)
288 icon5 = QIcon(self.repIcon+"/Paste24.png")
289 self.actionColler.setIcon(icon5)
290 icon6 = QIcon(self.repIcon+"/Delete24.png")
291 self.actionSupprimer.setIcon(icon6)
295 def connecterSignaux(self) :
296 self.connect(self.recentMenu,SIGNAL('aboutToShow()'),self.handleShowRecentMenu)
298 self.connect(self.action_Nouveau,SIGNAL("activated()"),self.fileNew)
299 self.connect(self.actionNouvel_Include,SIGNAL("activated()"),self.NewInclude)
300 self.connect(self.action_Ouvrir,SIGNAL("activated()"),self.fileOpen)
301 self.connect(self.actionEnregistrer,SIGNAL("activated()"),self.fileSave)
302 self.connect(self.actionEnregistrer_sous,SIGNAL("activated()"),self.fileSaveAs)
303 self.connect(self.actionFermer,SIGNAL("activated()"),self.fileClose)
304 self.connect(self.actionFermer_tout,SIGNAL("activated()"),self.fileCloseAll)
305 self.connect(self.actionQuitter,SIGNAL("activated()"),self.fileExit)
307 self.connect(self.actionEficas,SIGNAL("activated()"),self.aidePPal)
308 self.connect(self.actionVersion,SIGNAL("activated()"),self.version)
310 self.connect(self.actionCouper,SIGNAL("activated()"),self.editCut)
311 self.connect(self.actionCopier,SIGNAL("activated()"),self.editCopy)
312 self.connect(self.actionColler,SIGNAL("activated()"),self.editPaste)
313 self.connect(self.actionSupprimer,SIGNAL("activated()"),self.supprimer)
314 self.connect(self.actionRechercher,SIGNAL("activated()"),self.rechercher)
315 self.connect(self.actionDeplier_replier,SIGNAL("activated()"),self.Deplier)
317 self.connect(self.actionRapport_de_Validation,SIGNAL("activated()"),self.jdcRapport)
318 self.connect(self.actionFichier_Source,SIGNAL("activated()"),self.jdcFichierSource)
319 self.connect(self.actionFichier_Resultat,SIGNAL("activated()"),self.visuJdcPy)
322 #self.connect(self.helpIndexAction,SIGNAL("activated()"),self.helpIndex)
323 #self.connect(self.helpContentsAction,SIGNAL("activated()"),self.helpContents)
326 self.actionTraduitV7V8 = QAction(self)
327 self.actionTraduitV7V8.setObjectName("actionTraduitV7V8")
328 self.actionTraduitV8V9 = QAction(self)
329 self.actionTraduitV8V9.setObjectName("actionTraduitV8V9")
330 self.actionTraduitV9V10 = QAction(self)
331 self.actionTraduitV9V10.setObjectName("actionTraduitV9V10")
332 self.actionTraduitV7V8.setText(tr("TraduitV7V8"))
333 self.actionTraduitV8V9.setText(tr("TraduitV8V9"))
334 self.actionTraduitV9V10.setText(tr("TraduitV9V10"))
335 self.connect(self.actionParametres_Eficas,SIGNAL("activated()"),self.optionEditeur)
336 self.connect(self.actionLecteur_Pdf,SIGNAL("activated()"),self.optionPdf)
337 self.connect(self.actionTraduitV7V8,SIGNAL("activated()"),self.traductionV7V8)
338 self.connect(self.actionTraduitV8V9,SIGNAL("activated()"),self.traductionV8V9)
339 self.connect(self.actionTraduitV9V10,SIGNAL("activated()"),self.traductionV9V10)
342 self.actionChercheGrpMaille = QAction(self)
343 self.actionChercheGrpMaille.setText(tr("Acquiert Groupe Maille"))
344 self.connect(self.actionChercheGrpMaille,SIGNAL("activated()"),self.ChercheGrpMaille)
347 self.actionChercheGrp = QAction(self)
348 self.actionChercheGrp.setText(tr("Accquisition Groupe Maille"))
349 self.connect(self.actionChercheGrp,SIGNAL("activated()"),self.ChercheGrp)
352 self.actionCode = QAction(self)
353 self.actionCode.setText(tr("Specificites Maille"))
354 self.connect(self.actionCode,SIGNAL("activated()"),self.aideCode)
357 self.viewmanager.handleDeplier()
359 def ouvreFichiers(self) :
360 # Ouverture des fichiers de commandes donnes sur la ligne de commande
363 for study in session.d_env.studies:
365 d=session.get_unit(study,self)
366 self.viewmanager.handleOpen(fichier=study["comm"],units=d)
369 def get_source(self,file):
370 # appele par Editeur/session.py
372 p=convert.plugins['python']()
374 texte=p.convert('execnoparseur')
377 def initPatrons(self) :
378 # Mise a jour du menu des fichiers recemment ouverts
379 from Editeur import listePatrons
380 if not(self.code in listePatrons.sous_menus.keys()) :
381 if hasattr(self,"menuPatrons"):
382 self.menuPatrons.setAttribute(Qt.WA_DeleteOnClose)
383 self.menuPatrons.close()
384 delattr(self,"menuPatrons")
386 if (not hasattr(self,"menuPatrons")):
387 self.menuPatrons = QMenu(self.menubar)
388 self.menuPatrons.setObjectName("menuPatrons")
389 self.menubar.addAction(self.menuPatrons.menuAction())
390 self.menuPatrons.setTitle(QApplication.translate("Eficas", "Patrons", None, QApplication.UnicodeUTF8))
392 self.menuPatrons.clear()
393 self.listePatrons = listePatrons.listePatrons(self.code)
395 for nomSsMenu in self.listePatrons.liste.keys():
396 ssmenu=self.menuPatrons.addMenu(nomSsMenu)
397 for fichier in self.listePatrons.liste[nomSsMenu]:
398 id = ssmenu.addAction(fichier)
399 self.ficPatrons[id]=fichier
400 self.connect(id, SIGNAL('triggered()'),self.handleOpenPatrons)
401 # self.Patrons.setItemParameter(id,idx)
404 def initRecents(self):
405 self.recent = QStringList()
408 rep=os.path.join(os.environ['HOME'],'.config/Eficas',self.code)
409 monFichier=rep+"/listefichiers_"+self.code
415 l=(ligne.split("\n"))[0]
416 self.recent.append(l)
425 def addToRecentList(self, fn):
427 Public slot to add a filename to the list of recently opened files.
429 @param fn name of the file to be added
431 self.recent.removeAll(fn)
432 self.recent.prepend(fn)
433 if len(self.recent) > 9:
434 self.recent = self.recent[:9]
436 def sauveRecents(self) :
438 rep=self.CONFIGURATION.rep_user
439 monFichier=rep+"/listefichiers_"+self.code
443 f=open(monFichier,'w')
444 if len(self.recent) == 0 : return
446 while ( index < len(self.recent)):
447 ligne=str(self.recent[index])+"\n"
459 def traductionV7V8(self):
460 from gereTraduction import traduction
461 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V7V8")
463 def traductionV8V9(self):
464 from gereTraduction import traduction
465 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V8V9")
467 def traductionV9V10(self):
468 from gereTraduction import traduction
469 traduction(self.CONFIGURATION.repIni,self.viewmanager,"V9V10")
472 from monVisu import DVisu
473 titre = tr("version ")
474 monVisuDialg=DVisu(parent=self,fl=0)
475 monVisuDialg.setWindowTitle(titre)
476 monVisuDialg.TB.setText(self.VERSION_EFICAS +tr(" pour ") + self.code)
477 monVisuDialg.adjustSize()
481 if self.code==None : return
482 repAide=os.path.dirname(os.path.abspath(__file__))
483 maD=repAide+"/../Aide"
485 indexAide=maD+"/fichiers_EFICAS/index.html"
486 cmd="xdg-open "+indexAide
489 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
493 if self.code==None : return
496 cmd="xdg-open "+self.fileDoc
500 QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
503 def optionEditeur(self) :
505 name='monOptions_'+self.code
507 QMessageBox.critical( self,tr( "Parametrage"),tr( "Veuillez d abord choisir un code"))
511 optionCode=__import__(name)
514 QMessageBox.critical( self, tr("Parametrage"), tr("Pas de possibilite de personnalisation de la configuration "))
516 monOption=optionCode.Options(parent=self,modal = 0 ,configuration=self.CONFIGURATION)
519 def optionPdf(self) :
520 from monOptionsPdf import OptionPdf
521 monOption=OptionPdf(parent=self,modal = 0 ,configuration=self.CONFIGURATION)
524 def handleShowRecentMenu(self):
526 Private method to set up recent files menu.
528 self.recentMenu.clear()
530 for rp in self.recent:
531 id = self.recentMenu.addAction(rp)
532 self.ficRecents[id]=rp
533 self.connect(id, SIGNAL('triggered()'),self.handleOpenRecent)
534 self.recentMenu.addSeparator()
535 self.recentMenu.addAction(tr('&Effacer'), self.handleClearRecent)
537 def handleOpenPatrons(self):
539 fichier=self.repIni+"/../Editeur/Patrons/"+self.code+"/"+self.ficPatrons[idx]
540 self.viewmanager.handleOpen(fichier=fichier, patron = 1)
542 def handleOpenRecent(self):
544 fichier=self.ficRecents[idx]
545 self.viewmanager.handleOpen(fichier=fichier, patron =0 )
547 def handleClearRecent(self):
548 self.recent = QStringList()
553 self.viewmanager.newEditor()
554 except EficasException, exc:
557 QMessageBox.warning(self, tr(u"Erreur"), msg)
561 self.viewmanager.handleOpen()
562 except EficasException, exc:
565 QMessageBox.warning(self, tr(u"Erreur"), msg)
568 return self.viewmanager.saveCurrentEditor()
570 def fileSaveAs(self):
571 return self.viewmanager.saveAsCurrentEditor()
574 self.viewmanager.handleClose(texte='&Fermer')
576 def fileCloseAll(self):
577 self.viewmanager.handleCloseAll(texte='&Fermer')
580 # On peut sortir sur Abort
581 res=self.viewmanager.handleCloseAll()
587 self.viewmanager.handleEditCopy()
590 self.viewmanager.handleEditCut()
593 self.viewmanager.handleEditPaste()
595 def rechercher(self):
596 self.viewmanager.handleRechercher()
599 self.viewmanager.run()
602 self.viewmanager.saveRun()
606 self.viewmanager.handleSupprimer()
608 def jdcFichierSource(self):
609 self.viewmanager.handleViewJdcFichierSource()
611 def jdcRapport(self):
612 self.viewmanager.handleViewJdcRapport()
615 self.viewmanager.handleViewJdcPy()
618 def NewInclude(self):
619 self.viewmanager.newIncludeEditor()
622 for pathCode in self.ListeCode:
624 aEnlever=os.path.abspath(os.path.join(os.path.dirname(__file__),'..',pathCode))
625 sys.path.remove(aEnlever)
628 for pathCode in self.listeAEnlever:
630 sys.path.remove(aEnlever)
635 def closeEvent(self,event):
637 if res==2 : event.ignore()
639 if __name__=='__main__':
642 rep=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__),'..','ASTER')))
644 from Aster import prefsCode
645 if hasattr(prefsCode,'encoding'):
646 # Hack pour changer le codage par defaut des strings
649 sys.setdefaultencoding(prefsCode.encoding)
650 del sys.setdefaultencoding
653 from Editeur import import_code
654 from Editeur import session
656 # Analyse des arguments de la ligne de commande
657 options=session.parse(sys.argv)
661 app = QApplication(sys.argv)
662 #app.setMainWidget(mw) (qt3)
666 #app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))