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.appliEficas.CONFIGURATION.savedir,
48 self.appliEficas.trUtf8('JDC Files (*.comm);;''All Files (*)'))
49 if fichier.isNull(): return
50 fichier = os.path.abspath(unicode(fichier))
51 ulfile = os.path.abspath(unicode(fichier))
52 self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
53 self.appliEficas.addToRecentList(fichier)
54 maPage=self.getEditor( fichier,units=units)
56 def handleClose(self,doitSauverRecent = 1):
57 if doitSauverRecent : self.appliEficas.sauveRecents()
58 index=self.myQtab.currentIndex()
60 res=self.checkDirty(self.dict_editors[index])
61 if res == 2 : return 2 # l utilisateur a annule
62 index=self.myQtab.currentIndex()
64 while idx < len(self.dict_editors) -1 :
65 self.dict_editors[idx]=self.dict_editors[idx+1]
67 del self.dict_editors[len (self.dict_editors) -1]
69 del self.doubles[self.dict_editors[index]]
72 self.myQtab.removeTab(index)
77 index=self.myQtab.currentIndex()
79 editor=self.dict_editors[index]
83 index=self.myQtab.currentIndex()
85 editor=self.dict_editors[index]
89 index=self.myQtab.currentIndex()
91 editor=self.dict_editors[index]
95 index=self.myQtab.currentIndex()
97 editor=self.dict_editors[index]
100 def handleCloseAll(self):
102 self.appliEficas.sauveRecents()
103 while len(self.dict_editors) > 0 :
104 self.myQtab.setCurrentIndex(0)
105 res=self.handleClose(0)
106 if res==2 : return res # l utilsateur a annule
109 def handleEditCopy(self):
110 #print "passage dans handleEditCopy"
111 index=self.myQtab.currentIndex()
112 editor=self.dict_editors[index]
113 editor.handleEditCopy()
115 def handleEditCut(self):
116 #print "passage dans handleEditCut"
117 index=self.myQtab.currentIndex()
118 editor=self.dict_editors[index]
119 editor.handleEditCut()
121 def handleEditPaste(self):
122 #print "passage dans handleEditPaste"
123 index=self.myQtab.currentIndex()
124 editor=self.dict_editors[index]
125 editor.handleEditPaste()
127 def handleSupprimer(self):
128 index=self.myQtab.currentIndex()
129 editor=self.dict_editors[index]
130 editor.handleSupprimer()
132 def newEditor(self,include=0):
133 maPage=self.getEditor(include=include)
135 def newIncludeEditor(self):
136 self.newEditor(include=1)
138 def handleViewJdcFichierSource(self):
139 index=self.myQtab.currentIndex()
140 if index < 0 : return
141 self.dict_editors[index].viewJdcSource()
143 def handleViewJdcRapport(self):
144 index=self.myQtab.currentIndex()
145 if index < 0 : return
146 self.dict_editors[index].viewJdcRapport()
148 def handleViewJdcPy(self):
149 index=self.myQtab.currentIndex()
150 if index < 0 : return
151 self.dict_editors[index].viewJdcPy()
153 def saveCurrentEditor(self):
154 index=self.myQtab.currentIndex()
155 if index < 0 : return
158 print self.dict_editors
159 editor=self.dict_editors[index]
160 if editor in self.doubles.keys() :
163 self.appliEficas.trUtf8("Fichier Duplique"),
164 self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."),
165 self.appliEficas.trUtf8("&Annuler"))
167 ok, newName = editor.saveFile()
169 fileName=os.path.basename(unicode(newName))
170 self.myQtab.setTabText(index,fileName)
172 def saveAsCurrentEditor(self):
173 index=self.myQtab.currentIndex()
174 editor=self.dict_editors[index]
175 oldName=editor.fichier
176 ok,newName = editor.saveFileAs()
178 fileName=os.path.basename(unicode(newName))
179 self.myQtab.setTabText(index,fileName)
180 if editor in self.doubles.keys():
181 if oldName != newName :
182 del self.doubles[editor]
185 def displayJDC(self,jdc,fn=None):
187 Public slot to display a file in an editor.
188 @param fn name of file to be opened
189 # insert filename into list of recently opened files
192 if fn != None : titre=fn.split("/")[-1]
193 editor = self.getEditor(fichier= fn, jdc = jdc ,include=1)
194 self.appliEficas.addToRecentList(editor.getFileName())
196 def getEditor(self,fichier = None,jdc = None, units = None,include=0):
200 for indexEditor in self.dict_editors.keys():
201 editor=self.dict_editors[indexEditor]
202 if self.samepath(fichier, editor.getFileName()):
203 abort = QMessageBox.warning(self.appliEficas,
204 self.appliEficas.trUtf8("Fichier"),
205 self.appliEficas.trUtf8("Le fichier <b>%1</b> est deja ouvert.").arg(fichier),
206 self.appliEficas.trUtf8("&Duplication"),
207 self.appliEficas.trUtf8("&Abort"))
211 from editor import JDCEditor
212 editor = JDCEditor(self.appliEficas,fichier, jdc, self.myQtab,units=units,vm = self,include=include)
214 self.doubles[editor]=double
215 if editor.jdc: # le fichier est bien un jdc
216 self.editors.append(editor)
222 self.addView(editor, fichier)
224 self.myQtab.setCurrentIndex(indexEditor)
226 index=self.myQtab.currentIndex()
228 self.dict_editors[index]=editor
231 def addView(self, win, fichier=None):
233 self.untitledCount += 1
234 self.myQtab.addTab(win, self.appliEficas.trUtf8("Untitled %1").arg(self.untitledCount))
236 liste=fichier.split('/')
238 if not QFileInfo(fichier).isWritable():
239 txt = '%s (ro)' % txt
240 self.myQtab.addTab(win, txt)
241 self.myQtab.setCurrentWidget(win)
242 self.currentEditor=win
245 def getOpenStartDir(self) :
246 #PN --> Les Preferences
248 userDir=os.path.expanduser("~/Eficas_install/")
253 def samepath(self,f1, f2):
257 if f1 is None or f2 is None: return 0
258 if os.path.normcase(os.path.normpath(f1)) == os.path.normcase(os.path.normpath(f2)) : return 1
262 def checkDirty(self, editor):
264 Private method to check dirty status and open a message window.
266 @param editor editor window to check
267 @return flag indicating successful reset of the dirty flag (boolean)
270 if (editor.modified) and (editor in self.doubles.keys()) :
271 res = QMessageBox.warning(
273 self.appliEficas.trUtf8("Fichier Duplique"),
274 self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."),
275 self.appliEficas.trUtf8("&Quitter"),
276 self.appliEficas.trUtf8("&Annuler"))
277 if res == 0 : return 1
280 fn = editor.getFileName()
282 fn = self.appliEficas.trUtf8('Noname')
283 res = QMessageBox.warning(self.appliEficas,
284 self.appliEficas.trUtf8("Fichier Modifie"),
285 self.appliEficas.trUtf8("Le fichier <b>%1</b> n a pas ete sauvegarde.") .arg(fn),
286 self.appliEficas.trUtf8("&Sauvegarder"),
287 self.appliEficas.trUtf8("&Quitter "),
288 self.appliEficas.trUtf8("&Annuler") )
290 (ok, newName) = editor.saveFile()
292 fileName=os.path.basename(unicode(newName))
293 index=self.myQtab.currentIndex()
294 self.myQtab.setTabText(index,fileName)