1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017 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
21 from __future__ import absolute_import
23 from builtins import str
24 from builtins import object
28 from Extensions.i18n import tr
30 from PyQt5.QtWidgets import QFileDialog, QMessageBox
31 from PyQt5.QtCore import QFileInfo
33 DictExtensions= {"MAP" : ".map"}
34 class MyTabview(object):
36 def __init__(self,appliEficas):
37 self.appliEficas=appliEficas
40 self.appliEficas=appliEficas
43 self.untitledCount = 0
46 self.myQtab = self.appliEficas.myQtab
48 self.myQtab.currentChanged.connect(self.indexChanged)
49 self.myQtab.tabCloseRequested.connect(self.closeTab)
51 def indexChanged(self):
52 index=self.myQtab.currentIndex()
53 if index in self.dict_editors:
54 editor=self.dict_editors[index]
55 self.appliEficas.CONFIGURATION=editor.CONFIGURATION
56 self.appliEficas.code=editor.CONFIGURATION.code
57 self.appliEficas.setWindowTitle(editor.titre)
58 self.appliEficas.construitMenu()
60 def handleOpen(self,fichier=None,patron=0,units=None):
63 if self.appliEficas.demande==True :
64 self.appliEficas.definitCode(None,None)
65 if self.appliEficas.code == None:return
67 if self.appliEficas.code in DictExtensions:
68 chaine="JDC (*"+DictExtensions[self.appliEficas.code]+");;"
69 extensions=tr(chaine+ "All Files (*)")
70 elif self.appliEficas.code== "TELEMAC" : extensions=tr('CAS (*.cas);;All Files (*)')
72 extensions=tr('Fichiers JDC (*.comm);;''Tous les Fichiers (*)')
74 fichier = QFileDialog.getOpenFileName(self.appliEficas,
76 self.appliEficas.CONFIGURATION.savedir,
79 fichier = os.path.abspath(six.text_type(fichier))
80 ulfile = os.path.abspath(six.text_type(fichier))
81 self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
82 self.appliEficas.addToRecentList(fichier)
83 maPage=self.getEditor( fichier,units=units)
84 if maPage: result = maPage
85 if maPage : self.myQtab.setTabText(self.myQtab.indexOf(maPage),os.path.basename(fichier))
91 def handleClose(self,doitSauverRecent = 1,texte=tr('&Quitter')):
92 if doitSauverRecent : self.appliEficas.sauveRecents()
93 index=self.myQtab.currentIndex()
95 res=self.checkDirty(self.dict_editors[index],texte)
96 if res == 2 : return 2 # l utilisateur a annule
97 index=self.myQtab.currentIndex()
99 while idx < len(self.dict_editors) -1 :
100 self.dict_editors[idx]=self.dict_editors[idx+1]
102 del self.dict_editors[len (self.dict_editors) -1]
104 del self.doubles[self.dict_editors[index]]
107 self.myQtab.removeTab(index)
112 index=self.myQtab.currentIndex()
113 if index < 0 : return
114 editor=self.dict_editors[index]
118 index=self.myQtab.currentIndex()
119 if index < 0 : return
120 editor=self.dict_editors[index]
123 def handleCloseAll(self,texte=tr('Quitter')):
125 self.appliEficas.sauveRecents()
126 while len(self.dict_editors) > 0 :
127 self.myQtab.setCurrentIndex(0)
128 res=self.handleClose(0,texte)
129 if res==2 : return res # l utilsateur a annule
132 def handleRechercher(self):
133 #print "passage dans handleRechercher"
134 index=self.myQtab.currentIndex()
135 if index < 0 : return
136 editor=self.dict_editors[index]
137 editor.handleRechercher()
139 def handleRechercherDsCatalogue(self):
140 #print "passage dans handleRechercher"
141 index=self.myQtab.currentIndex()
142 if index < 0 : return
143 editor=self.dict_editors[index]
144 editor.handleRechercherDsCatalogue()
146 def handleDeplier(self):
147 index=self.myQtab.currentIndex()
148 if index < 0 : return
149 editor=self.dict_editors[index]
150 editor.handleDeplier()
152 def handleEditCopy(self):
153 #print "passage dans handleEditCopy"
154 index=self.myQtab.currentIndex()
155 if index < 0 : return
156 editor=self.dict_editors[index]
157 editor.handleEditCopy()
159 def handleEditCut(self):
160 #print "passage dans handleEditCut"
161 index=self.myQtab.currentIndex()
162 if index < 0 : return
163 editor=self.dict_editors[index]
164 editor.handleEditCut()
166 def handleEditPaste(self):
167 #print "passage dans handleEditPaste"
168 index=self.myQtab.currentIndex()
169 if index < 0 : return
170 editor=self.dict_editors[index]
171 editor.handleEditPaste()
173 def handleSupprimer(self):
174 index=self.myQtab.currentIndex()
175 if index < 0 : return
176 editor=self.dict_editors[index]
177 editor.handleSupprimer()
179 def newEditor(self,include=0):
180 if self.appliEficas.demande==True :
181 self.appliEficas.definitCode(None,None)
182 if self.appliEficas.code == None:return
183 maPage=self.getEditor(include=include)
185 def newIncludeEditor(self):
186 self.newEditor(include=1)
188 def handleViewJdcFichierSource(self):
189 index=self.myQtab.currentIndex()
190 if index < 0 : return
191 self.dict_editors[index].viewJdcSource()
193 def ouvreArbre(self):
194 index=self.myQtab.currentIndex()
195 if index < 0 : return
196 self.dict_editors[index].ouvreArbre()
198 def fermeArbre(self):
199 index=self.myQtab.currentIndex()
200 if index < 0 : return
201 self.dict_editors[index].fermeArbre()
203 def ajoutCommentaire(self):
204 index=self.myQtab.currentIndex()
205 if index < 0 : return
206 editor=self.dict_editors[index]
207 editor.ajoutCommentaire()
209 def handleViewJdcRegles(self):
210 index=self.myQtab.currentIndex()
211 if index < 0 : return
212 self.dict_editors[index].viewJdcRegles()
214 def handlegestionParam(self):
215 index=self.myQtab.currentIndex()
217 QMessageBox.warning( self.appliEficas,tr(u"Creation Parametre indisponible"),tr(u"les parametres sont lies a un jeu de donnees"))
219 self.dict_editors[index].gestionParam()
221 def handleViewJdcRapport(self):
222 index=self.myQtab.currentIndex()
223 if index < 0 : return
224 self.dict_editors[index].viewJdcRapport()
226 def handleViewJdcPy(self):
227 index=self.myQtab.currentIndex()
228 if index < 0 : return
229 self.dict_editors[index].viewJdcPy()
231 def saveCurrentEditor(self):
232 index=self.myQtab.currentIndex()
233 if index < 0 : return
234 editor=self.dict_editors[index]
235 if editor in self.doubles :
238 tr("Fichier Duplique"),
239 tr("Le fichier ne sera pas sauvegarde."),)
241 ok, newName = editor.saveFile()
243 fileName=os.path.basename(six.text_type(newName))
244 self.myQtab.setTabText(index,fileName)
247 def saveLegerCurrentEditor(self):
248 index=self.myQtab.currentIndex()
249 if index < 0 : return
250 editor=self.dict_editors[index]
251 ok, newName = editor.saveFileLeger()
254 def sauveLigneCurrentEditor(self):
255 index=self.myQtab.currentIndex()
256 if index < 0 : return
257 editor=self.dict_editors[index]
258 if editor in self.doubles :
261 tr("Fichier Duplique"),
262 tr("Le fichier ne sera pas sauvegarde."),)
264 ok, newName = editor.sauveLigneFile()
266 fileName=os.path.basename(six.text_type(newName))
267 self.myQtab.setTabText(index,fileName)
271 def saveAsCurrentEditor(self):
272 index=self.myQtab.currentIndex()
273 editor=self.dict_editors[index]
274 oldName=editor.fichier
275 ok,newName = editor.saveFileAs()
277 fileName=os.path.basename(six.text_type(newName))
278 self.myQtab.setTabText(index,fileName)
279 if editor in self.doubles :
280 if oldName != newName :
281 del self.doubles[editor]
284 def displayJDC(self,jdc,fn=None):
286 Public slot to display a file in an editor.
287 @param fn name of file to be opened
288 # insert filename into list of recently opened files
291 if fn != None : titre=fn.split("/")[-1]
292 editor = self.getEditor(fichier= fn, jdc = jdc ,include=1)
293 self.appliEficas.addToRecentList(editor.getFileName())
295 def getEditor(self,fichier = None,jdc = None, units = None,include=0):
299 for indexEditor in self.dict_editors :
300 editor=self.dict_editors[indexEditor]
301 if self.samepath(fichier, editor.getFileName()):
302 msgBox = QMessageBox()
303 msgBox.setWindowTitle(tr("Fichier"))
304 msgBox.setText(tr("Le fichier <b>%s</b> est deja ouvert", str(fichier)))
305 msgBox.addButton(tr("&Duplication"),0)
306 msgBox.addButton(tr("&Abandonner"),1)
311 from .editor import JDCEditor
312 editor = JDCEditor(self.appliEficas,fichier, jdc, self.myQtab,units=units,vm = self,include=include)
315 self.doubles[editor]=double
316 if editor.jdc: # le fichier est bien un jdc
317 self.editors.append(editor)
323 self.addView(editor, fichier)
325 self.myQtab.setCurrentIndex(indexEditor)
327 index=self.myQtab.currentIndex()
329 self.dict_editors[index]=editor
332 def addView(self, win, fichier=None):
333 #PNPNPNPN --> a affiner
335 self.untitledCount += 1
336 self.myQtab.addTab(win, tr("Fichier non encore nomme ", self.untitledCount))
337 #self.myQtab.addTab(win, str(self.appliEficas.code))
339 liste=fichier.split('/')
341 if not QFileInfo(fichier).isWritable():
342 txt = '%s (ro)' % txt
343 self.myQtab.addTab(win,txt )
344 self.myQtab.setCurrentWidget(win)
345 self.currentEditor=win
348 def getOpenStartDir(self) :
349 #PN --> Les Preferences
351 userDir=os.path.expanduser("~/Eficas_install/")
356 def samepath(self,f1, f2):
360 if f1 is None or f2 is None: return 0
361 if os.path.normcase(os.path.normpath(f1)) == os.path.normcase(os.path.normpath(f2)) : return 1
365 def checkDirty(self, editor,texte):
367 Private method to check dirty status and open a message window.
369 @param editor editor window to check
370 @return flag indicating successful reset of the dirty flag (boolean)
373 if (editor.modified) and (editor in self.doubles) :
374 msgBox = QMessageBox(None)
375 msgBox.setWindowTitle(tr("Fichier Duplique"))
376 msgBox.setText(tr("Le fichier ne sera pas sauvegarde."))
377 msgBox.addButton(texte,0)
378 msgBox.addButton(tr("&Annuler"),1)
380 if res == 0 : return 1
383 fn = editor.getFileName()
384 if fn is None: fn = tr('Noname')
385 msgBox = QMessageBox(None)
386 msgBox.setWindowTitle(tr("Fichier Modifie"))
387 msgBox.setText(tr("Le fichier ne sera pas sauvegarde."))
388 msgBox.addButton(tr("&Sauvegarder"),1)
389 msgBox.addButton(tr("&Quitter sans sauvegarder"),0)
390 msgBox.addButton(tr("&Annuler"),2)
392 if res == 2 : return res
394 (ok, newName) = editor.saveFile()
396 fileName=os.path.basename(six.text_type(newName))
397 index=self.myQtab.currentIndex()
398 self.myQtab.setTabText(index,fileName)
402 def handleAjoutGroup(self,listeGroup):
403 index=self.myQtab.currentIndex()
404 if index < 0 : return
405 editor=self.dict_editors[index]
406 editor.handleAjoutGroup(listeGroup)