]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/qtEficas.py
Salome HOME
bug sur un mesage dans une exception sur un validator (cf JPA)
[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             rep=os.path.join(os.path.expanduser("~"),'.config/Eficas',self.code)
677             monFichier=rep+"/listefichiers_"+self.code
678             index=0
679             f=open(monFichier)
680             while ( index < 9) :
681                 ligne=f.readline()
682                 if ligne != "" :
683                     l=(ligne.split("\n"))[0]
684                     self.recent.append(l)
685                 index=index+1
686         except :
687             pass
688
689         try    : f.close()
690         except : pass
691
692     def addToRecentList(self, fn):
693         while fn in self.recent: self.recent.remove(fn)
694         self.recent.insert(0,fn)
695         if len(self.recent) > 9:
696             self.recent = self.recent[:9]
697
698
699     def addToRecentListQT4(self, fn):
700         """
701         Public slot to add a filename to the list of recently opened files.
702
703         @param fn name of the file to be added
704         """
705         self.recent.removeAll(fn)
706         self.recent.prepend(fn)
707         if len(self.recent) > 9:
708             self.recent = self.recent[:9]
709         index=0
710         self.sauveRecents()
711
712     def sauveRecents(self) :
713         try :
714             rep=self.maConfiguration.rep_user
715             monFichier=rep+"/listefichiers_"+self.code
716         except :
717             return
718         try :
719             f=open(monFichier,'w')
720             if len(self.recent) == 0 : return
721             index=0
722             while ( index <  len(self.recent)):
723                 ligne=str(self.recent[index])+"\n"
724                 f.write(ligne)
725                 index=index+1
726         except :
727             pass
728         try :
729             f.close()
730         except :
731             pass
732
733
734
735     def traductionV11V12(self):
736         from .gereTraduction import traduction
737         traduction(self.maConfiguration.repIni,self.viewmanager,"V11V12")
738
739     def traductionV10V11(self):
740         from .gereTraduction import traduction
741         traduction(self.maConfiguration.repIni,self.viewmanager,"V10V11")
742
743     def traductionV9V10(self):
744         from .gereTraduction import traduction
745         traduction(self.maConfiguration.repIni,self.viewmanager,"V9V10")
746
747     def version(self) :
748         from .monVisu import DVisu
749         titre = tr("version ")
750         monVisuDialg=DVisu(parent=self,fl=0)
751         monVisuDialg.setWindowTitle(titre)
752         if self.code != None : monVisuDialg.TB.setText(self.VERSION_EFICAS +tr(" pour ") + self.code)
753         else :  monVisuDialg.TB.setText(self.VERSION_EFICAS )
754         monVisuDialg.adjustSize()
755         monVisuDialg.show()
756
757     def aidePPal(self) :
758         repAide=os.path.dirname(os.path.abspath(__file__))
759         maD=os.path.join( repAide,'..','Doc')
760         try :
761             indexAide=os.path.join(maD,'index.html')
762             if sys.platform[0:5]=="linux" : cmd="xdg-open "+indexAide
763             else                          : cmd="start "+indexAide
764             os.system(cmd)
765         except:
766             QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
767
768     def aidePSEN(self) :
769         repAide=os.path.dirname(os.path.abspath(__file__))
770         maD=os.path.join( repAide,'..','Doc')
771         try :
772             indexAide=os.path.join(maD,'index.html')
773             if sys.platform[0:5]=="linux" : cmd="xdg-open "+indexAide
774             else                          : cmd="start "+indexAide
775             os.system(cmd)
776         except:
777             QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
778
779     def aideCode(self) :
780         if self.code==None : return
781         try :
782         #if 1 :
783             if sys.platform[0:5]=="linux" : cmd="xdg-open "+self.fileDoc
784             else                          : cmd="start "+self.fileDoc
785             os.system(cmd)
786         except:
787         #else:
788             QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
789
790
791     def optionEditeur(self) :
792         try :
793             name='monOptions_'+self.code
794         except :
795             QMessageBox.critical( self,tr( "Parametrage"),tr( "Veuillez d abord choisir un code"))
796             return
797         try :
798         #if 1:
799             optionCode=__import__(name)
800         except :
801         #else :
802             QMessageBox.critical( self, tr("Parametrage"), tr("Pas de possibilite de personnalisation de la configuration "))
803             return
804         monOption=optionCode.Options(parent=self,modal = 0 ,configuration=self.maConfiguration)
805         monOption.show()
806
807     def optionPdf(self) :
808         from monOptionsPdf import OptionPdf
809         monOption=OptionPdf(parent=self,modal = 0 ,configuration=self.maConfiguration)
810         monOption.show()
811
812     def handleSortieComplete(self):
813         return self.viewmanager.saveCompleteCurrentEditor()
814
815     def handleShowRecentMenu(self):
816         """
817         Private method to set up recent files menu.
818         """
819         self.recentMenu.clear()
820
821         for rp in self.recent:
822             id = self.recentMenu.addAction(rp)
823             self.ficRecents[id]=rp
824             id.triggered.connect(self.handleOpenRecent)
825         self.recentMenu.addSeparator()
826         self.recentMenu.addAction(tr('&Effacer'), self.handleClearRecent)
827
828     def handleOpenPatrons(self):
829         idx=self.sender()
830         fichier=self.repIni+"/../Editeur/Patrons/"+self.code+"/"+self.ficPatrons[idx]
831         self.viewmanager.handleOpen(fichier=fichier, patron = 1)
832
833     def handleOpenRecent(self):
834         idx=self.sender()
835         fichier=self.ficRecents[idx]
836         self.viewmanager.handleOpen(fichier=fichier, patron =0 )
837
838     def handleClearRecent(self):
839         self.recent = QStringList()
840         self.sauveRecents()
841
842     def handleRechercherDsCatalogue(self):
843         if not self.viewmanager : return
844         self.viewmanager.handleRechercherDsCatalogue()
845
846     def fileNew(self):
847         try:
848             self.viewmanager.newEditor()
849         except EficasException as exc:
850             msg = str(exc)
851             if msg != "": QMessageBox.warning(self, tr(u"Erreur"), msg)
852
853     def openProcess(self):
854         ssCode=None
855         code="PSEN_N1"
856         self.cleanPath()
857         dirCode=os.path.abspath(os.path.join(os.path.abspath(__file__),'../..',"ProcessOutputs_Eficas"))
858         sys.path.insert(0,dirCode)
859         self.code=code
860         self.definitCode(code,ssCode)
861         self.multi=True
862         self.demande=False
863         self.initRecents()
864         self.fileOpen()
865
866
867     def fileOpen(self):
868         try:
869             self.viewmanager.handleOpen()
870         except EficasException as exc:
871             msg = str(exc)
872             if msg != "":
873                 QMessageBox.warning(self, tr(u"Erreur"), msg)
874
875     def sauveLigne(self):
876         return self.viewmanager.sauveLigneCurrentEditor()
877
878     def fileSave(self):
879         return self.viewmanager.saveCurrentEditor()
880
881     def fileSaveAs(self):
882         return self.viewmanager.saveAsCurrentEditor()
883
884     def fileClose(self):
885         self.viewmanager.handleClose(texte='&Fermer')
886
887     def fileCloseAll(self):
888         self.viewmanager.handleCloseAll(texte='&Fermer')
889
890     def fileExit(self):
891         # On peut sortir sur Abort
892         res=self.viewmanager.handleCloseAll()
893         if (res != 2) :
894             self.close()
895         return res
896
897     def editCopy(self):
898         self.viewmanager.handleEditCopy()
899
900     def editCut(self):
901         self.viewmanager.handleEditCut()
902
903     def editPaste(self):
904         self.viewmanager.handleEditPaste()
905
906     def rechercher(self):
907         self.viewmanager.handleRechercher()
908
909     def run(self):
910         self.viewmanager.run()
911
912     def saveRun(self):
913         self.viewmanager.saveRun()
914
915
916     def supprimer(self):
917         self.viewmanager.handleSupprimer()
918
919     def jdcFichierSource(self):
920         self.viewmanager.handleViewJdcFichierSource()
921
922     def jdcRapport(self):
923         self.viewmanager.handleViewJdcRapport()
924
925     def jdcRegles(self):
926         self.viewmanager.handleViewJdcRegles()
927
928     def gestionParam(self):
929         self.viewmanager.handleGestionParam()
930
931     def visuJdcPy(self):
932         self.viewmanager.handleViewJdcPy()
933
934     def ouvreArbre(self):
935         self.viewmanager.ouvreArbre()
936
937     def fermeArbre(self):
938         self.viewmanager.fermeArbre()
939
940     def newInclude(self):
941         self.viewmanager.newIncludeEditor()
942
943     def cleanPath(self):
944         for pathCode in self.ListePathCode:
945             try:
946                 aEnlever=os.path.abspath(os.path.join(os.path.dirname(__file__),'..',pathCode))
947                 sys.path.remove(aEnlever)
948             except :
949                 pass
950         for pathCode in self.listeAEnlever:
951             try:
952                 sys.path.remove(aEnlever)
953             except :
954                 pass
955
956
957     def closeEvent(self,event):
958         res=self.fileExit()
959         if res==2 : event.ignore()
960
961
962     def remplitIconesCommandes(self):
963         if self.maConfiguration.boutonDsMenuBar == False : return
964         if not hasattr(self, 'readercata') : return
965         from monLayoutBouton import MonLayoutBouton
966         if hasattr(self,'monLayoutBoutonRempli') : return
967         self.monLayoutBoutonRempli=MonLayoutBouton(self)
968
969     def handleAjoutEtape(self,nomEtape):
970         self.viewmanager.handleAjoutEtape(nomEtape)
971
972     def metMenuAJourUtilisateurs(self):
973         self.lesFonctionsUtilisateurs={}
974         if self.code not in self.mesScripts : return
975         if not hasattr(self.mesScripts[self.code],'dict_menu') : return
976         for monMenu in iter(self.mesScripts[self.code].dict_menu.items()) :
977             titre,lesFonctions= monMenu
978             self.menuOptions = self.menubar.addMenu("menuOptions")
979             self.menuOptions.setTitle(tr(titre))
980             for elt in lesFonctions :
981                 laFonctionUtilisateur, label, lesArguments = elt
982                 action = QAction(self)
983                 action.setText(label)
984             #action.triggered.connect(self.appelleFonctionUtilisateur)
985                 self.menuOptions.addAction(action)
986                 self.lesFonctionsUtilisateurs[action]=(laFonctionUtilisateur, lesArguments)
987             self.menuOptions.triggered.connect(self.handleFonctionUtilisateur)
988
989
990     def handleFonctionUtilisateur(self,action) :
991         (laFonctionUtilisateur, lesArguments)=self.lesFonctionsUtilisateurs[action]
992         self.viewmanager.handleFonctionUtilisateur(laFonctionUtilisateur, lesArguments)
993
994 if __name__=='__main__':
995
996     # Modules Eficas
997     rep=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__),'..','Adao')))
998     sys.path.append(rep)
999     from Adao import prefs
1000     from Adao import prefs_Adao
1001
1002     from Editeur import import_code
1003     from Editeur import session
1004
1005     # Analyse des arguments de la ligne de commande
1006     options=session.parse(sys.argv)
1007     code=options.code
1008
1009
1010     app = QApplication(sys.argv)
1011     #app.setMainWidget(mw) (qt3)
1012     Eficas=Appli()
1013     Eficas.show()
1014
1015     #mw.ouvreFichiers()
1016     #mw.show()
1017
1018     res=app.exec_()
1019     sys.exit(res)