]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/qtEficas.py
Salome HOME
reindent + copyright + merge manuel avec la V9_dev sauf repertoires metier
[tools/eficas.git] / InterfaceQT4 / qtEficas.py
1 #!/usr/bin/env python
2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2021   EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 from __future__ import absolute_import
23 from __future__ import print_function
24 try :
25     from builtins import str
26 except : pass
27
28 import os, sys
29
30
31 from PyQt5.QtWidgets import QApplication, QMainWindow, QGridLayout, QBoxLayout, QMenu, QAction, QMessageBox
32 from PyQt5.QtGui import QIcon
33 from PyQt5.QtCore import Qt, QSize
34
35
36 from Editeur import session
37 from myMain import Ui_Eficas
38 from InterfaceQT4.viewManager import MyViewManager
39 from InterfaceQT4.qtEficasSsIhm import AppliSsIhm
40
41 from Extensions.i18n import tr
42 from Extensions.eficas_exception import EficasException
43 from Extensions import param2
44
45
46 class Appli(AppliSsIhm,Ui_Eficas,QMainWindow):
47     """
48     Class implementing the main user interface.
49     """
50     def __init__(self,code=None,salome=1,parent=None, multi=False,langue='en',ssIhm=False, labelCode=None):
51         """
52         Constructor
53         """
54         if ssIhm == True :
55             print ('mauvaise utilisation de la classe Appli. Utiliser AppliSsIm SVP')
56             exit()
57
58         AppliSsIhm.__init__(self,code,salome,parent,multi=multi,langue=langue,ssIhm=True, labelCode=labelCode)
59         QMainWindow.__init__(self,parent)
60         Ui_Eficas.__init__(self)
61
62         self.ssIhm=False
63         self.multi=multi
64         self.demande=multi # voir PSEN
65
66
67         if self.multi == False :
68             self.definitCode(code,None)
69             if code==None: return
70         else :
71             self.definitCode(code,None)
72             if code==None: return
73             print ('il faut trouver le chemin du code')
74             return
75
76         self.suiteTelemac=False
77         if hasattr (self, 'maConfiguration') :
78             if self.maConfiguration.demandeLangue :
79                 from InterfaceQT4.monChoixLangue import MonChoixLangue
80                 widgetLangue = MonChoixLangue(self)
81                 ret=widgetLangue.exec_()
82             self.suiteTelemac=self.maConfiguration.suiteTelemac
83
84
85         if not self.salome and hasattr (self, 'maConfiguration') and hasattr(self.maConfiguration,'lang') : self.langue=self.maConfiguration.lang
86         from Extensions import localisation
87         app=QApplication
88         if hasattr (self, 'maConfiguration') : localisation.localise(None,self.langue,translatorFichier=self.maConfiguration.translatorFichier)
89         self.setupUi(self)
90
91         #if parent != None : self.parentCentralWidget = parent.centralWidget()
92         #else              : self.parentCentralWidget = None
93
94         if not self.salome :
95             if  hasattr (self, 'maConfiguration') and hasattr(self.maConfiguration,'taille') : self.taille=self.maConfiguration.taille
96             else : self.taille=1700
97
98             self.resize(self.taille,self.height())
99
100
101         icon = QIcon(self.repIcon+"/parametres.png")
102         self.actionParametres.setIcon(icon)
103         if  hasattr (self, 'maConfiguration') and self.maConfiguration.boutonDsMenuBar  :
104             self.frameEntete.setMaximumSize(QSize(16777215,100))
105             self.frameEntete.setMinimumSize(QSize(0,100))
106         if  hasattr (self, 'maConfiguration') and self.maConfiguration.enleverActionStructures  :
107             self.enleverActionsStructures()
108         if  hasattr (self, 'maConfiguration') and self.maConfiguration.enleverParametres  :
109             self.enleverParametres()
110         if  hasattr (self, 'maConfiguration') and self.maConfiguration.enleverSupprimer :
111             self.enleverSupprimer()
112
113
114         self.myQtab.removeTab(0)
115         self.blEnteteGlob = QBoxLayout(2,self.frameEntete)
116         self.blEnteteGlob.setSpacing(0)
117         self.blEnteteGlob.setContentsMargins(0,0,0,0)
118
119         self.blEntete = QBoxLayout(0)
120         self.blEntete.insertWidget(0,self.toolBar)
121         self.blEntete.insertWidget(0,self.menubar)
122         self.blEnteteGlob.insertLayout(0,self.blEntete)
123
124
125
126         if  hasattr (self, 'maConfiguration') and self.maConfiguration.boutonDsMenuBar  :
127             self.blEnteteCommmande = QBoxLayout(0)
128             self.blEnteteCommmande.insertWidget(0,self.toolBarCommande)
129             self.toolBarCommande.setIconSize(QSize(96,96))
130             self.blEnteteGlob.insertLayout(-1,self.blEnteteCommmande)
131         else :
132             self.toolBarCommande.close()
133
134
135         if hasattr (self, 'maConfiguration') and self.maConfiguration.closeEntete==True and self.salome: self.closeEntete()
136
137         eficas_root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
138
139         self.viewmanager = MyViewManager(self)
140         self.recentMenu=QMenu(tr('&Recents'))
141         #self.menuFichier.insertMenu(self.actionOuvrir,self.recentMenu)
142
143         # actionARemplacer ne sert que pour l insert Menu
144         self.menuFichier.insertMenu(self.actionARemplacer ,self.recentMenu)
145         self.menuFichier.removeAction(self.actionARemplacer)
146         self.connecterSignaux()
147         self.toolBar.addSeparator()
148
149
150         if self.code != None : self.construitMenu()
151
152         self.setWindowTitle(self.VERSION_EFICAS)
153         try :
154         #if 1 :
155          #print ('attention try devient if 1')
156             self.ouvreFichiers()
157         except EficasException as exc:
158         #except:
159             print ("je suis dans le except")
160             if self.salome == 0 : exit()
161
162         #self.adjustSize()
163
164     def closeEntete(self):
165         self.menuBar().close()
166         self.toolBar.close()
167         self.frameEntete.close()
168
169     def definitCode(self,code,ssCode) :
170         self.code=code
171         self.ssCode=ssCode
172         if self.code==None :
173             self.cleanPath()
174             from InterfaceQT4.monChoixCode import MonChoixCode
175             widgetChoix = MonChoixCode(self)
176             ret=widgetChoix.exec_()
177             #widgetChoix.show()
178         if self.code == None:return # pour le cancel de la fenetre choix code
179         AppliSsIhm.definitCode(self,self.code,ssCode)
180
181         #PN --> pb d exception qui font planter salome
182         # plus supporte en python 3
183         #app=QApplication
184         #if hasattr(prefsCode,'encoding'):
185         #   import sys
186         #   reload(sys)
187         #   sys.setdefaultencoding(prefsCode.encoding)
188
189     def construitMenu(self):
190         self.initPatrons()
191         self.initRecents()
192         self.initAides()
193         for intituleMenu in ("menuTraduction","menuOptions","menuMesh","menuExecution","menuN1"):
194             if hasattr(self,intituleMenu):
195                 menu=getattr(self,intituleMenu)
196                 menu.setAttribute(Qt.WA_DeleteOnClose)
197                 menu.close()
198                 delattr(self,intituleMenu)
199         for intituleAction in ("actionExecution","actionSaveRun"):
200             if hasattr(self,intituleAction):
201                 action=getattr(self,intituleAction)
202                 self.toolBar.removeAction(action)
203         if self.code.upper() in Appli.__dict__:
204             Appli.__dict__[self.code.upper()](self,)
205         if self.suiteTelemac : self.lookSuiteTelemac()
206         self.metMenuAJourUtilisateurs()
207         if  hasattr (self, 'maConfiguration') and self.maConfiguration.ajoutExecution :
208             self.ajoutExecution()
209
210     def initAides(self):
211         #print "je passe la"
212         repAide=os.path.dirname(os.path.abspath(__file__))
213         fileName='index.html'
214         self.docPath=repAide+"/../Aide"
215         if hasattr(self,'maConfiguration') and hasattr(self.maConfiguration,'docPath') : self.docPath=self.maConfiguration.docPath
216         if hasattr(self,'maConfiguration') and hasattr(self.maConfiguration,'fileName'):fileName=self.maConfiguration.fileName
217         self.fileDoc=os.path.join(self.docPath,fileName)
218         self.actionCode.setText(tr("Aide specifique ")+str(self.code))
219         if not os.path.isfile(self.fileDoc) :
220             self.fileDoc=""
221             self.docPath=""
222             self.actionCode.setEnabled(False)
223             return
224
225         self.actionCode.setEnabled(True)
226         self.menuAide.addAction(self.actionCode)
227
228     def newN1(self):
229         ssCode=None
230         code="PSEN_N1"
231         self.cleanPath()
232         dirCode=os.path.abspath(os.path.join(os.path.abspath(__file__),'../..',"ProcessOutputs_Eficas"))
233         sys.path.insert(0,dirCode)
234         self.code=code
235         self.definitCode(code,ssCode)
236         self.initRecents()
237         self.multi=True
238         self.demande=False
239         self.fileNew()
240
241     def newPSEN(self):
242         ssCode=None
243         code="PSEN"
244         self.cleanPath()
245         dirCode=os.path.abspath(os.path.join(os.path.abspath(__file__),'../..',code))
246         sys.path.insert(0,dirCode)
247         self.code=code
248         self.definitCode(code,ssCode)
249         self.multi=True
250         self.demande=False
251         self.fileNew()
252
253     def ajoutN1(self):
254         return
255         self.menuN1 = self.menubar.addMenu(tr("Process Output"))
256         self.actionN1 = QAction(self)
257         self.actionN1.setText(tr("Process Output"))
258         self.menuN1.addAction(self.actionN1)
259         self.actionN1.triggered.connect(self.newN1)
260
261
262         if hasattr(self,'actionOpenProcess'):return
263
264         self.actionOpenProcess = QAction(self)
265         self.actionOpenProcess.setText(tr("Open Process_Output File"))
266         self.menuN1.addAction(self.actionOpenProcess)
267         self.actionOpenProcess.triggered.connect(self.openProcess)
268
269     def ajoutExecution(self):
270         self.menuExecution = self.menubar.addMenu(tr("&Run"))
271         self.actionExecution = QAction(self)
272         if sys.platform[0:5]=="linux":
273             icon6 = QIcon(self.repIcon+"/roue.png")
274             self.actionExecution.setIcon(icon6)
275         else :
276             self.actionExecution.setText(tr("Run"))
277         self.actionExecution.setObjectName("actionExecution")
278         self.menuExecution.addAction(self.actionExecution)
279         if not(self.actionExecution in self.toolBar.actions()):
280             self.toolBar.addAction(self.actionExecution)
281         self.actionExecution.setText(tr("Run"))
282         self.actionExecution.triggered.connect(self.run)
283
284     def ajoutSauveExecution(self):
285         self.actionSaveRun = QAction(self)
286         icon7 = QIcon(self.repIcon+"/export_MAP.png")
287         self.actionSaveRun.setIcon(icon7)
288         self.actionSaveRun.setObjectName("actionSaveRun")
289         self.menuExecution.addAction(self.actionSaveRun)
290         if not(self.actionSaveRun in self.toolBar.actions()):
291             self.toolBar.addAction(self.actionSaveRun)
292         self.actionSaveRun.setText(tr("Save Run"))
293         self.actionSaveRun.triggered.connect(self.saveRun)
294
295     def griserActionsStructures(self):
296         self.actionCouper.setEnabled(False)
297         self.actionColler.setEnabled(False)
298         self.actionCopier.setEnabled(False)
299         self.actionSupprimer.setEnabled(False)
300
301     def enleverActionsStructures(self):
302         self.toolBar.removeAction(self.actionCopier)
303         self.toolBar.removeAction(self.actionColler)
304         self.toolBar.removeAction(self.actionCouper)
305         self.menuEdition.removeAction(self.actionCouper)
306         self.menuEdition.removeAction(self.actionCopier)
307         self.menuEdition.removeAction(self.actionColler)
308
309
310     def enleverParametres(self):
311         self.toolBar.removeAction(self.actionParametres)
312         self.menuJdC.removeAction(self.actionParametres)
313
314     def enleverSupprimer(self):
315         self.toolBar.removeAction(self.actionSupprimer)
316
317     def enlevernewInclude(self):
318         self.actionNouvel_Include.setVisible(False)
319
320     def enleverRechercherDsCatalogue(self):
321         self.actionRechercherDsCatalogue.setVisible(False)
322
323     def connectRechercherDsCatalogue(self):
324         if hasattr(self,'rechercherDejaLa') : return
325         self.rechercherDejaLa=True
326         self.actionRechercherDsCatalogue.triggered.connect(self.handleRechercherDsCatalogue)
327
328     def ajoutSortieComplete(self):
329         if hasattr(self,'actionSortieComplete') : return
330         self.actionSortieComplete = QAction(self)
331         self.actionSortieComplete.setText(tr("Sortie Complete"))
332         self.menuFichier.insertAction(self.actionEnregistrer_sous,self.actionSortieComplete)
333         self.actionSortieComplete.triggered.connect(self.handleSortieComplete)
334
335
336     def MT(self):
337         self.enlevernewInclude()
338         self.toolBar.addSeparator()
339
340
341     def ZCRACKS(self):
342         self.enlevernewInclude()
343         self.toolBar.addSeparator()
344         self.ajoutExecution()
345
346         self.menuOptions = self.menubar.addMenu("menuOptions")
347         self.menuOptions.addAction(self.actionParametres_Eficas)
348         self.menuOptions.setTitle(tr("Options"))
349
350     def ADAO(self):
351         self.enleverActionsStructures()
352         self.enlevernewInclude()
353
354     def ASTER(self) :
355         self.menuTraduction = self.menubar.addMenu("menuTraduction")
356         self.menuTraduction.addAction(self.actionTraduitV11V12)
357         self.menuTraduction.addAction(self.actionTraduitV10V11)
358         self.menuTraduction.addAction(self.actionTraduitV9V10)
359         self.menuTraduction.setTitle(tr("Traduction"))
360
361         self.menuFichier.addAction(self.actionSauveLigne)
362
363         self.menuOptions = self.menubar.addMenu("menuOptions")
364         self.menuOptions.addAction(self.actionParametres_Eficas)
365         self.menuOptions.addAction(self.actionLecteur_Pdf)
366         self.menuOptions.setTitle(tr("Options"))
367
368     def CARMEL3D(self):
369         #if self.salome == 0 : return
370         self.enlevernewInclude()
371         self.menuMesh = self.menubar.addMenu(tr("Gestion Maillage"))
372         self.menuMesh.setObjectName("Mesh")
373         self.menuMesh.addAction(self.actionChercheGrpMaille)
374         #self.griserActionsStructures()
375
376     def CARMELCND(self):
377         self.enlevernewInclude()
378         self.enleverRechercherDsCatalogue()
379         self.ajoutExecution()
380         self.ajoutSauveExecution()
381         self.griserActionsStructures()
382
383     def MAP(self):
384         self.enlevernewInclude()
385         self.toolBar.addSeparator()
386         self.ajoutExecution()
387         self.ajoutSauveExecution()
388         self.menuOptions = self.menubar.addMenu("menuOptions")
389         self.menuOptions.addAction(self.actionParametres_Eficas)
390         self.menuOptions.setTitle(tr("Options"))
391
392     def MAPIDENTIFICATION(self):
393         self.enlevernewInclude()
394         self.enleverSupprimer()
395         #self.ajoutExecution()
396         self.enleverRechercherDsCatalogue()
397         self.enleverActionsStructures()
398         self.enleverParametres()
399
400     def PSEN(self):
401         try : self.action_Nouveau.triggered.disconnect(self.fileNew)
402         except : pass
403         try : self.action_Nouveau.triggered.disconnect(self.newPSEN)
404         except : pass
405
406         self.action_Nouveau.triggered.connect(self.newPSEN)
407         self.enleverActionsStructures()
408         self.enleverParametres()
409         self.enleverRechercherDsCatalogue()
410         self.enlevernewInclude()
411         self.ajoutExecution()
412         self.ajoutN1()
413         self.ajoutHelpPSEN()
414         self.ajoutIcones()
415
416     def PSEN_N1(self):
417         self.enleverActionsStructures()
418         self.enleverParametres()
419         self.enleverRechercherDsCatalogue()
420         self.enlevernewInclude()
421         self.ajoutExecution()
422         self.ajoutIcones()
423
424     def TELEMAC(self):
425         self.enleverActionsStructures()
426         self.enlevernewInclude()
427         self.connectRechercherDsCatalogue()
428         self.ajoutSortieComplete()
429
430     def lookSuiteTelemac(self):
431         self.enleverActionsStructures()
432         self.enlevernewInclude()
433         self.enleverParametres()
434         self.enleverSupprimer()
435         self.enleverRechercherDsCatalogue()
436
437     def ajoutHelpPSEN(self):
438         self.actionParametres_Eficas.setText('Help PSEN')
439         self.actionParametres_Eficas.triggered.connect(self.aidePSEN)
440
441
442
443     def ChercheGrpMesh(self):
444         Msg,listeGroup=self.ChercheGrpMeshInSalome()
445         if Msg == None :
446             self.viewmanager.handleAjoutGroup(listeGroup)
447         else :
448             print ("il faut gerer les erreurs")
449
450     def ChercheGrpMaille(self):
451         # Normalement la variable self.salome permet de savoir si on est ou non dans Salome
452         try:
453             Msg,listeGroup=self.ChercheGrpMailleInSalome() # recherche dans Salome
454             #Msg = None; listeGroup = None # recherche manuelle, i.e., sans Salome si ligne precedente commentee
455         except:
456             raise ValueError('Salome non ouvert')
457         if Msg == None :
458             self.viewmanager.handleAjoutGroup(listeGroup)
459         else :
460             print ("il faut gerer les erreurs")
461
462
463     def ChercheGrp(self):
464         #Msg,listeGroup=self.ChercheGrpMailleInSalome()
465         #if Msg == None :
466         #   self.viewmanager.handleAjoutGroup(listeGroup)
467         #else :
468         #print "il faut gerer "
469         pass
470
471
472     def ajoutIcones(self) :
473         # Pour pallier les soucis de repertoire d icone
474         #print self.repIcon
475         icon = QIcon(self.repIcon+"/new_file.png")
476         self.action_Nouveau.setIcon(icon)
477         icon1 = QIcon(self.repIcon+"/ouvrir.png")
478         self.actionOuvrir.setIcon(icon1)
479         icon2 = QIcon(self.repIcon+"/save.png")
480         self.actionEnregistrer.setIcon(icon2)
481         icon6 = QIcon(self.repIcon+"/delete.png")
482         self.actionSupprimer.setIcon(icon6)
483         icon7 = QIcon(self.repIcon+"/roue.png")
484         self.actionExecution.setIcon(icon7)
485
486
487
488
489     def connecterSignauxQT4(self) :
490         self.connect(self.recentMenu,SIGNAL('aboutToShow()'),self.handleShowRecentMenu)
491
492         self.connect(self.action_Nouveau,SIGNAL("triggered()"),self.fileNew)
493         self.connect(self.actionNouvel_Include,SIGNAL("triggered()"),self.newInclude)
494         self.connect(self.actionOuvrir,SIGNAL("triggered()"),self.fileOpen)
495         self.connect(self.actionEnregistrer,SIGNAL("triggered()"),self.fileSave)
496         self.connect(self.actionEnregistrer_sous,SIGNAL("triggered()"),self.fileSaveAs)
497         self.connect(self.actionFermer,SIGNAL("triggered()"),self.fileClose)
498         self.connect(self.actionFermer_tout,SIGNAL("triggered()"),self.fileCloseAll)
499         self.connect(self.actionQuitter,SIGNAL("triggered()"),self.fileExit)
500
501         self.connect(self.actionEficas,SIGNAL("triggered()"),self.aidePPal)
502         self.connect(self.actionVersion,SIGNAL("triggered()"),self.version)
503         self.connect(self.actionParametres,SIGNAL("triggered()"),self.gestionParam)
504
505         self.connect(self.actionCouper,SIGNAL("triggered()"),self.editCut)
506         self.connect(self.actionCopier,SIGNAL("triggered()"),self.editCopy)
507         self.connect(self.actionColler,SIGNAL("triggered()"),self.editPaste)
508         self.connect(self.actionSupprimer,SIGNAL("triggered()"),self.supprimer)
509         self.connect(self.actionRechercher,SIGNAL("triggered()"),self.rechercher)
510         self.connect(self.actionDeplier_replier,SIGNAL("triggered()"),self.handleDeplier)
511
512         self.connect(self.actionRapport_de_Validation,SIGNAL("triggered()"),self.jdcRapport)
513         self.connect(self.actionRegles_du_JdC,SIGNAL("triggered()"),self.jdcRegles)
514         self.connect(self.actionFichier_Source,SIGNAL("triggered()"),self.jdcFichierSource)
515         self.connect(self.actionFichier_Resultat,SIGNAL("triggered()"),self.visuJdcPy)
516
517
518
519
520         # Pour Aster
521         self.actionTraduitV9V10 = QAction(self)
522         self.actionTraduitV9V10.setObjectName("actionTraduitV9V10")
523         self.actionTraduitV9V10.setText(tr("TraduitV9V10"))
524         self.actionTraduitV10V11 = QAction(self)
525         self.actionTraduitV10V11.setObjectName("actionTraduitV10V11")
526         self.actionTraduitV10V11.setText(tr("TraduitV10V11"))
527         self.actionTraduitV11V12 = QAction(self)
528         self.actionTraduitV11V12.setObjectName("actionTraduitV11V12")
529         self.actionTraduitV11V12.setText(tr("TraduitV11V12"))
530         self.actionSauveLigne = QAction(self)
531         self.actionSauveLigne.setText(tr("Sauve Format Ligne"))
532
533         #self.connect(self.actionParametres_Eficas,SIGNAL("triggered()"),self.optionEditeur)
534         self.connect(self.actionLecteur_Pdf,SIGNAL("triggered()"),self.optionPdf)
535         self.connect(self.actionTraduitV9V10,SIGNAL("triggered()"),self.traductionV9V10)
536         self.connect(self.actionTraduitV10V11,SIGNAL("triggered()"),self.traductionV10V11)
537         self.connect(self.actionTraduitV11V12,SIGNAL("triggered()"),self.traductionV11V12)
538         self.connect(self.actionSauveLigne,SIGNAL("triggered()"),self.sauveLigne)
539
540
541         # Pour Carmel
542         self.actionChercheGrpMaille = QAction(self)
543         self.actionChercheGrpMaille.setText(tr("Acquiert groupe mailles"))
544         self.connect(self.actionChercheGrpMaille,SIGNAL("triggered()"),self.ChercheGrpMaille)
545
546         # Pour CarmelCND
547         self.actionChercheGrp = QAction(self)
548         self.actionChercheGrp.setText(tr("Acquisition Groupe Maille"))
549         self.connect(self.actionChercheGrp,SIGNAL("triggered()"),self.ChercheGrp)
550
551         # Pour Aide
552         self.actionCode = QAction(self)
553         self.actionCode.setText(tr("Specificites Maille"))
554         self.connect(self.actionCode,SIGNAL("triggered()"),self.aideCode)
555
556     def connecterSignaux(self) :
557
558         self.recentMenu.aboutToShow.connect(self.handleShowRecentMenu)
559         self.action_Nouveau.triggered.connect(self.fileNew)
560         self.actionNouvel_Include.triggered.connect(self.newInclude)
561         self.actionOuvrir.triggered.connect(self.fileOpen)
562         self.actionEnregistrer.triggered.connect(self.fileSave)
563         self.actionEnregistrer_sous.triggered.connect(self.fileSaveAs)
564         self.actionFermer.triggered.connect(self.fileClose)
565         self.actionFermer_tout.triggered.connect(self.fileCloseAll)
566         self.actionQuitter.triggered.connect(self.fileExit)
567
568         self.actionEficas.triggered.connect(self.aidePPal)
569         self.actionVersion.triggered.connect(self.version)
570         self.actionParametres.triggered.connect(self.gestionParam)
571         self.actionCommentaire.triggered.connect(self.ajoutCommentaire)
572
573         self.actionCouper.triggered.connect(self.editCut)
574         self.actionCopier.triggered.connect(self.editCopy)
575         self.actionColler.triggered.connect(self.editPaste)
576         self.actionSupprimer.triggered.connect(self.supprimer)
577         self.actionRechercher.triggered.connect(self.rechercher)
578         self.actionDeplier_replier.triggered.connect(self.handleDeplier)
579
580         self.actionRapport_de_Validation.triggered.connect(self.jdcRapport)
581         self.actionRegles_du_JdC.triggered.connect(self.jdcRegles)
582         self.actionFichier_Source.triggered.connect(self.jdcFichierSource)
583         self.actionFichier_Resultat.triggered.connect(self.visuJdcPy)
584         self.actionAfficher_l_Arbre.triggered.connect(self.ouvreArbre)
585         self.actionCacher_l_Arbre.triggered.connect(self.fermeArbre)
586
587
588         # Pour Aster
589         self.actionTraduitV9V10 = QAction(self)
590         self.actionTraduitV9V10.setObjectName("actionTraduitV9V10")
591         self.actionTraduitV9V10.setText(tr("TraduitV9V10"))
592         self.actionTraduitV10V11 = QAction(self)
593         self.actionTraduitV10V11.setObjectName("actionTraduitV10V11")
594         self.actionTraduitV10V11.setText(tr("TraduitV10V11"))
595         self.actionTraduitV11V12 = QAction(self)
596         self.actionTraduitV11V12.setObjectName("actionTraduitV11V12")
597         self.actionTraduitV11V12.setText(tr("TraduitV11V12"))
598         self.actionSauveLigne = QAction(self)
599         self.actionSauveLigne.setText(tr("Sauve Format Ligne"))
600
601         #self.actionParametres_Eficas.triggered.connect(self.optionEditeur)
602         self.actionTraduitV9V10.triggered.connect(self.traductionV9V10)
603         self.actionTraduitV10V11.triggered.connect(self.traductionV10V11)
604         self.actionTraduitV11V12.triggered.connect(self.traductionV11V12)
605         self.actionSauveLigne.triggered.connect(self.sauveLigne)
606
607         # Pour Carmel
608         self.actionChercheGrpMaille = QAction(self)
609         self.actionChercheGrpMaille.setText(tr("Acquiert Groupe Maille"))
610
611         # Pour CarmelCND
612         self.actionChercheGrp = QAction(self)
613         self.actionChercheGrp.setText(tr("Accquisition Groupe Maille"))
614         self.actionChercheGrp.triggered.connect(self.ChercheGrp)
615
616         # Pour Aide
617         self.actionCode = QAction(self)
618         self.actionCode.setText(tr("Specificites Maille"))
619         self.actionCode.triggered.connect(self.aideCode)
620
621
622     def handleDeplier(self):
623         self.viewmanager.handleDeplier()
624
625     def ajoutCommentaire(self):
626         self.viewmanager.ajoutCommentaire()
627
628     def ouvreFichiers(self) :
629     # Ouverture des fichiers de commandes donnes sur la ligne de commande
630         cwd=os.getcwd()
631         self.dir=cwd
632         for study in session.d_env.studies:
633             os.chdir(cwd)
634             d=session.getUnit(study,self)
635             self.viewmanager.handleOpen(fichier=study["comm"],units=d)
636
637
638     def  getSource(self,file):
639     # appele par Editeur/session.py
640         import convert
641         p=convert.plugins['python']()
642         p.readfile(file)
643         texte=p.convert('execnoparseur')
644         return texte
645
646     def initPatrons(self) :
647     # Mise a jour du menu des fichiers recemment ouverts
648         from Editeur import listePatrons
649         if not(self.code in listePatrons.sous_menus) :
650             if hasattr(self,"menuPatrons"):
651                 self.menuPatrons.setAttribute(Qt.WA_DeleteOnClose)
652                 self.menuPatrons.close()
653                 delattr(self,"menuPatrons")
654             return
655         if (not hasattr(self,"menuPatrons")):
656             self.menuPatrons = QMenu(self.menubar)
657             self.menuPatrons.setObjectName("menuPatrons")
658             self.menubar.addAction(self.menuPatrons.menuAction())
659             self.menuPatrons.setTitle(tr("Patrons"))
660         else :
661             self.menuPatrons.clear()
662         self.listePatrons = listePatrons.listePatrons(self.code)
663         idx = 0
664         for nomSsMenu in self.listePatrons.liste:
665             ssmenu=self.menuPatrons.addMenu(nomSsMenu)
666             for fichier in self.listePatrons.liste[nomSsMenu]:
667                 id = ssmenu.addAction(fichier)
668                 self.ficPatrons[id]=fichier
669                 self.id.triggered.connect(self.handleOpenPatrons)
670             #   self.Patrons.setItemParameter(id,idx)
671                 idx=idx+1
672
673     def initRecents(self):
674         self.recent =  []
675         try :
676             #if sys.platform[0:5]=="linux" :
677                 #rep=os.path.join(os.environ['HOME'],'.config/Eficas',self.code)
678             rep=os.path.join(os.path.expanduser("~"),'.config/Eficas',self.code)
679             #else :
680             #   rep=os.path.join('C:/','.config/Eficas',self.code)
681             monFichier=rep+"/listefichiers_"+self.code
682             index=0
683             f=open(monFichier)
684             while ( index < 9) :
685                 ligne=f.readline()
686                 if ligne != "" :
687                     l=(ligne.split("\n"))[0]
688                     self.recent.append(l)
689                 index=index+1
690         except :
691             pass
692
693         try    : f.close()
694         except : pass
695
696     def addToRecentList(self, fn):
697         while fn in self.recent: self.recent.remove(fn)
698         self.recent.insert(0,fn)
699         if len(self.recent) > 9:
700             self.recent = self.recent[:9]
701
702
703     def addToRecentListQT4(self, fn):
704         """
705         Public slot to add a filename to the list of recently opened files.
706
707         @param fn name of the file to be added
708         """
709         self.recent.removeAll(fn)
710         self.recent.prepend(fn)
711         if len(self.recent) > 9:
712             self.recent = self.recent[:9]
713         index=0
714         self.sauveRecents()
715
716     def sauveRecents(self) :
717         try :
718             rep=self.maConfiguration.rep_user
719             monFichier=rep+"/listefichiers_"+self.code
720         except :
721             return
722         try :
723             f=open(monFichier,'w')
724             if len(self.recent) == 0 : return
725             index=0
726             while ( index <  len(self.recent)):
727                 ligne=str(self.recent[index])+"\n"
728                 f.write(ligne)
729                 index=index+1
730         except :
731             pass
732         try :
733             f.close()
734         except :
735             pass
736
737
738
739     def traductionV11V12(self):
740         from .gereTraduction import traduction
741         traduction(self.maConfiguration.repIni,self.viewmanager,"V11V12")
742
743     def traductionV10V11(self):
744         from .gereTraduction import traduction
745         traduction(self.maConfiguration.repIni,self.viewmanager,"V10V11")
746
747     def traductionV9V10(self):
748         from .gereTraduction import traduction
749         traduction(self.maConfiguration.repIni,self.viewmanager,"V9V10")
750
751     def version(self) :
752         from .monVisu import DVisu
753         titre = tr("version ")
754         monVisuDialg=DVisu(parent=self,fl=0)
755         monVisuDialg.setWindowTitle(titre)
756         if self.code != None : monVisuDialg.TB.setText(self.VERSION_EFICAS +tr(" pour ") + self.code)
757         else :  monVisuDialg.TB.setText(self.VERSION_EFICAS )
758         monVisuDialg.adjustSize()
759         monVisuDialg.show()
760
761     def aidePPal(self) :
762         repAide=os.path.dirname(os.path.abspath(__file__))
763         maD=os.path.join( repAide,'..','Doc')
764         try :
765             indexAide=os.path.join(maD,'index.html')
766             if sys.platform[0:5]=="linux" : cmd="xdg-open "+indexAide
767             else                          : cmd="start "+indexAide
768             os.system(cmd)
769         except:
770             QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
771
772     def aidePSEN(self) :
773         repAide=os.path.dirname(os.path.abspath(__file__))
774         maD=os.path.join( repAide,'..','Doc')
775         try :
776             indexAide=os.path.join(maD,'index.html')
777             if sys.platform[0:5]=="linux" : cmd="xdg-open "+indexAide
778             else                          : cmd="start "+indexAide
779             os.system(cmd)
780         except:
781             QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
782
783     def aideCode(self) :
784         if self.code==None : return
785         try :
786         #if 1 :
787             if sys.platform[0:5]=="linux" : cmd="xdg-open "+self.fileDoc
788             else                          : cmd="start "+self.fileDoc
789             os.system(cmd)
790         except:
791         #else:
792             QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
793
794
795     def optionEditeur(self) :
796         try :
797             name='monOptions_'+self.code
798         except :
799             QMessageBox.critical( self,tr( "Parametrage"),tr( "Veuillez d abord choisir un code"))
800             return
801         try :
802         #if 1:
803             optionCode=__import__(name)
804         except :
805         #else :
806             QMessageBox.critical( self, tr("Parametrage"), tr("Pas de possibilite de personnalisation de la configuration "))
807             return
808         monOption=optionCode.Options(parent=self,modal = 0 ,configuration=self.maConfiguration)
809         monOption.show()
810
811     def optionPdf(self) :
812         from monOptionsPdf import OptionPdf
813         monOption=OptionPdf(parent=self,modal = 0 ,configuration=self.maConfiguration)
814         monOption.show()
815
816     def handleSortieComplete(self):
817         return self.viewmanager.saveCompleteCurrentEditor()
818
819     def handleShowRecentMenu(self):
820         """
821         Private method to set up recent files menu.
822         """
823         self.recentMenu.clear()
824
825         for rp in self.recent:
826             id = self.recentMenu.addAction(rp)
827             self.ficRecents[id]=rp
828             id.triggered.connect(self.handleOpenRecent)
829         self.recentMenu.addSeparator()
830         self.recentMenu.addAction(tr('&Effacer'), self.handleClearRecent)
831
832     def handleOpenPatrons(self):
833         idx=self.sender()
834         fichier=self.repIni+"/../Editeur/Patrons/"+self.code+"/"+self.ficPatrons[idx]
835         self.viewmanager.handleOpen(fichier=fichier, patron = 1)
836
837     def handleOpenRecent(self):
838         idx=self.sender()
839         fichier=self.ficRecents[idx]
840         self.viewmanager.handleOpen(fichier=fichier, patron =0 )
841
842     def handleClearRecent(self):
843         self.recent = QStringList()
844         self.sauveRecents()
845
846     def handleRechercherDsCatalogue(self):
847         if not self.viewmanager : return
848         self.viewmanager.handleRechercherDsCatalogue()
849
850     def fileNew(self):
851         try:
852             self.viewmanager.newEditor()
853         except EficasException as exc:
854             msg = str(exc)
855             if msg != "": QMessageBox.warning(self, tr(u"Erreur"), msg)
856
857     def openProcess(self):
858         ssCode=None
859         code="PSEN_N1"
860         self.cleanPath()
861         dirCode=os.path.abspath(os.path.join(os.path.abspath(__file__),'../..',"ProcessOutputs_Eficas"))
862         sys.path.insert(0,dirCode)
863         self.code=code
864         self.definitCode(code,ssCode)
865         self.multi=True
866         self.demande=False
867         self.initRecents()
868         self.fileOpen()
869
870
871     def fileOpen(self):
872         try:
873             self.viewmanager.handleOpen()
874         except EficasException as exc:
875             msg = str(exc)
876             if msg != "":
877                 QMessageBox.warning(self, tr(u"Erreur"), msg)
878
879     def sauveLigne(self):
880         return self.viewmanager.sauveLigneCurrentEditor()
881
882     def fileSave(self):
883         return self.viewmanager.saveCurrentEditor()
884
885     def fileSaveAs(self):
886         return self.viewmanager.saveAsCurrentEditor()
887
888     def fileClose(self):
889         self.viewmanager.handleClose(texte='&Fermer')
890
891     def fileCloseAll(self):
892         self.viewmanager.handleCloseAll(texte='&Fermer')
893
894     def fileExit(self):
895         # On peut sortir sur Abort
896         res=self.viewmanager.handleCloseAll()
897         if (res != 2) :
898             self.close()
899         return res
900
901     def editCopy(self):
902         self.viewmanager.handleEditCopy()
903
904     def editCut(self):
905         self.viewmanager.handleEditCut()
906
907     def editPaste(self):
908         self.viewmanager.handleEditPaste()
909
910     def rechercher(self):
911         self.viewmanager.handleRechercher()
912
913     def run(self):
914         self.viewmanager.run()
915
916     def saveRun(self):
917         self.viewmanager.saveRun()
918
919
920     def supprimer(self):
921         self.viewmanager.handleSupprimer()
922
923     def jdcFichierSource(self):
924         self.viewmanager.handleViewJdcFichierSource()
925
926     def jdcRapport(self):
927         self.viewmanager.handleViewJdcRapport()
928
929     def jdcRegles(self):
930         self.viewmanager.handleViewJdcRegles()
931
932     def gestionParam(self):
933         self.viewmanager.handleGestionParam()
934
935     def visuJdcPy(self):
936         self.viewmanager.handleViewJdcPy()
937
938     def ouvreArbre(self):
939         self.viewmanager.ouvreArbre()
940
941     def fermeArbre(self):
942         self.viewmanager.fermeArbre()
943
944     def newInclude(self):
945         self.viewmanager.newIncludeEditor()
946
947     def cleanPath(self):
948         for pathCode in self.ListePathCode:
949             try:
950                 aEnlever=os.path.abspath(os.path.join(os.path.dirname(__file__),'..',pathCode))
951                 sys.path.remove(aEnlever)
952             except :
953                 pass
954         for pathCode in self.listeAEnlever:
955             try:
956                 sys.path.remove(aEnlever)
957             except :
958                 pass
959
960
961     def closeEvent(self,event):
962         res=self.fileExit()
963         if res==2 : event.ignore()
964
965
966     def remplitIconesCommandes(self):
967         if self.maConfiguration.boutonDsMenuBar == False : return
968         if not hasattr(self, 'readercata') : return
969         from monLayoutBouton import MonLayoutBouton
970         if hasattr(self,'monLayoutBoutonRempli') : return
971         self.monLayoutBoutonRempli=MonLayoutBouton(self)
972
973     def handleAjoutEtape(self,nomEtape):
974         self.viewmanager.handleAjoutEtape(nomEtape)
975
976     def metMenuAJourUtilisateurs(self):
977         self.lesFonctionsUtilisateurs={}
978         if self.code not in self.mesScripts : return
979         if not hasattr(self.mesScripts[self.code],'dict_menu') : return
980         for monMenu in iter(self.mesScripts[self.code].dict_menu.items()) :
981             titre,lesFonctions= monMenu
982             self.menuOptions = self.menubar.addMenu("menuOptions")
983             self.menuOptions.setTitle(tr(titre))
984             for elt in lesFonctions :
985                 laFonctionUtilisateur, label, lesArguments = elt
986                 action = QAction(self)
987                 action.setText(label)
988             #action.triggered.connect(self.appelleFonctionUtilisateur)
989                 self.menuOptions.addAction(action)
990                 self.lesFonctionsUtilisateurs[action]=(laFonctionUtilisateur, lesArguments)
991             self.menuOptions.triggered.connect(self.handleFonctionUtilisateur)
992
993
994     def handleFonctionUtilisateur(self,action) :
995         (laFonctionUtilisateur, lesArguments)=self.lesFonctionsUtilisateurs[action]
996         self.viewmanager.handleFonctionUtilisateur(laFonctionUtilisateur, lesArguments)
997
998 if __name__=='__main__':
999
1000     # Modules Eficas
1001     rep=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__),'..','Adao')))
1002     sys.path.append(rep)
1003     from Adao import prefs
1004     from Adao import prefs_Adao
1005
1006     from Editeur import import_code
1007     from Editeur import session
1008
1009     # Analyse des arguments de la ligne de commande
1010     options=session.parse(sys.argv)
1011     code=options.code
1012
1013
1014     app = QApplication(sys.argv)
1015     #app.setMainWidget(mw) (qt3)
1016     Eficas=Appli()
1017     Eficas.show()
1018
1019     #mw.ouvreFichiers()
1020     #mw.show()
1021
1022     res=app.exec_()
1023     sys.exit(res)