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 self.appliEficas.addToRecentList(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 if self.samepath(fichier, editor.getFileName()):
169 abort = QMessageBox.warning(self.appliEficas,
170 self.appliEficas.trUtf8("Fichier"),
171 self.appliEficas.trUtf8("Le fichier <b>%1</b> est deja ouvert.").arg(fichier),
172 self.appliEficas.trUtf8("&Duplication"),
173 self.appliEficas.trUtf8("&Abort"))
177 from editor import JDCEditor
178 editor = JDCEditor(self.appliEficas,fichier, jdc, self.myQtab,units=units,vm = self,include=include)
180 self.doubles[editor]=double
181 if editor.jdc: # le fichier est bien un jdc
182 self.editors.append(editor)
188 self.addView(editor, fichier)
190 self.myQtab.setCurrentIndex(indexEditor)
192 index=self.myQtab.currentIndex()
194 self.dict_editors[index]=editor
197 def addView(self, win, fichier=None):
199 self.untitledCount += 1
200 self.myQtab.addTab(win, self.appliEficas.trUtf8("Untitled %1").arg(self.untitledCount))
202 liste=fichier.split('/')
204 if not QFileInfo(fichier).isWritable():
205 txt = '%s (ro)' % txt
206 self.myQtab.addTab(win, txt)
207 self.myQtab.setCurrentWidget(win)
208 self.currentEditor=win
211 def getOpenStartDir(self) :
212 #PN --> Les Preferences
214 userDir=os.path.expanduser("~/Eficas_install/")
219 def samepath(self,f1, f2):
223 if f1 is None or f2 is None: return 0
224 if os.path.normcase(os.path.normpath(f1)) == os.path.normcase(os.path.normpath(f2)) : return 1
228 def checkDirty(self, editor):
230 Private method to check dirty status and open a message window.
232 @param editor editor window to check
233 @return flag indicating successful reset of the dirty flag (boolean)
237 if (editor.modified) and (editor in self.doubles.keys()) :
238 res = QMessageBox.warning(
240 self.appliEficas.trUtf8("Fichier Duplique"),
241 self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."),
242 self.appliEficas.trUtf8("&Quitter"),
243 self.appliEficas.trUtf8("&Annuler"))
244 if res == 0 : return 1
247 fn = editor.getFileName()
249 fn = self.appliEficas.trUtf8('Noname')
250 res = QMessageBox.warning(self.appliEficas,
251 self.appliEficas.trUtf8("Fichier Modifie"),
252 self.appliEficas.trUtf8("Le fichier <b>%1</b> n a pas ete sauvegarde.")
254 self.appliEficas.trUtf8("&Sauvegarder"),
255 self.appliEficas.trUtf8("&Quitter "),
256 self.appliEficas.trUtf8("&Annuler"), 0, 2)
258 (ok, newName) = editor.saveFile()
260 fileName=os.path.basename(unicode(newName))
261 index=self.myQtab.currentIndex()
262 self.myQtab.setTabText(index,fileName)