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)
41 if self.appliEficas.multi== True:
42 self.myQtab.connect(self.myQtab,SIGNAL("currentChanged(int)"),self.indexChanged)
44 def indexChanged(self):
45 index=self.myQtab.currentIndex()
46 if self.dict_editors.has_key(index):
47 editor=self.dict_editors[index]
48 self.appliEficas.CONFIGURATION=editor.CONFIGURATION
49 self.appliEficas.setWindowTitle(editor.titre)
51 def handleOpen(self,fichier=None,patron=0,units=None):
54 if self.appliEficas.multi==True :
55 self.appliEficas.definitCode(None,None)
56 fichier = QFileDialog.getOpenFileName(self.appliEficas,
57 self.appliEficas.trUtf8('Ouvrir Fichier'),
58 self.appliEficas.CONFIGURATION.savedir,
59 self.appliEficas.trUtf8('JDC Files (*.comm);;''All Files (*)'))
62 fichier = os.path.abspath(unicode(fichier))
63 ulfile = os.path.abspath(unicode(fichier))
64 self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
65 self.appliEficas.addToRecentList(fichier)
66 maPage=self.getEditor( fichier,units=units)
71 def handleClose(self,doitSauverRecent = 1,texte='&Quitter'):
72 if doitSauverRecent : self.appliEficas.sauveRecents()
73 index=self.myQtab.currentIndex()
75 res=self.checkDirty(self.dict_editors[index],texte)
76 if res == 2 : return 2 # l utilisateur a annule
77 index=self.myQtab.currentIndex()
79 while idx < len(self.dict_editors) -1 :
80 self.dict_editors[idx]=self.dict_editors[idx+1]
82 del self.dict_editors[len (self.dict_editors) -1]
84 del self.doubles[self.dict_editors[index]]
87 self.myQtab.removeTab(index)
92 index=self.myQtab.currentIndex()
94 editor=self.dict_editors[index]
98 index=self.myQtab.currentIndex()
100 editor=self.dict_editors[index]
104 index=self.myQtab.currentIndex()
105 if index < 0 : return
106 editor=self.dict_editors[index]
110 index=self.myQtab.currentIndex()
111 if index < 0 : return
112 editor=self.dict_editors[index]
115 def handleCloseAll(self,texte='Quitter'):
117 self.appliEficas.sauveRecents()
118 while len(self.dict_editors) > 0 :
119 self.myQtab.setCurrentIndex(0)
120 res=self.handleClose(0,texte)
121 if res==2 : return res # l utilsateur a annule
124 def handleEditCopy(self):
125 #print "passage dans handleEditCopy"
126 index=self.myQtab.currentIndex()
127 editor=self.dict_editors[index]
128 editor.handleEditCopy()
130 def handleEditCut(self):
131 #print "passage dans handleEditCut"
132 index=self.myQtab.currentIndex()
133 editor=self.dict_editors[index]
134 editor.handleEditCut()
136 def handleEditPaste(self):
137 #print "passage dans handleEditPaste"
138 index=self.myQtab.currentIndex()
139 editor=self.dict_editors[index]
140 editor.handleEditPaste()
142 def handleSupprimer(self):
143 index=self.myQtab.currentIndex()
144 editor=self.dict_editors[index]
145 editor.handleSupprimer()
147 def newEditor(self,include=0):
148 if self.appliEficas.multi==True :
149 self.appliEficas.definitCode(None,None)
150 maPage=self.getEditor(include=include)
152 def newIncludeEditor(self):
153 self.newEditor(include=1)
155 def handleViewJdcFichierSource(self):
156 index=self.myQtab.currentIndex()
157 if index < 0 : return
158 self.dict_editors[index].viewJdcSource()
160 def handleViewJdcRapport(self):
161 index=self.myQtab.currentIndex()
162 if index < 0 : return
163 self.dict_editors[index].viewJdcRapport()
165 def handleViewJdcPy(self):
166 index=self.myQtab.currentIndex()
167 if index < 0 : return
168 self.dict_editors[index].viewJdcPy()
170 def saveCurrentEditor(self):
171 index=self.myQtab.currentIndex()
172 if index < 0 : return
173 editor=self.dict_editors[index]
174 if editor in self.doubles.keys() :
177 self.appliEficas.trUtf8("Fichier Duplique"),
178 self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."),
179 self.appliEficas.trUtf8("&Annuler"))
181 ok, newName = editor.saveFile()
183 fileName=os.path.basename(unicode(newName))
184 self.myQtab.setTabText(index,fileName)
187 def saveAsCurrentEditor(self):
188 index=self.myQtab.currentIndex()
189 editor=self.dict_editors[index]
190 oldName=editor.fichier
191 ok,newName = editor.saveFileAs()
193 fileName=os.path.basename(unicode(newName))
194 self.myQtab.setTabText(index,fileName)
195 if editor in self.doubles.keys():
196 if oldName != newName :
197 del self.doubles[editor]
200 def displayJDC(self,jdc,fn=None):
202 Public slot to display a file in an editor.
203 @param fn name of file to be opened
204 # insert filename into list of recently opened files
207 if fn != None : titre=fn.split("/")[-1]
208 editor = self.getEditor(fichier= fn, jdc = jdc ,include=1)
209 self.appliEficas.addToRecentList(editor.getFileName())
211 def getEditor(self,fichier = None,jdc = None, units = None,include=0):
215 for indexEditor in self.dict_editors.keys():
216 editor=self.dict_editors[indexEditor]
217 if self.samepath(fichier, editor.getFileName()):
218 abort = QMessageBox.warning(self.appliEficas,
219 self.appliEficas.trUtf8("Fichier"),
220 self.appliEficas.trUtf8("Le fichier <b>%1</b> est deja ouvert.").arg(fichier),
221 self.appliEficas.trUtf8("&Duplication"),
222 self.appliEficas.trUtf8("&Abort"))
226 from editor import JDCEditor
227 editor = JDCEditor(self.appliEficas,fichier, jdc, self.myQtab,units=units,vm = self,include=include)
229 self.doubles[editor]=double
230 if editor.jdc: # le fichier est bien un jdc
231 self.editors.append(editor)
237 self.addView(editor, fichier)
239 self.myQtab.setCurrentIndex(indexEditor)
241 index=self.myQtab.currentIndex()
243 self.dict_editors[index]=editor
246 def addView(self, win, fichier=None):
248 self.untitledCount += 1
249 self.myQtab.addTab(win, self.appliEficas.trUtf8("Untitled %1").arg(self.untitledCount))
251 liste=fichier.split('/')
253 if not QFileInfo(fichier).isWritable():
254 txt = '%s (ro)' % txt
255 self.myQtab.addTab(win, txt)
256 self.myQtab.setCurrentWidget(win)
257 self.currentEditor=win
260 def getOpenStartDir(self) :
261 #PN --> Les Preferences
263 userDir=os.path.expanduser("~/Eficas_install/")
268 def samepath(self,f1, f2):
272 if f1 is None or f2 is None: return 0
273 if os.path.normcase(os.path.normpath(f1)) == os.path.normcase(os.path.normpath(f2)) : return 1
277 def checkDirty(self, editor,texte):
279 Private method to check dirty status and open a message window.
281 @param editor editor window to check
282 @return flag indicating successful reset of the dirty flag (boolean)
285 if (editor.modified) and (editor in self.doubles.keys()) :
286 res = QMessageBox.warning(
288 self.appliEficas.trUtf8("Fichier Duplique"),
289 self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."),
290 self.appliEficas.trUtf8(texte),
291 self.appliEficas.trUtf8("&Annuler"))
292 if res == 0 : return 1
295 fn = editor.getFileName()
297 fn = self.appliEficas.trUtf8('Noname')
298 res = QMessageBox.warning(self.appliEficas,
299 self.appliEficas.trUtf8("Fichier Modifie"),
300 self.appliEficas.trUtf8("Le fichier <b>%1</b> n a pas ete sauvegarde.") .arg(fn),
301 self.appliEficas.trUtf8("&Sauvegarder"),
302 self.appliEficas.trUtf8(texte),
303 self.appliEficas.trUtf8("&Annuler") )
305 (ok, newName) = editor.saveFile()
307 fileName=os.path.basename(unicode(newName))
308 index=self.myQtab.currentIndex()
309 self.myQtab.setTabText(index,fileName)
313 def handleAjoutGroup(self,listeGroup):
314 index=self.myQtab.currentIndex()
315 editor=self.dict_editors[index]
316 editor.handleAjoutGroup(listeGroup)