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 Extensions.i18n import tr
23 from determine import monEnvQT5
25 from PyQt5.QtWidgets import QFileDialog
26 from PyQt5.QtCore import QFileInfo
28 from PyQt4.QtGui import *
29 from PyQt4.QtCore import *
31 DictExtensions= {"MAP" : ".map"}
34 def __init__(self,appliEficas):
35 self.appliEficas=appliEficas
38 self.appliEficas=appliEficas
41 self.untitledCount = 0
44 self.myQtab = self.appliEficas.myQtab
47 self.myQtab.currentChanged.connect(self.indexChanged)
48 self.myQtab.tabCloseRequested.connect(self.closeTab)
50 self.myQtab.connect(self.myQtab, SIGNAL('tabCloseRequested(int)'), self.closeTab)
51 if self.appliEficas.multi== True:
52 self.myQtab.connect(self.myQtab,SIGNAL("currentChanged(int)"),self.indexChanged)
54 def indexChanged(self):
55 index=self.myQtab.currentIndex()
56 if self.dict_editors.has_key(index):
57 editor=self.dict_editors[index]
58 self.appliEficas.CONFIGURATION=editor.CONFIGURATION
59 self.appliEficas.code=editor.CONFIGURATION.code
60 self.appliEficas.setWindowTitle(editor.titre)
61 self.appliEficas.construitMenu()
63 def handleOpen(self,fichier=None,patron=0,units=None):
66 if self.appliEficas.multi==True :
67 self.appliEficas.definitCode(None,None)
68 if self.appliEficas.code == None:return
70 if DictExtensions.has_key(self.appliEficas.code) :
71 chaine="JDC (*"+DictExtensions[self.appliEficas.code]+");;"
72 extensions=tr(chaine+ "All Files (*)")
74 extensions=tr('Fichiers JDC (*.comm);;''Tous les Fichiers (*)')
76 fichier = QFileDialog.getOpenFileName(self.appliEficas,
78 self.appliEficas.CONFIGURATION.savedir,
82 fichier = os.path.abspath(unicode(fichier))
83 ulfile = os.path.abspath(unicode(fichier))
84 self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
85 self.appliEficas.addToRecentList(fichier)
86 maPage=self.getEditor( fichier,units=units)
87 if maPage: result = maPage
88 if maPage : self.myQtab.setTabText(self.myQtab.indexOf(maPage),os.path.basename(fichier))
94 def handleClose(self,doitSauverRecent = 1,texte=tr('&Quitter')):
95 if doitSauverRecent : self.appliEficas.sauveRecents()
96 index=self.myQtab.currentIndex()
98 res=self.checkDirty(self.dict_editors[index],texte)
99 if res == 2 : return 2 # l utilisateur a annule
100 index=self.myQtab.currentIndex()
102 while idx < len(self.dict_editors) -1 :
103 self.dict_editors[idx]=self.dict_editors[idx+1]
105 del self.dict_editors[len (self.dict_editors) -1]
107 del self.doubles[self.dict_editors[index]]
110 self.myQtab.removeTab(index)
115 index=self.myQtab.currentIndex()
116 if index < 0 : return
117 editor=self.dict_editors[index]
121 index=self.myQtab.currentIndex()
122 if index < 0 : return
123 editor=self.dict_editors[index]
126 def handleCloseAll(self,texte=tr('Quitter')):
128 self.appliEficas.sauveRecents()
129 while len(self.dict_editors) > 0 :
130 self.myQtab.setCurrentIndex(0)
131 res=self.handleClose(0,texte)
132 if res==2 : return res # l utilsateur a annule
135 def handleRechercher(self):
136 #print "passage dans handleRechercher"
137 index=self.myQtab.currentIndex()
138 if index < 0 : return
139 editor=self.dict_editors[index]
140 editor.handleRechercher()
142 def handleDeplier(self):
143 index=self.myQtab.currentIndex()
144 if index < 0 : return
145 editor=self.dict_editors[index]
146 editor.handleDeplier()
148 def handleEditCopy(self):
149 #print "passage dans handleEditCopy"
150 index=self.myQtab.currentIndex()
151 if index < 0 : return
152 editor=self.dict_editors[index]
153 editor.handleEditCopy()
155 def handleEditCut(self):
156 #print "passage dans handleEditCut"
157 index=self.myQtab.currentIndex()
158 if index < 0 : return
159 editor=self.dict_editors[index]
160 editor.handleEditCut()
162 def handleEditPaste(self):
163 #print "passage dans handleEditPaste"
164 index=self.myQtab.currentIndex()
165 if index < 0 : return
166 editor=self.dict_editors[index]
167 editor.handleEditPaste()
169 def handleSupprimer(self):
170 index=self.myQtab.currentIndex()
171 if index < 0 : return
172 editor=self.dict_editors[index]
173 editor.handleSupprimer()
175 def newEditor(self,include=0):
176 if self.appliEficas.multi==True :
177 self.appliEficas.definitCode(None,None)
178 if self.appliEficas.code == None:return
179 maPage=self.getEditor(include=include)
181 def newIncludeEditor(self):
182 self.newEditor(include=1)
184 def handleViewJdcFichierSource(self):
185 index=self.myQtab.currentIndex()
186 if index < 0 : return
187 self.dict_editors[index].viewJdcSource()
189 def handleViewJdcRegles(self):
190 index=self.myQtab.currentIndex()
191 if index < 0 : return
192 self.dict_editors[index].viewJdcRegles()
194 def handlegestionParam(self):
195 index=self.myQtab.currentIndex()
197 QMessageBox.warning( self.appliEficas,tr(u"Creation Parametre indisponible"),tr(u"les parametres sont lies a un jeu de donnees"))
199 self.dict_editors[index].gestionParam()
201 def handleViewJdcRapport(self):
202 index=self.myQtab.currentIndex()
203 if index < 0 : return
204 self.dict_editors[index].viewJdcRapport()
206 def handleViewJdcPy(self):
207 index=self.myQtab.currentIndex()
208 if index < 0 : return
209 self.dict_editors[index].viewJdcPy()
211 def saveCurrentEditor(self):
212 index=self.myQtab.currentIndex()
213 if index < 0 : return
214 editor=self.dict_editors[index]
215 if editor in self.doubles.keys() :
218 tr("Fichier Duplique"),
219 tr("Le fichier ne sera pas sauvegarde."),
222 ok, newName = editor.saveFile()
224 fileName=os.path.basename(unicode(newName))
225 self.myQtab.setTabText(index,fileName)
228 def sauveLigneCurrentEditor(self):
229 index=self.myQtab.currentIndex()
230 if index < 0 : return
231 editor=self.dict_editors[index]
232 if editor in self.doubles.keys() :
235 tr("Fichier Duplique"),
236 tr("Le fichier ne sera pas sauvegarde."),
239 ok, newName = editor.sauveLigneFile()
241 fileName=os.path.basename(unicode(newName))
242 self.myQtab.setTabText(index,fileName)
246 def saveAsCurrentEditor(self):
247 index=self.myQtab.currentIndex()
248 editor=self.dict_editors[index]
249 oldName=editor.fichier
250 ok,newName = editor.saveFileAs()
252 fileName=os.path.basename(unicode(newName))
253 self.myQtab.setTabText(index,fileName)
254 if editor in self.doubles.keys():
255 if oldName != newName :
256 del self.doubles[editor]
259 def displayJDC(self,jdc,fn=None):
261 Public slot to display a file in an editor.
262 @param fn name of file to be opened
263 # insert filename into list of recently opened files
266 if fn != None : titre=fn.split("/")[-1]
267 editor = self.getEditor(fichier= fn, jdc = jdc ,include=1)
268 self.appliEficas.addToRecentList(editor.getFileName())
270 def getEditor(self,fichier = None,jdc = None, units = None,include=0):
274 for indexEditor in self.dict_editors.keys():
275 editor=self.dict_editors[indexEditor]
276 if self.samepath(fichier, editor.getFileName()):
277 abort = QMessageBox.warning(self.appliEficas,
279 tr("Le fichier <b>%s</b> est deja ouvert.",str(fichier)),
285 from editor import JDCEditor
286 editor = JDCEditor(self.appliEficas,fichier, jdc, self.myQtab,units=units,vm = self,include=include)
288 self.doubles[editor]=double
289 if editor.jdc: # le fichier est bien un jdc
290 self.editors.append(editor)
296 self.addView(editor, fichier)
298 self.myQtab.setCurrentIndex(indexEditor)
300 index=self.myQtab.currentIndex()
302 self.dict_editors[index]=editor
305 def addView(self, win, fichier=None):
306 #PNPNPNPN --> a affiner
308 self.untitledCount += 1
309 self.myQtab.addTab(win, tr("Fichier non encore nomme ", self.untitledCount))
310 #self.myQtab.addTab(win, str(self.appliEficas.code))
312 liste=fichier.split('/')
314 if not QFileInfo(fichier).isWritable():
315 txt = '%s (ro)' % txt
316 self.myQtab.addTab(win,txt )
317 self.myQtab.setCurrentWidget(win)
318 self.currentEditor=win
321 def getOpenStartDir(self) :
322 #PN --> Les Preferences
324 userDir=os.path.expanduser("~/Eficas_install/")
329 def samepath(self,f1, f2):
333 if f1 is None or f2 is None: return 0
334 if os.path.normcase(os.path.normpath(f1)) == os.path.normcase(os.path.normpath(f2)) : return 1
338 def checkDirty(self, editor,texte):
340 Private method to check dirty status and open a message window.
342 @param editor editor window to check
343 @return flag indicating successful reset of the dirty flag (boolean)
346 if (editor.modified) and (editor in self.doubles.keys()) :
347 res = QMessageBox.warning(
349 tr("Fichier Duplique"),
350 tr("Le fichier ne sera pas sauvegarde."),
353 if res == 0 : return 1
356 fn = editor.getFileName()
358 fn = self.appliEficas.trUtf8('Noname')
359 res = QMessageBox.warning(self.appliEficas,
360 tr("Fichier Modifie"),
361 tr("Le fichier %s n a pas ete sauvegarde.",str(fn)),
366 (ok, newName) = editor.saveFile()
368 fileName=os.path.basename(unicode(newName))
369 index=self.myQtab.currentIndex()
370 self.myQtab.setTabText(index,fileName)
374 def handleAjoutGroup(self,listeGroup):
375 index=self.myQtab.currentIndex()
376 if index < 0 : return
377 editor=self.dict_editors[index]
378 editor.handleAjoutGroup(listeGroup)