Salome HOME
5f633e6e2971b9281e1daac349b76f78d7039fe0
[tools/eficas.git] / InterfaceQT4 / qtEficas.py
1 # -*- coding: iso-8859-1 -*-
2
3 import os, sys
4 REPINI=os.path.dirname(os.path.abspath(__file__))
5 INSTALLDIR=os.path.join(REPINI,'..')
6 sys.path.append(INSTALLDIR)
7 sys.path.append(INSTALLDIR+"/UiQT4")
8 sys.path.append(INSTALLDIR+"/InterfaceQT4")
9
10 from PyQt4.QtGui  import *
11 from PyQt4.QtCore import *
12 from PyQt4.QtAssistant import *
13 from myMain import Ui_Eficas
14 from viewManager import MyTabview
15
16 from Editeur import configuration
17 from Editeur import session
18
19
20
21 class Appli(Ui_Eficas,QMainWindow):    
22     """
23     Class implementing the main user interface.
24     """
25     def __init__(self,code="ASTER",salome=0,parent=None):
26         """
27         Constructor
28         """
29         self.ihm="QT"
30         self.code=code
31         self.salome=salome
32         self.top = self #(pour CONFIGURATION)
33
34         self.initPrefs()
35         self.CONFIGURATION = configuration.make_config(self,prefs.REPINI)
36         self.CONFIGStyle = configuration.make_config_style(self,prefs.REPINI)
37
38         QMainWindow.__init__(self)
39         Ui_Eficas.__init__(self)
40         self.setupUi(self)
41         self.viewmanager = MyTabview(self) 
42         self.recentMenu=self.menuFichier.addMenu(self.trUtf8('&Recents'))
43         self.connecterSignaux() 
44
45
46         #self.monAssistant=QAssistantClient(QString(""), self.viewmanager)
47         
48         #if self.salome :
49         #   from Editeur import session
50         #   self.ouvreFichiers()
51         from Editeur import session
52         self.ouvreFichiers()
53
54         self.ficPatrons={}
55         self.initPatrons()
56
57         self.recent =  QStringList()
58         self.ficRecents={}
59         self.initRecents()
60         
61     def OPENTURNS(self) :
62         self.MenuBar.removeItem(5)
63         self.MenuBar.removeItem(6)
64         self.MenuBar.removeItem(7)
65
66
67     def connecterSignaux(self) :
68         self.connect(self.recentMenu,SIGNAL('aboutToShow()'),self.handleShowRecentMenu)
69
70         self.connect(self.action_Nouveau,SIGNAL("activated()"),self.fileNew)
71         self.connect(self.actionNouvel_Include,SIGNAL("activated()"),self.NewInclude)
72         self.connect(self.action_Ouvrir,SIGNAL("activated()"),self.fileOpen)
73         self.connect(self.actionEnregistrer,SIGNAL("activated()"),self.fileSave)
74         self.connect(self.actionEnregistrer_sous,SIGNAL("activated()"),self.fileSaveAs)
75         self.connect(self.actionFermer,SIGNAL("activated()"),self.fileClose)
76         self.connect(self.actionFermer_tout,SIGNAL("activated()"),self.fileCloseAll)
77         self.connect(self.actionQuitter,SIGNAL("activated()"),self.fileExit)
78
79         self.connect(self.actionCouper,SIGNAL("activated()"),self.editCut)
80         self.connect(self.actionCopier,SIGNAL("activated()"),self.editCopy)
81         self.connect(self.actionColler,SIGNAL("activated()"),self.editPaste)
82
83         self.connect(self.actionRapport_de_Validation,SIGNAL("activated()"),self.jdcRapport)
84         self.connect(self.actionFichier_Source,SIGNAL("activated()"),self.jdcFichierSource)
85         self.connect(self.actionFichier_Resultat,SIGNAL("activated()"),self.visuJdcPy)
86
87         self.connect(self.actionParametres_Eficas,SIGNAL("activated()"),self.optionEditeur)
88         self.connect(self.actionLecteur_Pdf,SIGNAL("activated()"),self.optionPdf)
89
90         self.connect(self.actionTraduitV7V8,SIGNAL("activated()"),self.traductionV7V8)
91         self.connect(self.actionTraduitV8V9,SIGNAL("activated()"),self.traductionV8V9)
92
93         #self.connect(self.helpIndexAction,SIGNAL("activated()"),self.helpIndex)
94         #self.connect(self.helpContentsAction,SIGNAL("activated()"),self.helpContents)
95         #self.connect(self.helpAboutAction,SIGNAL("activated()"),self.helpAbout)
96         #self.connect(self.aidenew_itemAction,SIGNAL("activated()"),self.helpAbout)
97                              
98
99     def ouvreFichiers(self) :
100     # Ouverture des fichiers de commandes donnes sur la ligne de commande
101         cwd=os.getcwd()
102         self.dir=cwd
103         for study in session.d_env.studies:
104             os.chdir(cwd)
105             d=session.get_unit(study,self)
106             self.viewmanager.handleOpen(fichier=study["comm"],units=d)
107
108     def  get_source(self,file):
109     # appele par Editeur/session.py
110         import convert
111         p=convert.plugins['python']()
112         p.readfile(file)
113         texte=p.convert('execnoparseur')
114         return texte
115
116
117         
118     def initPatrons(self) :
119     # Mise à jour du menu des fichiers recemment ouverts
120         from Editeur import listePatrons
121         self.listePatrons = listePatrons.listePatrons(self.code)
122         idx = 0
123         for nomSsMenu in self.listePatrons.liste.keys():
124             ssmenu=self.menuPatrons.addMenu(nomSsMenu)
125             for fichier in self.listePatrons.liste[nomSsMenu]:
126                id = ssmenu.addAction(fichier)
127                self.ficPatrons[id]=fichier
128                self.connect(id, SIGNAL('triggered()'),self.handleOpenPatrons)
129             #   self.Patrons.setItemParameter(id,idx)
130                idx=idx+1
131
132     def initRecents(self):
133        #try :
134        if 1 :
135            rep=self.CONFIGURATION.rep_user
136            monFichier=rep+"/listefichiers_"+self.code
137            index=0
138            f=open(monFichier)
139            while ( index < 9) :
140               ligne=f.readline()
141               if ligne != "" :
142                  l=(ligne.split("\n"))[0]
143                  self.recent.append(l)
144               index=index+1
145        #except : pass
146        else :
147            pass
148
149        try    : f.close()
150        except : pass
151
152     def addToRecentList(self, fn):
153         """
154         Public slot to add a filename to the list of recently opened files.
155
156         @param fn name of the file to be added
157         """
158         self.recent.removeAll(fn)
159         self.recent.prepend(fn)
160         if len(self.recent) > 9:
161             self.recent = self.recent[:9]
162
163     def sauveRecents(self) :
164        rep=self.CONFIGURATION.rep_user
165        monFichier=rep+"/listefichiers_"+self.code
166        try :
167             f=open(monFichier,'w')
168             if len(self.recent) == 0 : return
169             index=0
170             while ( index <  len(self.recent)):
171               ligne=str(self.recent[index])+"\n"
172               f.write(ligne)
173               index=index+1
174        except :
175             pass
176        try :
177             f.close()
178        except :
179             pass
180
181
182
183     def traductionV7V8(self):
184         from gereTraduction import traduction
185         traduction(self.CONFIGURATION.rep_user,self.viewmanager,"V7V8")
186
187     def traductionV8V9(self):
188         from gereTraduction import traduction
189         traduction(self.CONFIGURATION.rep_user,self.viewmanager,"V8V9")
190
191     def version(self) :
192         from desVisu import DVisu
193         titre = "version "
194         monVisu=DVisu(parent=self.viewmanager)
195         monVisu.setCaption(titre)
196         monVisu.TB.setText("Eficas V1.13")
197         monVisu.adjustSize()
198         monVisu.show()
199
200     def aidePPal(self) :
201         maD=INSTALLDIR+"/AIDE/fichiers"
202         docsPath = QDir(maD).absPath()
203         self.monAssistant.showPage( QString("%1/index.html").arg(docsPath) )
204
205     def optionEditeur(self) :
206         from monOptionsEditeur import Options
207         monOption=Options(parent=self,modal = 0 ,configuration=self.CONFIGURATION)
208         monOption.show()
209         
210     def optionPdf(self) :
211         from monOptionsPdf import OptionPdf
212         monOption=OptionPdf(parent=self,modal = 0 ,configuration=self.CONFIGURATION)
213         monOption.show()
214         
215     def handleShowRecentMenu(self):
216         """
217         Private method to set up recent files menu.
218         """
219         self.recentMenu.clear()
220         
221         for rp in self.recent:
222             id = self.recentMenu.addAction(rp)
223             self.ficRecents[id]=rp
224             self.connect(id, SIGNAL('triggered()'),self.handleOpenRecent)
225         self.recentMenu.addSeparator()
226         self.recentMenu.addAction(self.trUtf8('&Clear'), self.handleClearRecent)
227         
228     def handleOpenPatrons(self):
229         idx=self.sender()
230         fichier=REPINI+"/../Editeur/Patrons/"+self.code+"/"+self.ficPatrons[idx]
231         self.viewmanager.handleOpen(fichier=fichier, patron = 1)
232
233     def handleOpenRecent(self):
234         idx=self.sender()
235         fichier=self.ficRecents[idx]
236         self.viewmanager.handleOpen(fichier=fichier, patron =0 )
237         
238     def handleClearRecent(self):
239         self.recent = QStringList()
240         
241     def fileNew(self):        
242         self.viewmanager.newEditor()        
243         
244     def fileOpen(self ):
245         self.viewmanager.handleOpen()        
246         
247     def fileSave(self):
248         self.viewmanager.saveCurrentEditor()
249         
250     def fileSaveAs(self):
251         self.viewmanager.saveAsCurrentEditor()
252         
253     def fileClose(self):
254         self.viewmanager.handleClose()
255         
256     def fileCloseAll(self):
257         self.viewmanager.handleCloseAll()
258         
259     def fileExit(self):
260         # On peut sortir sur Abort
261         self.viewmanager.handleCloseAll()
262         if self.salome :
263            self.close()
264         else :
265            qApp.closeAllWindows()
266         
267     def editCopy(self):
268         self.viewmanager.handleEditCopy()
269       
270     def editCut(self):
271         self.viewmanager.handleEditCut()
272     
273     def editPaste(self):
274         self.viewmanager.handleEditPaste()
275         
276     def jdcFichierSource(self):
277         self.viewmanager.handleViewJdcFichierSource()
278         
279     def jdcRapport(self):
280         self.viewmanager.handleViewJdcRapport()
281         
282     def visuJdcPy(self):
283         self.viewmanager.handleViewJdcPy()
284
285     def helpAbout(self):
286         import AIDE
287         AIDE.go3(parent=self)
288
289     def NewInclude(self):
290         self.viewmanager.newIncludeEditor()
291
292     def initPrefs(self):
293         if code == "ASTER" : 
294            from Aster import prefs
295            import sys
296            sys.path.append(INSTALLDIR+"/Aster")
297         else :
298            import prefs 
299            #try :
300            if 1 :
301              apply(Appli.__dict__[code],(self,))
302            #except :
303            else:
304              pass
305         if hasattr(prefs,'encoding'):
306            import sys
307            reload(sys)
308            sys.setdefaultencoding(prefs.encoding)
309
310 if __name__=='__main__':
311
312     # Modules Eficas
313     sys.path.append(INSTALLDIR+"/Aster")
314     from Aster import prefs
315     if hasattr(prefs,'encoding'):
316        # Hack pour changer le codage par defaut des strings
317        import sys
318        reload(sys)
319        sys.setdefaultencoding(prefs.encoding)
320        del sys.setdefaultencoding
321        # Fin hack
322
323     from Editeur import import_code
324     from Editeur import session
325
326     # Analyse des arguments de la ligne de commande
327     options=session.parse(sys.argv)
328     code=options.code
329
330
331     app = QApplication(sys.argv)
332     #app.setMainWidget(mw) (qt3)
333     Eficas=Appli()
334     Eficas.show()
335
336     #app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
337     #mw.ouvreFichiers()
338     #mw.show()
339
340     res=app.exec_()
341     sys.exit(res)