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
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 (*)")
71 extensions=tr('Fichiers JDC (*.comm);;''Tous les Fichiers (*)')
73 fichier = QFileDialog.getOpenFileName(self.appliEficas,
75 self.appliEficas.CONFIGURATION.savedir,
78 fichier = os.path.abspath(six.text_type(fichier))
79 ulfile = os.path.abspath(six.text_type(fichier))
80 self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
81 self.appliEficas.addToRecentList(fichier)
82 maPage=self.getEditor( fichier,units=units)
83 if maPage: result = maPage
84 if maPage : self.myQtab.setTabText(self.myQtab.indexOf(maPage),os.path.basename(fichier))
90 def handleClose(self,doitSauverRecent = 1,texte=tr('&Quitter')):
91 if doitSauverRecent : self.appliEficas.sauveRecents()
92 index=self.myQtab.currentIndex()
94 res=self.checkDirty(self.dict_editors[index],texte)
95 if res == 2 : return 2 # l utilisateur a annule
96 index=self.myQtab.currentIndex()
98 while idx < len(self.dict_editors) -1 :
99 self.dict_editors[idx]=self.dict_editors[idx+1]
101 del self.dict_editors[len (self.dict_editors) -1]
103 del self.doubles[self.dict_editors[index]]
106 self.myQtab.removeTab(index)
111 index=self.myQtab.currentIndex()
112 if index < 0 : return
113 editor=self.dict_editors[index]
117 index=self.myQtab.currentIndex()
118 if index < 0 : return
119 editor=self.dict_editors[index]
122 def handleCloseAll(self,texte=tr('Quitter')):
124 self.appliEficas.sauveRecents()
125 while len(self.dict_editors) > 0 :
126 self.myQtab.setCurrentIndex(0)
127 res=self.handleClose(0,texte)
128 if res==2 : return res # l utilsateur a annule
131 def handleRechercher(self):
132 #print "passage dans handleRechercher"
133 index=self.myQtab.currentIndex()
134 if index < 0 : return
135 editor=self.dict_editors[index]
136 editor.handleRechercher()
138 def handleRechercherDsCatalogue(self):
139 #print "passage dans handleRechercher"
140 index=self.myQtab.currentIndex()
141 if index < 0 : return
142 editor=self.dict_editors[index]
143 editor.handleRechercherDsCatalogue()
145 def handleDeplier(self):
146 index=self.myQtab.currentIndex()
147 if index < 0 : return
148 editor=self.dict_editors[index]
149 editor.handleDeplier()
151 def handleEditCopy(self):
152 #print "passage dans handleEditCopy"
153 index=self.myQtab.currentIndex()
154 if index < 0 : return
155 editor=self.dict_editors[index]
156 editor.handleEditCopy()
158 def handleEditCut(self):
159 #print "passage dans handleEditCut"
160 index=self.myQtab.currentIndex()
161 if index < 0 : return
162 editor=self.dict_editors[index]
163 editor.handleEditCut()
165 def handleEditPaste(self):
166 #print "passage dans handleEditPaste"
167 index=self.myQtab.currentIndex()
168 if index < 0 : return
169 editor=self.dict_editors[index]
170 editor.handleEditPaste()
172 def handleSupprimer(self):
173 index=self.myQtab.currentIndex()
174 if index < 0 : return
175 editor=self.dict_editors[index]
176 editor.handleSupprimer()
178 def newEditor(self,include=0):
179 if self.appliEficas.demande==True :
180 self.appliEficas.definitCode(None,None)
181 if self.appliEficas.code == None:return
182 maPage=self.getEditor(include=include)
184 def newIncludeEditor(self):
185 self.newEditor(include=1)
187 def handleViewJdcFichierSource(self):
188 index=self.myQtab.currentIndex()
189 if index < 0 : return
190 self.dict_editors[index].viewJdcSource()
192 def ouvreArbre(self):
193 index=self.myQtab.currentIndex()
194 if index < 0 : return
195 self.dict_editors[index].ouvreArbre()
197 def fermeArbre(self):
198 index=self.myQtab.currentIndex()
199 if index < 0 : return
200 self.dict_editors[index].fermeArbre()
202 def ajoutCommentaire(self):
203 index=self.myQtab.currentIndex()
204 if index < 0 : return
205 editor=self.dict_editors[index]
206 editor.ajoutCommentaire()
208 def handleViewJdcRegles(self):
209 index=self.myQtab.currentIndex()
210 if index < 0 : return
211 self.dict_editors[index].viewJdcRegles()
213 def handlegestionParam(self):
214 index=self.myQtab.currentIndex()
216 QMessageBox.warning( self.appliEficas,tr(u"Creation Parametre indisponible"),tr(u"les parametres sont lies a un jeu de donnees"))
218 self.dict_editors[index].gestionParam()
220 def handleViewJdcRapport(self):
221 index=self.myQtab.currentIndex()
222 if index < 0 : return
223 self.dict_editors[index].viewJdcRapport()
225 def handleViewJdcPy(self):
226 index=self.myQtab.currentIndex()
227 if index < 0 : return
228 self.dict_editors[index].viewJdcPy()
230 def saveCurrentEditor(self):
231 index=self.myQtab.currentIndex()
232 if index < 0 : return
233 editor=self.dict_editors[index]
234 if editor in self.doubles :
237 tr("Fichier Duplique"),
238 tr("Le fichier ne sera pas sauvegarde."),)
240 ok, newName = editor.saveFile()
242 fileName=os.path.basename(six.text_type(newName))
243 self.myQtab.setTabText(index,fileName)
246 def saveLegerCurrentEditor(self):
247 index=self.myQtab.currentIndex()
248 if index < 0 : return
249 editor=self.dict_editors[index]
250 ok, newName = editor.saveFileLeger()
253 def sauveLigneCurrentEditor(self):
254 index=self.myQtab.currentIndex()
255 if index < 0 : return
256 editor=self.dict_editors[index]
257 if editor in self.doubles :
260 tr("Fichier Duplique"),
261 tr("Le fichier ne sera pas sauvegarde."),)
263 ok, newName = editor.sauveLigneFile()
265 fileName=os.path.basename(six.text_type(newName))
266 self.myQtab.setTabText(index,fileName)
270 def saveAsCurrentEditor(self):
271 index=self.myQtab.currentIndex()
272 editor=self.dict_editors[index]
273 oldName=editor.fichier
274 ok,newName = editor.saveFileAs()
276 fileName=os.path.basename(six.text_type(newName))
277 self.myQtab.setTabText(index,fileName)
278 if editor in self.doubles :
279 if oldName != newName :
280 del self.doubles[editor]
283 def displayJDC(self,jdc,fn=None):
285 Public slot to display a file in an editor.
286 @param fn name of file to be opened
287 # insert filename into list of recently opened files
290 if fn != None : titre=fn.split("/")[-1]
291 editor = self.getEditor(fichier= fn, jdc = jdc ,include=1)
292 self.appliEficas.addToRecentList(editor.getFileName())
294 def getEditor(self,fichier = None,jdc = None, units = None,include=0):
298 for indexEditor in self.dict_editors :
299 editor=self.dict_editors[indexEditor]
300 if self.samepath(fichier, editor.getFileName()):
301 msgBox = QMessageBox()
302 msgBox.setWindowTitle(tr("Fichier"))
303 msgBox.setText(tr("Le fichier <b>%s</b> est deja ouvert", str(fichier)))
304 msgBox.addButton(tr("&Duplication"),0)
305 msgBox.addButton(tr("&Abandonner"),1)
310 from .editor import JDCEditor
311 editor = JDCEditor(self.appliEficas,fichier, jdc, self.myQtab,units=units,vm = self,include=include)
314 self.doubles[editor]=double
315 if editor.jdc: # le fichier est bien un jdc
316 self.editors.append(editor)
322 self.addView(editor, fichier)
324 self.myQtab.setCurrentIndex(indexEditor)
326 index=self.myQtab.currentIndex()
328 self.dict_editors[index]=editor
331 def addView(self, win, fichier=None):
332 #PNPNPNPN --> a affiner
334 self.untitledCount += 1
335 self.myQtab.addTab(win, tr("Fichier non encore nomme ", self.untitledCount))
336 #self.myQtab.addTab(win, str(self.appliEficas.code))
338 liste=fichier.split('/')
340 if not QFileInfo(fichier).isWritable():
341 txt = '%s (ro)' % txt
342 self.myQtab.addTab(win,txt )
343 self.myQtab.setCurrentWidget(win)
344 self.currentEditor=win
347 def getOpenStartDir(self) :
348 #PN --> Les Preferences
350 userDir=os.path.expanduser("~/Eficas_install/")
355 def samepath(self,f1, f2):
359 if f1 is None or f2 is None: return 0
360 if os.path.normcase(os.path.normpath(f1)) == os.path.normcase(os.path.normpath(f2)) : return 1
364 def checkDirty(self, editor,texte):
366 Private method to check dirty status and open a message window.
368 @param editor editor window to check
369 @return flag indicating successful reset of the dirty flag (boolean)
372 if (editor.modified) and (editor in self.doubles) :
373 msgBox = QMessageBox(None)
374 msgBox.setWindowTitle(tr("Fichier Duplique"))
375 msgBox.setText(tr("Le fichier ne sera pas sauvegarde."))
376 msgBox.addButton(texte,0)
377 msgBox.addButton(tr("&Annuler"),1)
379 if res == 0 : return 1
382 fn = editor.getFileName()
383 if fn is None: fn = tr('Noname')
384 msgBox = QMessageBox(None)
385 msgBox.setWindowTitle(tr("Fichier Modifie"))
386 msgBox.setText(tr("Le fichier ne sera pas sauvegarde."))
387 msgBox.addButton(tr("&Sauvegarder"),1)
388 msgBox.addButton(tr("&Quitter sans sauvegarder"),0)
390 if res == 2 : res = 1
392 (ok, newName) = editor.saveFile()
394 fileName=os.path.basename(six.text_type(newName))
395 index=self.myQtab.currentIndex()
396 self.myQtab.setTabText(index,fileName)
400 def handleAjoutGroup(self,listeGroup):
401 index=self.myQtab.currentIndex()
402 if index < 0 : return
403 editor=self.dict_editors[index]
404 editor.handleAjoutGroup(listeGroup)