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