]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/qtEficas.py
Salome HOME
chgt copyright
[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 import six
30
31
32 from PyQt5.QtWidgets import QApplication, QMainWindow, QGridLayout, QBoxLayout, QMenu, QAction, QMessageBox
33 from PyQt5.QtGui import QIcon
34 from PyQt5.QtCore import Qt, QSize
35
36
37 from Editeur import session
38 from myMain import Ui_Eficas
39 from InterfaceQT4.viewManager import MyViewManager
40 from InterfaceQT4.qtEficasSsIhm import AppliSsIhm
41
42 from Extensions.i18n import tr
43 from Extensions.eficas_exception import EficasException
44 from Extensions import param2
45
46
47 class Appli(AppliSsIhm,Ui_Eficas,QMainWindow):
48     """
49     Class implementing the main user interface.
50     """
51     def __init__(self,code=None,salome=1,parent=None,ssCode=None,multi=False,langue='fr',ssIhm=False,versionCode=None):
52         """
53         Constructor
54         """
55         if ssIhm == True : 
56            print ('mauvaise utilisation de la classe Appli. Utiliser AppliSsIm SVP')
57            exit()
58
59         AppliSsIhm.__init__(self,code,salome,parent,ssCode,multi,langue,ssIhm=True,versionCode=None)
60         QMainWindow.__init__(self,parent)
61         Ui_Eficas.__init__(self)
62
63         self.ssIhm=False
64         self.multi=multi
65         self.demande=multi # voir PSEN
66
67         if self.multi == False :
68              self.definitCode(code,ssCode)
69              if code==None: return
70         else :
71              print ('a programmer')
72
73         self.suiteTelemac=False
74         if hasattr (self, 'maConfiguration') :
75            if self.maConfiguration.force_langue :
76               from InterfaceQT4.monChoixLangue import MonChoixLangue
77               widgetLangue = MonChoixLangue(self)
78               ret=widgetLangue.exec_()
79            self.suiteTelemac=self.maConfiguration.suiteTelemac
80
81
82         if not self.salome and hasattr (self, 'maConfiguration') and hasattr(self.maConfiguration,'lang') : self.langue=self.maConfiguration.lang
83         from Extensions import localisation
84         app=QApplication
85         if hasattr (self, 'maConfiguration') : localisation.localise(None,self.langue,translatorFichier=self.maConfiguration.translatorFichier)
86         self.setupUi(self)
87
88         #if parent != None : self.parentCentralWidget = parent.centralWidget()
89         #else              : self.parentCentralWidget = None
90
91         if not self.salome :
92            if  hasattr (self, 'maConfiguration') and hasattr(self.maConfiguration,'taille') : self.taille=self.maConfiguration.taille
93            else : self.taille=1700
94
95            #if self.code in ['MAP',] : self.resize(1440,self.height())
96            #else : self.resize(self.taille,self.height())
97            self.resize(self.taille,self.height())
98
99
100         icon = QIcon(self.repIcon+"/parametres.png")
101         self.actionParametres.setIcon(icon)
102         if  hasattr (self, 'maConfiguration') and self.maConfiguration.boutonDsMenuBar  : 
103            self.frameEntete.setMaximumSize(QSize(16777215,100))
104            self.frameEntete.setMinimumSize(QSize(0,100))
105         if  hasattr (self, 'maConfiguration') and self.maConfiguration.enleverActionStructures  : 
106             self.enleverActionsStructures()
107         if  hasattr (self, 'maConfiguration') and self.maConfiguration.enleverParametres  : 
108             self.enleverParametres()
109         if  hasattr (self, 'maConfiguration') and self.maConfiguration.enleverSupprimer : 
110             self.enleverSupprimer()
111
112
113         self.myQtab.removeTab(0)
114         self.blEnteteGlob = QBoxLayout(2,self.frameEntete)
115         self.blEnteteGlob.setSpacing(0)
116         self.blEnteteGlob.setContentsMargins(0,0,0,0)
117
118         self.blEntete = QBoxLayout(0)
119         self.blEntete.insertWidget(0,self.toolBar)
120         self.blEntete.insertWidget(0,self.menubar)
121         self.blEnteteGlob.insertLayout(0,self.blEntete)
122
123
124         
125         if  hasattr (self, 'maConfiguration') and self.maConfiguration.boutonDsMenuBar  : 
126             self.blEnteteCommmande = QBoxLayout(0)
127             self.blEnteteCommmande.insertWidget(0,self.toolBarCommande)
128             self.toolBarCommande.setIconSize(QSize(96,96))
129             self.blEnteteGlob.insertLayout(-1,self.blEnteteCommmande)
130         else :
131             self.toolBarCommande.close()
132          
133
134         if hasattr (self, 'maConfiguration') and self.maConfiguration.closeEntete==True and self.salome: self.closeEntete()
135
136         eficas_root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
137
138         self.viewmanager = MyViewManager(self)
139         self.recentMenu=QMenu(tr('&Recents'))
140         #self.menuFichier.insertMenu(self.actionOuvrir,self.recentMenu)
141
142         # actionARemplacer ne sert que pour l insert Menu
143         self.menuFichier.insertMenu(self.actionARemplacer ,self.recentMenu)
144         self.menuFichier.removeAction(self.actionARemplacer)
145         self.connecterSignaux()
146         self.toolBar.addSeparator()
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         if self.first:  self.first=0
400         try : self.action_Nouveau.triggered.disconnect(self.fileNew)
401         except : pass
402         try : self.action_Nouveau.triggered.disconnect(self.newPSEN)
403         except : pass
404
405         self.action_Nouveau.triggered.connect(self.newPSEN)
406         self.enleverActionsStructures()
407         self.enleverParametres()
408         self.enleverRechercherDsCatalogue()
409         self.enlevernewInclude()
410         self.ajoutExecution()
411         self.ajoutN1()
412         self.ajoutHelpPSEN()
413         self.ajoutIcones()
414
415     def PSEN_N1(self):
416         self.enleverActionsStructures()
417         self.enleverParametres()
418         self.enleverRechercherDsCatalogue()
419         self.enlevernewInclude()
420         self.ajoutExecution()
421         self.ajoutIcones()
422
423     def TELEMAC(self):
424         self.enleverActionsStructures()
425         self.enlevernewInclude()
426         self.connectRechercherDsCatalogue()
427         self.ajoutSortieComplete()
428
429     def lookSuiteTelemac(self):
430         self.enleverActionsStructures()
431         self.enlevernewInclude()
432         self.enleverParametres()
433         self.enleverSupprimer()
434         self.enleverRechercherDsCatalogue()
435
436     def ajoutHelpPSEN(self):
437         self.actionParametres_Eficas.setText('Help PSEN')
438         self.actionParametres_Eficas.triggered.connect(self.aidePSEN)
439
440
441
442     def ChercheGrpMesh(self):
443         Msg,listeGroup=self.ChercheGrpMeshInSalome()
444         if Msg == None :
445            self.viewmanager.handleAjoutGroup(listeGroup)
446         else :
447            print ("il faut gerer les erreurs")
448
449     def ChercheGrpMaille(self):
450         # Normalement la variable self.salome permet de savoir si on est ou non dans Salome
451         try:
452             Msg,listeGroup=self.ChercheGrpMailleInSalome() # recherche dans Salome
453             #Msg = None; listeGroup = None # recherche manuelle, i.e., sans Salome si ligne precedente commentee
454         except:
455             raise ValueError('Salome non ouvert')
456         if Msg == None :
457            self.viewmanager.handleAjoutGroup(listeGroup)
458         else :
459            print ("il faut gerer les erreurs")
460
461
462     def ChercheGrp(self):
463         #Msg,listeGroup=self.ChercheGrpMailleInSalome()
464         #if Msg == None :
465         #   self.viewmanager.handleAjoutGroup(listeGroup)
466         #else :
467         #print "il faut gerer "
468         pass
469
470
471     def ajoutIcones(self) :
472         # Pour pallier les soucis de repertoire d icone
473         #print self.repIcon
474         icon = QIcon(self.repIcon+"/new_file.png")
475         self.action_Nouveau.setIcon(icon)
476         icon1 = QIcon(self.repIcon+"/ouvrir.png")
477         self.actionOuvrir.setIcon(icon1)
478         icon2 = QIcon(self.repIcon+"/save.png")
479         self.actionEnregistrer.setIcon(icon2)
480         icon6 = QIcon(self.repIcon+"/delete.png")
481         self.actionSupprimer.setIcon(icon6)
482         icon7 = QIcon(self.repIcon+"/roue.png")
483         self.actionExecution.setIcon(icon7)
484
485
486
487
488     def connecterSignauxQT4(self) :
489         self.connect(self.recentMenu,SIGNAL('aboutToShow()'),self.handleShowRecentMenu)
490
491         self.connect(self.action_Nouveau,SIGNAL("triggered()"),self.fileNew)
492         self.connect(self.actionNouvel_Include,SIGNAL("triggered()"),self.newInclude)
493         self.connect(self.actionOuvrir,SIGNAL("triggered()"),self.fileOpen)
494         self.connect(self.actionEnregistrer,SIGNAL("triggered()"),self.fileSave)
495         self.connect(self.actionEnregistrer_sous,SIGNAL("triggered()"),self.fileSaveAs)
496         self.connect(self.actionFermer,SIGNAL("triggered()"),self.fileClose)
497         self.connect(self.actionFermer_tout,SIGNAL("triggered()"),self.fileCloseAll)
498         self.connect(self.actionQuitter,SIGNAL("triggered()"),self.fileExit)
499
500         self.connect(self.actionEficas,SIGNAL("triggered()"),self.aidePPal)
501         self.connect(self.actionVersion,SIGNAL("triggered()"),self.version)
502         self.connect(self.actionParametres,SIGNAL("triggered()"),self.gestionParam)
503
504         self.connect(self.actionCouper,SIGNAL("triggered()"),self.editCut)
505         self.connect(self.actionCopier,SIGNAL("triggered()"),self.editCopy)
506         self.connect(self.actionColler,SIGNAL("triggered()"),self.editPaste)
507         self.connect(self.actionSupprimer,SIGNAL("triggered()"),self.supprimer)
508         self.connect(self.actionRechercher,SIGNAL("triggered()"),self.rechercher)
509         self.connect(self.actionDeplier_replier,SIGNAL("triggered()"),self.handleDeplier)
510
511         self.connect(self.actionRapport_de_Validation,SIGNAL("triggered()"),self.jdcRapport)
512         self.connect(self.actionRegles_du_JdC,SIGNAL("triggered()"),self.jdcRegles)
513         self.connect(self.actionFichier_Source,SIGNAL("triggered()"),self.jdcFichierSource)
514         self.connect(self.actionFichier_Resultat,SIGNAL("triggered()"),self.visuJdcPy)
515
516
517
518
519         # Pour Aster
520         self.actionTraduitV9V10 = QAction(self)
521         self.actionTraduitV9V10.setObjectName("actionTraduitV9V10")
522         self.actionTraduitV9V10.setText(tr("TraduitV9V10"))
523         self.actionTraduitV10V11 = QAction(self)
524         self.actionTraduitV10V11.setObjectName("actionTraduitV10V11")
525         self.actionTraduitV10V11.setText(tr("TraduitV10V11"))
526         self.actionTraduitV11V12 = QAction(self)
527         self.actionTraduitV11V12.setObjectName("actionTraduitV11V12")
528         self.actionTraduitV11V12.setText(tr("TraduitV11V12"))
529         self.actionSauveLigne = QAction(self)
530         self.actionSauveLigne.setText(tr("Sauve Format Ligne"))
531
532         #self.connect(self.actionParametres_Eficas,SIGNAL("triggered()"),self.optionEditeur)
533         self.connect(self.actionLecteur_Pdf,SIGNAL("triggered()"),self.optionPdf)
534         self.connect(self.actionTraduitV9V10,SIGNAL("triggered()"),self.traductionV9V10)
535         self.connect(self.actionTraduitV10V11,SIGNAL("triggered()"),self.traductionV10V11)
536         self.connect(self.actionTraduitV11V12,SIGNAL("triggered()"),self.traductionV11V12)
537         self.connect(self.actionSauveLigne,SIGNAL("triggered()"),self.sauveLigne)
538
539
540         # Pour Carmel
541         self.actionChercheGrpMaille = QAction(self)
542         self.actionChercheGrpMaille.setText(tr("Acquiert groupe mailles"))
543         self.connect(self.actionChercheGrpMaille,SIGNAL("triggered()"),self.ChercheGrpMaille)
544
545         # Pour CarmelCND
546         self.actionChercheGrp = QAction(self)
547         self.actionChercheGrp.setText(tr("Acquisition Groupe Maille"))
548         self.connect(self.actionChercheGrp,SIGNAL("triggered()"),self.ChercheGrp)
549
550         # Pour Aide
551         self.actionCode = QAction(self)
552         self.actionCode.setText(tr("Specificites Maille"))
553         self.connect(self.actionCode,SIGNAL("triggered()"),self.aideCode)
554
555     def connecterSignaux(self) :
556
557         self.recentMenu.aboutToShow.connect(self.handleShowRecentMenu)
558         self.action_Nouveau.triggered.connect(self.fileNew)
559         self.actionNouvel_Include.triggered.connect(self.newInclude)
560         self.actionOuvrir.triggered.connect(self.fileOpen)
561         self.actionEnregistrer.triggered.connect(self.fileSave)
562         self.actionEnregistrer_sous.triggered.connect(self.fileSaveAs)
563         self.actionFermer.triggered.connect(self.fileClose)
564         self.actionFermer_tout.triggered.connect(self.fileCloseAll)
565         self.actionQuitter.triggered.connect(self.fileExit)
566
567         self.actionEficas.triggered.connect(self.aidePPal)
568         self.actionVersion.triggered.connect(self.version)
569         self.actionParametres.triggered.connect(self.gestionParam)
570         self.actionCommentaire.triggered.connect(self.ajoutCommentaire)
571
572         self.actionCouper.triggered.connect(self.editCut)
573         self.actionCopier.triggered.connect(self.editCopy)
574         self.actionColler.triggered.connect(self.editPaste)
575         self.actionSupprimer.triggered.connect(self.supprimer)
576         self.actionRechercher.triggered.connect(self.rechercher)
577         self.actionDeplier_replier.triggered.connect(self.handleDeplier)
578
579         self.actionRapport_de_Validation.triggered.connect(self.jdcRapport)
580         self.actionRegles_du_JdC.triggered.connect(self.jdcRegles)
581         self.actionFichier_Source.triggered.connect(self.jdcFichierSource)
582         self.actionFichier_Resultat.triggered.connect(self.visuJdcPy)
583         self.actionAfficher_l_Arbre.triggered.connect(self.ouvreArbre)
584         self.actionCacher_l_Arbre.triggered.connect(self.fermeArbre)
585
586
587         # Pour Aster
588         self.actionTraduitV9V10 = QAction(self)
589         self.actionTraduitV9V10.setObjectName("actionTraduitV9V10")
590         self.actionTraduitV9V10.setText(tr("TraduitV9V10"))
591         self.actionTraduitV10V11 = QAction(self)
592         self.actionTraduitV10V11.setObjectName("actionTraduitV10V11")
593         self.actionTraduitV10V11.setText(tr("TraduitV10V11"))
594         self.actionTraduitV11V12 = QAction(self)
595         self.actionTraduitV11V12.setObjectName("actionTraduitV11V12")
596         self.actionTraduitV11V12.setText(tr("TraduitV11V12"))
597         self.actionSauveLigne = QAction(self)
598         self.actionSauveLigne.setText(tr("Sauve Format Ligne"))
599
600         #self.actionParametres_Eficas.triggered.connect(self.optionEditeur)
601         self.actionTraduitV9V10.triggered.connect(self.traductionV9V10)
602         self.actionTraduitV10V11.triggered.connect(self.traductionV10V11)
603         self.actionTraduitV11V12.triggered.connect(self.traductionV11V12)
604         self.actionSauveLigne.triggered.connect(self.sauveLigne)
605
606         # Pour Carmel
607         self.actionChercheGrpMaille = QAction(self)
608         self.actionChercheGrpMaille.setText(tr("Acquiert Groupe Maille"))
609
610         # Pour CarmelCND
611         self.actionChercheGrp = QAction(self)
612         self.actionChercheGrp.setText(tr("Accquisition Groupe Maille"))
613         self.actionChercheGrp.triggered.connect(self.ChercheGrp)
614
615         # Pour Aide
616         self.actionCode = QAction(self)
617         self.actionCode.setText(tr("Specificites Maille"))
618         self.actionCode.triggered.connect(self.aideCode)
619
620
621     def handleDeplier(self):
622         self.viewmanager.handleDeplier()
623
624     def ajoutCommentaire(self):
625         self.viewmanager.ajoutCommentaire()
626
627     def ouvreFichiers(self) :
628     # Ouverture des fichiers de commandes donnes sur la ligne de commande
629         cwd=os.getcwd()
630         self.dir=cwd
631         for study in session.d_env.studies:
632             os.chdir(cwd)
633             d=session.getUnit(study,self)
634             self.viewmanager.handleOpen(fichier=study["comm"],units=d)
635
636
637     def  getSource(self,file):
638     # appele par Editeur/session.py
639         import convert
640         p=convert.plugins['python']()
641         p.readfile(file)
642         texte=p.convert('execnoparseur')
643         return texte
644
645     def initPatrons(self) :
646     # Mise a jour du menu des fichiers recemment ouverts
647         from Editeur import listePatrons
648         if not(self.code in listePatrons.sous_menus) :
649            if hasattr(self,"menuPatrons"):
650               self.menuPatrons.setAttribute(Qt.WA_DeleteOnClose)
651               self.menuPatrons.close()
652               delattr(self,"menuPatrons")
653            return
654         if (not hasattr(self,"menuPatrons")):
655            self.menuPatrons = QMenu(self.menubar)
656            self.menuPatrons.setObjectName("menuPatrons")
657            self.menubar.addAction(self.menuPatrons.menuAction())
658            self.menuPatrons.setTitle(tr("Patrons"))
659         else :
660            self.menuPatrons.clear()
661         self.listePatrons = listePatrons.listePatrons(self.code)
662         idx = 0
663         for nomSsMenu in self.listePatrons.liste:
664             ssmenu=self.menuPatrons.addMenu(nomSsMenu)
665             for fichier in self.listePatrons.liste[nomSsMenu]:
666                id = ssmenu.addAction(fichier)
667                self.ficPatrons[id]=fichier
668                self.id.triggered.connect(self.handleOpenPatrons)
669             #   self.Patrons.setItemParameter(id,idx)
670                idx=idx+1
671
672     def initRecents(self):
673        self.recent =  []
674        try :
675            rep=os.path.join(os.path.expanduser("~"),'.config/Eficas',self.code)
676            #if sys.platform[0:5]=="linux" :
677               #rep=os.path.join(os.environ['HOME'],'.config/Eficas',self.code)
678            #else :
679            #   rep=os.path.join('C:/','.config/Eficas',self.code)
680            monFichier=rep+"/listefichiers_"+self.code
681            index=0
682            f=open(monFichier)
683            while ( index < 9) :
684               ligne=f.readline()
685               if ligne != "" :
686                  l=(ligne.split("\n"))[0]
687                  self.recent.append(l)
688               index=index+1
689        except :
690            pass
691
692        try    : f.close()
693        except : pass
694
695     def addToRecentList(self, fn):
696       while fn in self.recent: self.recent.remove(fn)
697       self.recent.insert(0,fn)
698       if len(self.recent) > 9:
699          self.recent = self.recent[:9]
700
701
702     def addToRecentListQT4(self, fn):
703         """
704         Public slot to add a filename to the list of recently opened files.
705
706         @param fn name of the file to be added
707         """
708         self.recent.removeAll(fn)
709         self.recent.prepend(fn)
710         if len(self.recent) > 9:
711             self.recent = self.recent[:9]
712         index=0
713         self.sauveRecents()
714
715     def sauveRecents(self) :
716        try :
717          rep=self.maConfiguration.rep_user
718          monFichier=rep+"/listefichiers_"+self.code
719        except :
720          return
721        try :
722             f=open(monFichier,'w')
723             if len(self.recent) == 0 : return
724             index=0
725             while ( index <  len(self.recent)):
726               ligne=str(self.recent[index])+"\n"
727               f.write(ligne)
728               index=index+1
729        except :
730             pass
731        try :
732             f.close()
733        except :
734             pass
735
736
737
738     def traductionV11V12(self):
739         from .gereTraduction import traduction
740         traduction(self.maConfiguration.repIni,self.viewmanager,"V11V12")
741
742     def traductionV10V11(self):
743         from .gereTraduction import traduction
744         traduction(self.maConfiguration.repIni,self.viewmanager,"V10V11")
745
746     def traductionV9V10(self):
747         from .gereTraduction import traduction
748         traduction(self.maConfiguration.repIni,self.viewmanager,"V9V10")
749
750     def version(self) :
751         from .monVisu import DVisu
752         titre = tr("version ")
753         monVisuDialg=DVisu(parent=self,fl=0)
754         monVisuDialg.setWindowTitle(titre)
755         if self.code != None : monVisuDialg.TB.setText(self.VERSION_EFICAS +tr(" pour ") + self.code)
756         else :  monVisuDialg.TB.setText(self.VERSION_EFICAS )
757         monVisuDialg.adjustSize()
758         monVisuDialg.show()
759
760     def aidePPal(self) :
761         repAide=os.path.dirname(os.path.abspath(__file__))
762         maD=os.path.join( repAide,'..','Doc')
763         try :
764           indexAide=os.path.join(maD,'index.html')
765           if sys.platform[0:5]=="linux" : cmd="xdg-open "+indexAide
766           else                          : cmd="start "+indexAide
767           os.system(cmd)
768         except:
769           QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
770
771     def aidePSEN(self) :
772         repAide=os.path.dirname(os.path.abspath(__file__))
773         maD=os.path.join( repAide,'..','Doc')
774         try :
775           indexAide=os.path.join(maD,'index.html')
776           if sys.platform[0:5]=="linux" : cmd="xdg-open "+indexAide
777           else                          : cmd="start "+indexAide
778           os.system(cmd)
779         except:
780           QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
781
782     def aideCode(self) :
783         if self.code==None : return
784         try :
785         #if 1 :
786           if sys.platform[0:5]=="linux" : cmd="xdg-open "+self.fileDoc
787           else                          : cmd="start "+self.fileDoc
788           os.system(cmd)
789         except:
790         #else:
791           QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
792
793
794     def optionEditeur(self) :
795         try :
796            name='monOptions_'+self.code
797         except :
798            QMessageBox.critical( self,tr( "Parametrage"),tr( "Veuillez d abord choisir un code"))
799            return
800         try :
801         #if 1:
802            optionCode=__import__(name)
803         except :
804         #else :
805            QMessageBox.critical( self, tr("Parametrage"), tr("Pas de possibilite de personnalisation de la configuration "))
806            return
807         monOption=optionCode.Options(parent=self,modal = 0 ,configuration=self.maConfiguration)
808         monOption.show()
809
810     def optionPdf(self) :
811         from monOptionsPdf import OptionPdf
812         monOption=OptionPdf(parent=self,modal = 0 ,configuration=self.maConfiguration)
813         monOption.show()
814
815     def handleSortieComplete(self):
816         return self.viewmanager.saveCompleteCurrentEditor()
817
818     def handleShowRecentMenu(self):
819         """
820         Private method to set up recent files menu.
821         """
822         self.recentMenu.clear()
823
824         for rp in self.recent:
825             id = self.recentMenu.addAction(rp)
826             self.ficRecents[id]=rp
827             id.triggered.connect(self.handleOpenRecent)
828         self.recentMenu.addSeparator()
829         self.recentMenu.addAction(tr('&Effacer'), self.handleClearRecent)
830
831     def handleOpenPatrons(self):
832         idx=self.sender()
833         fichier=self.repIni+"/../Editeur/Patrons/"+self.code+"/"+self.ficPatrons[idx]
834         self.viewmanager.handleOpen(fichier=fichier, patron = 1)
835
836     def handleOpenRecent(self):
837         idx=self.sender()
838         fichier=self.ficRecents[idx]
839         self.viewmanager.handleOpen(fichier=fichier, patron =0 )
840
841     def handleClearRecent(self):
842         self.recent = QStringList()
843         self.sauveRecents()
844
845     def handleRechercherDsCatalogue(self):
846         if not self.viewmanager : return
847         self.viewmanager.handleRechercherDsCatalogue()
848
849     def fileNew(self):
850         try:
851             self.viewmanager.newEditor()
852         except EficasException as exc:
853             msg = six.text_type(exc)
854             if msg != "": QMessageBox.warning(self, tr(u"Erreur"), msg)
855
856     def openProcess(self):
857         ssCode=None
858         code="PSEN_N1"
859         self.cleanPath()
860         dirCode=os.path.abspath(os.path.join(os.path.abspath(__file__),'../..',"ProcessOutputs_Eficas"))
861         sys.path.insert(0,dirCode)
862         self.code=code
863         self.definitCode(code,ssCode)
864         self.multi=True
865         self.demande=False
866         self.initRecents()
867         self.fileOpen()
868
869
870     def fileOpen(self):
871         try:
872             self.viewmanager.handleOpen()
873         except EficasException as exc:
874             msg = six.text_type(exc)
875             if msg != "":
876                 QMessageBox.warning(self, tr(u"Erreur"), msg)
877
878     def sauveLigne(self):
879         return self.viewmanager.sauveLigneCurrentEditor()
880
881     def fileSave(self):
882         return self.viewmanager.saveCurrentEditor()
883
884     def fileSaveAs(self):
885         return self.viewmanager.saveAsCurrentEditor()
886
887     def fileClose(self):
888         self.viewmanager.handleClose(texte='&Fermer')
889
890     def fileCloseAll(self):
891         self.viewmanager.handleCloseAll(texte='&Fermer')
892
893     def fileExit(self):
894         # On peut sortir sur Abort
895         res=self.viewmanager.handleCloseAll()
896         if (res != 2) :
897             self.close()
898         return res
899
900     def editCopy(self):
901         self.viewmanager.handleEditCopy()
902
903     def editCut(self):
904         self.viewmanager.handleEditCut()
905
906     def editPaste(self):
907         self.viewmanager.handleEditPaste()
908
909     def rechercher(self):
910         self.viewmanager.handleRechercher()
911
912     def run(self):
913         self.viewmanager.run()
914
915     def saveRun(self):
916         self.viewmanager.saveRun()
917
918
919     def supprimer(self):
920         self.viewmanager.handleSupprimer()
921
922     def jdcFichierSource(self):
923         self.viewmanager.handleViewJdcFichierSource()
924
925     def jdcRapport(self):
926         self.viewmanager.handleViewJdcRapport()
927
928     def jdcRegles(self):
929         self.viewmanager.handleViewJdcRegles()
930
931     def gestionParam(self):
932         self.viewmanager.handleGestionParam()
933
934     def visuJdcPy(self):
935         self.viewmanager.handleViewJdcPy()
936
937     def ouvreArbre(self):
938         self.viewmanager.ouvreArbre()
939
940     def fermeArbre(self):
941         self.viewmanager.fermeArbre()
942
943     def newInclude(self):
944         self.viewmanager.newIncludeEditor()
945
946     def cleanPath(self):
947         for pathCode in self.ListePathCode:
948             try:
949               aEnlever=os.path.abspath(os.path.join(os.path.dirname(__file__),'..',pathCode))
950               sys.path.remove(aEnlever)
951             except :
952               pass
953         for pathCode in self.listeAEnlever:
954             try:
955               sys.path.remove(aEnlever)
956             except :
957               pass
958
959
960     def closeEvent(self,event):
961       res=self.fileExit()
962       if res==2 : event.ignore()
963
964  
965     def remplitIconesCommandes(self):
966         if self.maConfiguration.boutonDsMenuBar == False : return
967         if not hasattr(self, 'readercata') : return
968         from monLayoutBouton import MonLayoutBouton
969         if hasattr(self,'monLayoutBoutonRempli') : return
970         self.monLayoutBoutonRempli=MonLayoutBouton(self)
971         
972     def handleAjoutEtape(self,nomEtape):
973         self.viewmanager.handleAjoutEtape(nomEtape)
974      
975     def metMenuAJourUtilisateurs(self):
976         self.lesFonctionsUtilisateurs={}
977         if self.code not in self.mesScripts : return
978         if not hasattr(self.mesScripts[self.code],'dict_menu') : return
979         for monMenu in iter(self.mesScripts[self.code].dict_menu.items()) :
980             titre,lesFonctions= monMenu
981             self.menuOptions = self.menubar.addMenu("menuOptions")
982             self.menuOptions.setTitle(tr(titre))
983             for elt in lesFonctions :
984                laFonctionUtilisateur, label, lesArguments = elt
985                action = QAction(self)
986                action.setText(label)
987             #action.triggered.connect(self.appelleFonctionUtilisateur)
988                self.menuOptions.addAction(action)
989                self.lesFonctionsUtilisateurs[action]=(laFonctionUtilisateur, lesArguments)
990             self.menuOptions.triggered.connect(self.handleFonctionUtilisateur)
991
992     def handleFonctionUtilisateur(self,action) :
993         (laFonctionUtilisateur, lesArguments)=self.lesFonctionsUtilisateurs[action]
994         self.viewmanager.handleFonctionUtilisateur(laFonctionUtilisateur, lesArguments)
995
996 if __name__=='__main__':
997
998     # Modules Eficas
999     rep=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__),'..','Adao')))
1000     sys.path.append(rep)
1001     from Adao import prefs
1002     from Adao import prefs_Adao
1003     #if hasattr(prefsCode,'encoding'):
1004        # Hack pour changer le codage par defaut des strings
1005        #import sys
1006        #reload(sys)
1007        #sys.setdefaultencoding(prefsCode.encoding)
1008        #del sys.setdefaultencoding
1009        # Fin hack
1010
1011     from Editeur import import_code
1012     from Editeur import session
1013
1014     # Analyse des arguments de la ligne de commande
1015     options=session.parse(sys.argv)
1016     code=options.code
1017
1018
1019     app = QApplication(sys.argv)
1020     #app.setMainWidget(mw) (qt3)
1021     Eficas=Appli()
1022     Eficas.show()
1023
1024     #mw.ouvreFichiers()
1025     #mw.show()
1026
1027     res=app.exec_()
1028     sys.exit(res)