1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 from PyQt4.QtGui import *
23 from PyQt4.QtCore import *
24 from Extensions.i18n import tr
26 DictExtensions= {"MAP" : ".map"}
29 def __init__(self,appliEficas):
30 self.appliEficas=appliEficas
33 self.appliEficas=appliEficas
36 self.untitledCount = 0
39 self.myQtab = self.appliEficas.myQtab
40 if self.appliEficas.multi== True:
41 self.myQtab.connect(self.myQtab,SIGNAL("currentChanged(int)"),self.indexChanged)
43 def indexChanged(self):
44 index=self.myQtab.currentIndex()
45 if self.dict_editors.has_key(index):
46 editor=self.dict_editors[index]
47 self.appliEficas.CONFIGURATION=editor.CONFIGURATION
48 self.appliEficas.code=editor.CONFIGURATION.code
49 self.appliEficas.setWindowTitle(editor.titre)
50 self.appliEficas.construitMenu()
52 def handleOpen(self,fichier=None,patron=0,units=None):
55 if self.appliEficas.multi==True :
56 self.appliEficas.definitCode(None,None)
57 if self.appliEficas.code == None:return
59 if DictExtensions.has_key(self.appliEficas.code) :
60 chaine="JDC (*"+DictExtensions[self.appliEficas.code]+");;"
61 extensions=tr(chaine+ "All Files (*)")
63 extensions=tr('Fichiers JDC (*.comm);;''Tous les Fichiers (*)')
65 fichier = QFileDialog.getOpenFileName(self.appliEficas,
67 self.appliEficas.CONFIGURATION.savedir,
71 fichier = os.path.abspath(unicode(fichier))
72 ulfile = os.path.abspath(unicode(fichier))
73 self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
74 self.appliEficas.addToRecentList(fichier)
75 maPage=self.getEditor( fichier,units=units)
76 if maPage: result = maPage
77 if maPage : self.myQtab.setTabText(self.myQtab.indexOf(maPage),os.path.basename(fichier))
80 def handleClose(self,doitSauverRecent = 1,texte=tr('&Quitter')):
81 if doitSauverRecent : self.appliEficas.sauveRecents()
82 index=self.myQtab.currentIndex()
84 res=self.checkDirty(self.dict_editors[index],texte)
85 if res == 2 : return 2 # l utilisateur a annule
86 index=self.myQtab.currentIndex()
88 while idx < len(self.dict_editors) -1 :
89 self.dict_editors[idx]=self.dict_editors[idx+1]
91 del self.dict_editors[len (self.dict_editors) -1]
93 del self.doubles[self.dict_editors[index]]
96 self.myQtab.removeTab(index)
101 index=self.myQtab.currentIndex()
102 if index < 0 : return
103 editor=self.dict_editors[index]
107 index=self.myQtab.currentIndex()
108 if index < 0 : return
109 editor=self.dict_editors[index]
112 def handleCloseAll(self,texte=tr('Quitter')):
114 self.appliEficas.sauveRecents()
115 while len(self.dict_editors) > 0 :
116 self.myQtab.setCurrentIndex(0)
117 res=self.handleClose(0,texte)
118 if res==2 : return res # l utilsateur a annule
121 def handleRechercher(self):
122 #print "passage dans handleRechercher"
123 index=self.myQtab.currentIndex()
124 if index < 0 : return
125 editor=self.dict_editors[index]
126 editor.handleRechercher()
128 def handleDeplier(self):
129 index=self.myQtab.currentIndex()
130 if index < 0 : return
131 editor=self.dict_editors[index]
132 editor.handleDeplier()
134 def handleEditCopy(self):
135 #print "passage dans handleEditCopy"
136 index=self.myQtab.currentIndex()
137 if index < 0 : return
138 editor=self.dict_editors[index]
139 editor.handleEditCopy()
141 def handleEditCut(self):
142 #print "passage dans handleEditCut"
143 index=self.myQtab.currentIndex()
144 if index < 0 : return
145 editor=self.dict_editors[index]
146 editor.handleEditCut()
148 def handleEditPaste(self):
149 #print "passage dans handleEditPaste"
150 index=self.myQtab.currentIndex()
151 if index < 0 : return
152 editor=self.dict_editors[index]
153 editor.handleEditPaste()
155 def handleSupprimer(self):
156 index=self.myQtab.currentIndex()
157 if index < 0 : return
158 editor=self.dict_editors[index]
159 editor.handleSupprimer()
161 def newEditor(self,include=0):
162 if self.appliEficas.multi==True :
163 self.appliEficas.definitCode(None,None)
164 if self.appliEficas.code == None:return
165 maPage=self.getEditor(include=include)
167 def newIncludeEditor(self):
168 self.newEditor(include=1)
170 def handleViewJdcFichierSource(self):
171 index=self.myQtab.currentIndex()
172 if index < 0 : return
173 self.dict_editors[index].viewJdcSource()
175 def handleViewJdcRapport(self):
176 index=self.myQtab.currentIndex()
177 if index < 0 : return
178 self.dict_editors[index].viewJdcRapport()
180 def handleViewJdcPy(self):
181 index=self.myQtab.currentIndex()
182 if index < 0 : return
183 self.dict_editors[index].viewJdcPy()
185 def saveCurrentEditor(self):
186 index=self.myQtab.currentIndex()
187 if index < 0 : return
188 editor=self.dict_editors[index]
189 if editor in self.doubles.keys() :
192 tr("Fichier Duplique"),
193 tr("Le fichier ne sera pas sauvegarde."),
196 ok, newName = editor.saveFile()
198 fileName=os.path.basename(unicode(newName))
199 self.myQtab.setTabText(index,fileName)
202 def saveAsCurrentEditor(self):
203 index=self.myQtab.currentIndex()
204 editor=self.dict_editors[index]
205 oldName=editor.fichier
206 ok,newName = editor.saveFileAs()
208 fileName=os.path.basename(unicode(newName))
209 self.myQtab.setTabText(index,fileName)
210 if editor in self.doubles.keys():
211 if oldName != newName :
212 del self.doubles[editor]
215 def displayJDC(self,jdc,fn=None):
217 Public slot to display a file in an editor.
218 @param fn name of file to be opened
219 # insert filename into list of recently opened files
222 if fn != None : titre=fn.split("/")[-1]
223 editor = self.getEditor(fichier= fn, jdc = jdc ,include=1)
224 self.appliEficas.addToRecentList(editor.getFileName())
226 def getEditor(self,fichier = None,jdc = None, units = None,include=0):
230 for indexEditor in self.dict_editors.keys():
231 editor=self.dict_editors[indexEditor]
232 if self.samepath(fichier, editor.getFileName()):
233 abort = QMessageBox.warning(self.appliEficas,
235 tr("Le fichier <b>%s</b> est deja ouvert.",str(fichier)),
241 from editor import JDCEditor
242 editor = JDCEditor(self.appliEficas,fichier, jdc, self.myQtab,units=units,vm = self,include=include)
244 self.doubles[editor]=double
245 if editor.jdc: # le fichier est bien un jdc
246 self.editors.append(editor)
252 self.addView(editor, fichier)
254 self.myQtab.setCurrentIndex(indexEditor)
256 index=self.myQtab.currentIndex()
258 self.dict_editors[index]=editor
261 def addView(self, win, fichier=None):
262 #PNPNPNPN --> a affiner
264 self.untitledCount += 1
265 self.myQtab.addTab(win, tr("Fichier non encore nommé ", self.untitledCount))
266 #self.myQtab.addTab(win, str(self.appliEficas.code))
268 liste=fichier.split('/')
270 if not QFileInfo(fichier).isWritable():
271 txt = '%s (ro)' % txt
272 self.myQtab.addTab(win,txt )
273 self.myQtab.setCurrentWidget(win)
274 self.currentEditor=win
277 def getOpenStartDir(self) :
278 #PN --> Les Preferences
280 userDir=os.path.expanduser("~/Eficas_install/")
285 def samepath(self,f1, f2):
289 if f1 is None or f2 is None: return 0
290 if os.path.normcase(os.path.normpath(f1)) == os.path.normcase(os.path.normpath(f2)) : return 1
294 def checkDirty(self, editor,texte):
296 Private method to check dirty status and open a message window.
298 @param editor editor window to check
299 @return flag indicating successful reset of the dirty flag (boolean)
302 if (editor.modified) and (editor in self.doubles.keys()) :
303 res = QMessageBox.warning(
305 tr("Fichier Duplique"),
306 tr("Le fichier ne sera pas sauvegarde."),
309 if res == 0 : return 1
312 fn = editor.getFileName()
314 fn = self.appliEficas.trUtf8('Noname')
315 res = QMessageBox.warning(self.appliEficas,
316 tr("Fichier Modifie"),
317 tr("Le fichier %s n a pas ete sauvegarde.",str(fn)),
322 (ok, newName) = editor.saveFile()
324 fileName=os.path.basename(unicode(newName))
325 index=self.myQtab.currentIndex()
326 self.myQtab.setTabText(index,fileName)
330 def handleAjoutGroup(self,listeGroup):
331 index=self.myQtab.currentIndex()
332 if index < 0 : return
333 editor=self.dict_editors[index]
334 editor.handleAjoutGroup(listeGroup)