1 # -*- coding: utf-8 -*-
2 # CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
20 # ======================================================================
23 from PyQt4.QtGui import *
24 from PyQt4.QtCore import *
28 def __init__(self,appliEficas):
29 self.appliEficas=appliEficas
32 self.appliEficas=appliEficas
35 self.untitledCount = 0
38 self.gridLayout = QGridLayout(self.appliEficas.centralWidget())
39 self.myQtab = QTabWidget(self.appliEficas.centralWidget())
40 self.gridLayout.addWidget(self.myQtab)
43 def handleOpen(self,fichier=None,patron=0,units=None):
45 fichier = QFileDialog.getOpenFileName(self.appliEficas,
46 self.appliEficas.trUtf8('Ouvrir Fichier'),
47 self.getOpenStartDir(),
48 self.appliEficas.trUtf8('JDC Files (*.comm);;''All Files (*)'))
49 if fichier.isNull(): return
50 from utilitaires import normabspath
51 fichier = normabspath(unicode(fichier))
52 maPage=self.getEditor( fichier,units=units)
54 def handleClose(self,doitSauverRecent = 1):
55 print "passage dans handleClose"
56 print self.dict_editors
57 if doitSauverRecent : self.appliEficas.sauveRecents()
58 index=self.myQtab.currentIndex()
60 self.checkDirty(self.dict_editors[index])
61 index=self.myQtab.currentIndex()
62 while index < len(self.dict_editors) -1 :
63 self.dict_editors[index]=self.dict_editors[index+1]
65 del self.dict_editors[len (self.dict_editors) -1]
67 del self.doubles[self.dict_editors[index]]
70 print self.dict_editors
71 self.myQtab.removeTab(index)
74 def handleCloseAll(self):
75 self.appliEficas.sauveRecents()
76 print "passage dans CloseAll"
77 print "self.dict_editors", self.dict_editors
78 while len(self.dict_editors) > 0 :
79 self.myQtab.setCurrentIndex(0)
82 def handleEditCopy(self):
83 print "passage dans handleEditCopy"
84 index=self.myQtab.currentIndex()
85 editor=self.dict_editors[index]
86 editor.handleEditCopy()
88 def handleEditCut(self):
89 print "passage dans handleEditCut"
90 index=self.myQtab.currentIndex()
91 editor=self.dict_editors[index]
92 editor.handleEditCut()
94 def handleEditPaste(self):
95 print "passage dans handleEditPaste"
96 index=self.myQtab.currentIndex()
97 editor=self.dict_editors[index]
98 editor.handleEditPaste()
100 def newEditor(self,include=0):
101 print "passage dans newEditor"
102 maPage=self.getEditor()
104 def newIncludeEditor(self):
105 self.newEditor(include=1)
107 def handleViewJdcFichierSource(self):
108 index=self.myQtab.currentIndex()
109 if index < 0 : return
110 self.dict_editors[index].viewJdcSource()
112 def handleViewJdcRapport(self):
113 index=self.myQtab.currentIndex()
114 if index < 0 : return
115 self.dict_editors[index].viewJdcRapport()
117 def handleViewJdcPy(self):
118 index=self.myQtab.currentIndex()
119 if index < 0 : return
120 self.dict_editors[index].viewJdcPy()
122 def saveCurrentEditor(self):
123 index=self.myQtab.currentIndex()
124 if index < 0 : return
125 editor=self.dict_editors[index]
126 if editor in self.doubles.keys() :
129 self.appliEficas.trUtf8("Fichier Duplique"),
130 self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."),
131 self.appliEficas.trUtf8("&Annuler"))
133 ok, newName = editor.saveFile()
135 fileName=os.path.basename(unicode(newName))
136 self.myQtab.setTabText(index,fileName)
138 def saveAsCurrentEditor(self):
139 index=self.myQtab.currentIndex()
140 editor=self.dict_editors[index]
141 oldName=editor.fichier
142 ok,newName = editor.saveFileAs()
144 fileName=os.path.basename(unicode(newName))
145 self.myQtab.setTabText(index,fileName)
146 if editor in self.doubles.keys():
147 if oldName != newName :
148 del self.doubles[editor]
151 def displayJDC(self,jdc,fn=None):
153 Public slot to display a file in an editor.
154 @param fn name of file to be opened
155 # insert filename into list of recently opened files
158 if fn != None : titre=fn.split("/")[-1]
159 editor = self.getEditor(fichier= fn, jdc = jdc ,include=1)
160 self.appliEficas.addToRecentList(editor.getFileName())
162 def getEditor(self,fichier = None,jdc = None, units = None,include=0):
166 for indexEditor in self.dict_editors.keys():
167 editor=self.dict_editors[indexEditor]
168 from utilitaires import samepath
169 if samepath(fichier, editor.getFileName()):
170 abort = QMessageBox.warning(self.appliEficas,
171 self.appliEficas.trUtf8("Fichier"),
172 self.appliEficas.trUtf8("Le fichier <b>%1</b> est deja ouvert.").arg(fichier),
173 self.appliEficas.trUtf8("&Duplication"),
174 self.appliEficas.trUtf8("&Abort"))
178 from editor import JDCEditor
179 editor = JDCEditor(fichier, jdc, self.myQtab,units=units,appli=self.appliEficas,vm = self,include=include)
181 self.doubles[editor]=double
182 if editor.jdc: # le fichier est bien un jdc
183 self.editors.append(editor)
189 self.addView(editor, fichier)
191 self.myQtab.setCurrentIndex(indexEditor)
193 index=self.myQtab.currentIndex()
195 self.dict_editors[index]=editor
198 def addView(self, win, fichier=None):
200 self.untitledCount += 1
201 self.myQtab.addTab(win, self.appliEficas.trUtf8("Untitled %1").arg(self.untitledCount))
203 liste=fichier.split('/')
205 if not QFileInfo(fichier).isWritable():
206 txt = '%s (ro)' % txt
207 self.myQtab.addTab(win, txt)
208 self.myQtab.setCurrentWidget(win)
209 self.currentEditor=win
212 def getOpenStartDir(self) :
213 #PN --> Les Preferences
215 userDir=os.path.expanduser("~/Eficas_install/")
221 def checkDirty(self, editor):
223 Private method to check dirty status and open a message window.
225 @param editor editor window to check
226 @return flag indicating successful reset of the dirty flag (boolean)
230 if (editor.modified) and (editor in self.doubles.keys()) :
231 res = QMessageBox.warning(
233 self.appliEficas.trUtf8("Fichier Duplique"),
234 self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."),
235 self.appliEficas.trUtf8("&Quitter"),
236 self.appliEficas.trUtf8("&Annuler"))
237 if res == 0 : return 1
240 fn = editor.getFileName()
242 fn = self.appliEficas.trUtf8('Noname')
243 res = QMessageBox.warning(self.appliEficas,
244 self.appliEficas.trUtf8("Fichier Modifie"),
245 self.appliEficas.trUtf8("Le fichier <b>%1</b> n a pas ete sauvegarde.")
247 self.appliEficas.trUtf8("&Sauvegarder"),
248 self.appliEficas.trUtf8("&Quitter "),
249 self.appliEficas.trUtf8("&Annuler"), 0, 2)
251 (ok, newName) = editor.saveFile()
253 fileName=os.path.basename(unicode(newName))
254 index=self.myQtab.currentIndex()
255 self.myQtab.setTabText(index,fileName)