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 self.myQtab.connect(self.myQtab, SIGNAL('tabCloseRequested(int)'), self.closeTab)
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.code=editor.CONFIGURATION.code
50 self.appliEficas.setWindowTitle(editor.titre)
51 self.appliEficas.construitMenu()
53 def handleOpen(self,fichier=None,patron=0,units=None):
56 if self.appliEficas.multi==True :
57 self.appliEficas.definitCode(None,None)
58 if self.appliEficas.code == None:return
60 if DictExtensions.has_key(self.appliEficas.code) :
61 chaine="JDC (*"+DictExtensions[self.appliEficas.code]+");;"
62 extensions=tr(chaine+ "All Files (*)")
64 extensions=tr('Fichiers JDC (*.comm);;''Tous les Fichiers (*)')
66 fichier = QFileDialog.getOpenFileName(self.appliEficas,
68 self.appliEficas.CONFIGURATION.savedir,
72 fichier = os.path.abspath(unicode(fichier))
73 ulfile = os.path.abspath(unicode(fichier))
74 self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
75 self.appliEficas.addToRecentList(fichier)
76 maPage=self.getEditor( fichier,units=units)
77 if maPage: result = maPage
78 if maPage : self.myQtab.setTabText(self.myQtab.indexOf(maPage),os.path.basename(fichier))
84 def handleClose(self,doitSauverRecent = 1,texte=tr('&Quitter')):
85 if doitSauverRecent : self.appliEficas.sauveRecents()
86 index=self.myQtab.currentIndex()
88 res=self.checkDirty(self.dict_editors[index],texte)
89 if res == 2 : return 2 # l utilisateur a annule
90 index=self.myQtab.currentIndex()
92 while idx < len(self.dict_editors) -1 :
93 self.dict_editors[idx]=self.dict_editors[idx+1]
95 del self.dict_editors[len (self.dict_editors) -1]
97 del self.doubles[self.dict_editors[index]]
100 self.myQtab.removeTab(index)
105 index=self.myQtab.currentIndex()
106 if index < 0 : return
107 editor=self.dict_editors[index]
111 index=self.myQtab.currentIndex()
112 if index < 0 : return
113 editor=self.dict_editors[index]
116 def handleCloseAll(self,texte=tr('Quitter')):
118 self.appliEficas.sauveRecents()
119 while len(self.dict_editors) > 0 :
120 self.myQtab.setCurrentIndex(0)
121 res=self.handleClose(0,texte)
122 if res==2 : return res # l utilsateur a annule
125 def handleRechercher(self):
126 #print "passage dans handleRechercher"
127 index=self.myQtab.currentIndex()
128 if index < 0 : return
129 editor=self.dict_editors[index]
130 editor.handleRechercher()
132 def handleDeplier(self):
133 index=self.myQtab.currentIndex()
134 if index < 0 : return
135 editor=self.dict_editors[index]
136 editor.handleDeplier()
138 def handleEditCopy(self):
139 #print "passage dans handleEditCopy"
140 index=self.myQtab.currentIndex()
141 if index < 0 : return
142 editor=self.dict_editors[index]
143 editor.handleEditCopy()
145 def handleEditCut(self):
146 #print "passage dans handleEditCut"
147 index=self.myQtab.currentIndex()
148 if index < 0 : return
149 editor=self.dict_editors[index]
150 editor.handleEditCut()
152 def handleEditPaste(self):
153 #print "passage dans handleEditPaste"
154 index=self.myQtab.currentIndex()
155 if index < 0 : return
156 editor=self.dict_editors[index]
157 editor.handleEditPaste()
159 def handleSupprimer(self):
160 index=self.myQtab.currentIndex()
161 if index < 0 : return
162 editor=self.dict_editors[index]
163 editor.handleSupprimer()
165 def newEditor(self,include=0):
166 if self.appliEficas.multi==True :
167 self.appliEficas.definitCode(None,None)
168 if self.appliEficas.code == None:return
169 maPage=self.getEditor(include=include)
171 def newIncludeEditor(self):
172 self.newEditor(include=1)
174 def handleViewJdcFichierSource(self):
175 index=self.myQtab.currentIndex()
176 if index < 0 : return
177 self.dict_editors[index].viewJdcSource()
179 def handleViewJdcRegles(self):
180 index=self.myQtab.currentIndex()
181 if index < 0 : return
182 self.dict_editors[index].viewJdcRegles()
184 def handlegestionParam(self):
185 index=self.myQtab.currentIndex()
187 QMessageBox.warning( self.appliEficas,tr(u"Creation Parametre indisponible"),tr(u"les parametres sont lies a un jeu de donnees"))
189 self.dict_editors[index].gestionParam()
191 def handleViewJdcRapport(self):
192 index=self.myQtab.currentIndex()
193 if index < 0 : return
194 self.dict_editors[index].viewJdcRapport()
196 def handleViewJdcPy(self):
197 index=self.myQtab.currentIndex()
198 if index < 0 : return
199 self.dict_editors[index].viewJdcPy()
201 def saveCurrentEditor(self):
202 index=self.myQtab.currentIndex()
203 if index < 0 : return
204 editor=self.dict_editors[index]
205 if editor in self.doubles.keys() :
208 tr("Fichier Duplique"),
209 tr("Le fichier ne sera pas sauvegarde."),
212 ok, newName = editor.saveFile()
214 fileName=os.path.basename(unicode(newName))
215 self.myQtab.setTabText(index,fileName)
218 def sauveLigneCurrentEditor(self):
219 index=self.myQtab.currentIndex()
220 if index < 0 : return
221 editor=self.dict_editors[index]
222 if editor in self.doubles.keys() :
225 tr("Fichier Duplique"),
226 tr("Le fichier ne sera pas sauvegarde."),
229 ok, newName = editor.sauveLigneFile()
231 fileName=os.path.basename(unicode(newName))
232 self.myQtab.setTabText(index,fileName)
236 def saveAsCurrentEditor(self):
237 index=self.myQtab.currentIndex()
238 editor=self.dict_editors[index]
239 oldName=editor.fichier
240 ok,newName = editor.saveFileAs()
242 fileName=os.path.basename(unicode(newName))
243 self.myQtab.setTabText(index,fileName)
244 if editor in self.doubles.keys():
245 if oldName != newName :
246 del self.doubles[editor]
249 def displayJDC(self,jdc,fn=None):
251 Public slot to display a file in an editor.
252 @param fn name of file to be opened
253 # insert filename into list of recently opened files
256 if fn != None : titre=fn.split("/")[-1]
257 editor = self.getEditor(fichier= fn, jdc = jdc ,include=1)
258 self.appliEficas.addToRecentList(editor.getFileName())
260 def getEditor(self,fichier = None,jdc = None, units = None,include=0):
264 for indexEditor in self.dict_editors.keys():
265 editor=self.dict_editors[indexEditor]
266 if self.samepath(fichier, editor.getFileName()):
267 abort = QMessageBox.warning(self.appliEficas,
269 tr("Le fichier <b>%s</b> est deja ouvert.",str(fichier)),
275 from editor import JDCEditor
276 editor = JDCEditor(self.appliEficas,fichier, jdc, self.myQtab,units=units,vm = self,include=include)
278 self.doubles[editor]=double
279 if editor.jdc: # le fichier est bien un jdc
280 self.editors.append(editor)
286 self.addView(editor, fichier)
288 self.myQtab.setCurrentIndex(indexEditor)
290 index=self.myQtab.currentIndex()
292 self.dict_editors[index]=editor
295 def addView(self, win, fichier=None):
296 #PNPNPNPN --> a affiner
298 self.untitledCount += 1
299 self.myQtab.addTab(win, tr("Fichier non encore nomme ", self.untitledCount))
300 #self.myQtab.addTab(win, str(self.appliEficas.code))
302 liste=fichier.split('/')
304 if not QFileInfo(fichier).isWritable():
305 txt = '%s (ro)' % txt
306 self.myQtab.addTab(win,txt )
307 self.myQtab.setCurrentWidget(win)
308 self.currentEditor=win
311 def getOpenStartDir(self) :
312 #PN --> Les Preferences
314 userDir=os.path.expanduser("~/Eficas_install/")
319 def samepath(self,f1, f2):
323 if f1 is None or f2 is None: return 0
324 if os.path.normcase(os.path.normpath(f1)) == os.path.normcase(os.path.normpath(f2)) : return 1
328 def checkDirty(self, editor,texte):
330 Private method to check dirty status and open a message window.
332 @param editor editor window to check
333 @return flag indicating successful reset of the dirty flag (boolean)
336 if (editor.modified) and (editor in self.doubles.keys()) :
337 res = QMessageBox.warning(
339 tr("Fichier Duplique"),
340 tr("Le fichier ne sera pas sauvegarde."),
343 if res == 0 : return 1
346 fn = editor.getFileName()
348 fn = self.appliEficas.trUtf8('Noname')
349 res = QMessageBox.warning(self.appliEficas,
350 tr("Fichier Modifie"),
351 tr("Le fichier %s n a pas ete sauvegarde.",str(fn)),
356 (ok, newName) = editor.saveFile()
358 fileName=os.path.basename(unicode(newName))
359 index=self.myQtab.currentIndex()
360 self.myQtab.setTabText(index,fileName)
364 def handleAjoutGroup(self,listeGroup):
365 index=self.myQtab.currentIndex()
366 if index < 0 : return
367 editor=self.dict_editors[index]
368 editor.handleAjoutGroup(listeGroup)