]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/viewManager.py
Salome HOME
*** empty log message ***
[tools/eficas.git] / InterfaceQT4 / viewManager.py
1 # -*- coding: utf-8 -*-
2 #            CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002  EDF R&D                  WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
9 #
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
14 #
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 #    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
18 #
19 #
20 # ======================================================================
21
22 import os, string
23 from PyQt4.QtGui  import *
24 from PyQt4.QtCore import *
25
26 class MyTabview:
27
28    def __init__(self,appliEficas):
29        self.appliEficas=appliEficas
30        self.tabWidgets = []
31        self.mesIndexes = {}
32        self.appliEficas=appliEficas
33        self.editors = []
34        self.dict_editors={}
35        self.untitledCount = 0
36        self.doubles = {}
37
38        self.gridLayout = QGridLayout(self.appliEficas.centralWidget())
39        self.myQtab = QTabWidget(self.appliEficas.centralWidget())
40        self.gridLayout.addWidget(self.myQtab)
41         
42
43    def handleOpen(self,fichier=None,patron=0,units=None):
44        if fichier is None:
45             fichier = QFileDialog.getOpenFileName(self.appliEficas,
46                         self.appliEficas.trUtf8('Ouvrir Fichier'),
47                         self.appliEficas.CONFIGURATION.savedir,
48                         self.appliEficas.trUtf8('JDC Files (*.comm);;''All Files (*)'))
49             if fichier.isNull(): return
50        fichier = os.path.abspath(unicode(fichier))
51        ulfile = os.path.abspath(unicode(fichier))
52        self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
53        self.appliEficas.addToRecentList(fichier)
54        maPage=self.getEditor( fichier,units=units)
55
56    def handleClose(self,doitSauverRecent = 1):
57        if doitSauverRecent : self.appliEficas.sauveRecents()
58        index=self.myQtab.currentIndex()
59        if index < 0 : return
60        res=self.checkDirty(self.dict_editors[index])
61        if res == 2 : return 2             # l utilisateur a annule
62        index=self.myQtab.currentIndex()
63        idx=index
64        while idx < len(self.dict_editors) -1 :
65              self.dict_editors[idx]=self.dict_editors[idx+1]
66              idx = idx + 1
67        del self.dict_editors[len (self.dict_editors) -1]
68        try :
69            del self.doubles[self.dict_editors[index]]
70        except :
71            pass
72        self.myQtab.removeTab(index)
73        return res
74        
75
76    def run(self):
77        index=self.myQtab.currentIndex()
78        if index < 0 : return
79        editor=self.dict_editors[index]
80        editor.run()
81
82    def saveRun(self):
83        index=self.myQtab.currentIndex()
84        if index < 0 : return
85        editor=self.dict_editors[index]
86        editor.saveRun()
87
88    def runYACS(self):
89        index=self.myQtab.currentIndex()
90        if index < 0 : return
91        editor=self.dict_editors[index]
92        editor.runYACS()
93
94    def saveYACS(self):
95        index=self.myQtab.currentIndex()
96        if index < 0 : return
97        editor=self.dict_editors[index]
98        editor.saveYACS()
99
100    def handleCloseAll(self):
101        res=0
102        self.appliEficas.sauveRecents()
103        while len(self.dict_editors) > 0 :
104              self.myQtab.setCurrentIndex(0)
105              res=self.handleClose(0)
106              if res==2 : return res   # l utilsateur a annule
107        return res
108         
109    def handleEditCopy(self):
110        #print "passage dans handleEditCopy"
111        index=self.myQtab.currentIndex()
112        editor=self.dict_editors[index]
113        editor.handleEditCopy()
114
115    def handleEditCut(self):
116        #print "passage dans handleEditCut"
117        index=self.myQtab.currentIndex()
118        editor=self.dict_editors[index]
119        editor.handleEditCut()
120
121    def handleEditPaste(self):
122        #print "passage dans handleEditPaste"
123        index=self.myQtab.currentIndex()
124        editor=self.dict_editors[index]
125        editor.handleEditPaste()
126
127    def handleSupprimer(self):
128        index=self.myQtab.currentIndex()
129        editor=self.dict_editors[index]
130        editor.handleSupprimer()
131
132    def newEditor(self,include=0):
133        maPage=self.getEditor(include=include)
134
135    def newIncludeEditor(self):
136        self.newEditor(include=1)
137
138    def handleViewJdcFichierSource(self):
139        index=self.myQtab.currentIndex()
140        if index < 0 : return
141        self.dict_editors[index].viewJdcSource()
142
143    def handleViewJdcRapport(self):
144        index=self.myQtab.currentIndex()
145        if index < 0 : return
146        self.dict_editors[index].viewJdcRapport()
147
148    def handleViewJdcPy(self):
149        index=self.myQtab.currentIndex()
150        if index < 0 : return
151        self.dict_editors[index].viewJdcPy()
152
153    def saveCurrentEditor(self):
154        index=self.myQtab.currentIndex()
155        if index < 0 : return
156        print self
157        print index
158        print self.dict_editors
159        editor=self.dict_editors[index]
160        if editor in self.doubles.keys() :
161            QMessageBox.warning(
162                      None,
163                      self.appliEficas.trUtf8("Fichier Duplique"),
164                      self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."),
165                      self.appliEficas.trUtf8("&Annuler"))
166            return
167        ok, newName = editor.saveFile()
168        if ok :
169            fileName=os.path.basename(unicode(newName))
170            self.myQtab.setTabText(index,fileName)
171
172    def saveAsCurrentEditor(self):
173        index=self.myQtab.currentIndex()
174        editor=self.dict_editors[index]
175        oldName=editor.fichier
176        ok,newName = editor.saveFileAs()
177        if ok :
178            fileName=os.path.basename(unicode(newName))
179            self.myQtab.setTabText(index,fileName)
180        if editor in self.doubles.keys():
181           if oldName != newName :
182              del self.doubles[editor]
183
184
185    def displayJDC(self,jdc,fn=None):
186         """
187         Public slot to display a file in an editor.
188         @param fn name of file to be opened
189         # insert filename into list of recently opened files
190         """
191         titre=None
192         if fn != None : titre=fn.split("/")[-1]
193         editor = self.getEditor(fichier= fn, jdc = jdc ,include=1)
194         self.appliEficas.addToRecentList(editor.getFileName())
195
196    def getEditor(self,fichier = None,jdc = None, units = None,include=0):
197        newWin = 0
198        double = None
199        indexEditor=0
200        for indexEditor in self.dict_editors.keys():
201            editor=self.dict_editors[indexEditor]
202            if self.samepath(fichier, editor.getFileName()):
203               abort = QMessageBox.warning(self.appliEficas,
204                         self.appliEficas.trUtf8("Fichier"),
205                         self.appliEficas.trUtf8("Le fichier <b>%1</b> est deja ouvert.").arg(fichier),
206                         self.appliEficas.trUtf8("&Duplication"),
207                         self.appliEficas.trUtf8("&Abort"))
208               if abort: break
209               double=editor
210        else :
211             from editor import JDCEditor
212             editor = JDCEditor(self.appliEficas,fichier, jdc, self.myQtab,units=units,vm = self,include=include)
213             if double != None : 
214                self.doubles[editor]=double
215             if editor.jdc: # le fichier est bien un jdc
216                 self.editors.append(editor)
217                 newWin = 1
218             else:
219                 editor.closeIt()
220
221        if newWin:
222             self.addView(editor, fichier)
223        elif editor.jdc:
224             self.myQtab.setCurrentIndex(indexEditor)
225
226        index=self.myQtab.currentIndex()
227        if index != -1 :
228           self.dict_editors[index]=editor
229        return editor
230
231    def addView(self, win, fichier=None):
232         if fichier is None:
233             self.untitledCount += 1
234             self.myQtab.addTab(win, self.appliEficas.trUtf8("Untitled %1").arg(self.untitledCount))
235         else:
236             liste=fichier.split('/')
237             txt =  liste[-1]
238             if not QFileInfo(fichier).isWritable():
239                 txt = '%s (ro)' % txt
240             self.myQtab.addTab(win, txt)
241         self.myQtab.setCurrentWidget(win)
242         self.currentEditor=win
243         win.setFocus()
244
245    def getOpenStartDir(self) :
246        #PN --> Les Preferences
247         try :
248             userDir=os.path.expanduser("~/Eficas_install/")
249             return userDir
250         except :
251             return ""
252
253    def samepath(self,f1, f2):
254     """
255     compare two paths.
256     """
257     if f1 is None or f2 is None: return 0
258     if os.path.normcase(os.path.normpath(f1)) == os.path.normcase(os.path.normpath(f2)) : return 1
259     return 0
260
261
262    def checkDirty(self, editor):
263         """
264         Private method to check dirty status and open a message window.
265         
266         @param editor editor window to check
267         @return flag indicating successful reset of the dirty flag (boolean)
268         """        
269         res=1 
270         if (editor.modified) and (editor in self.doubles.keys()) :
271             res = QMessageBox.warning(
272                      None,
273                      self.appliEficas.trUtf8("Fichier Duplique"),
274                      self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."),
275                      self.appliEficas.trUtf8("&Quitter"), 
276                      self.appliEficas.trUtf8("&Annuler"))
277             if res == 0 : return 1
278             return 0
279         if editor.modified:
280             fn = editor.getFileName()
281             if fn is None:
282                 fn = self.appliEficas.trUtf8('Noname')
283             res = QMessageBox.warning(self.appliEficas, 
284                 self.appliEficas.trUtf8("Fichier Modifie"),
285                 self.appliEficas.trUtf8("Le fichier <b>%1</b> n a pas ete sauvegarde.") .arg(fn),
286                 self.appliEficas.trUtf8("&Sauvegarder"),
287                 self.appliEficas.trUtf8("&Quitter "),
288                 self.appliEficas.trUtf8("&Annuler") )
289             if res == 0:
290                 (ok, newName) = editor.saveFile()
291                 if ok:
292                     fileName=os.path.basename(unicode(newName))
293                     index=self.myQtab.currentIndex()
294                     self.myQtab.setTabText(index,fileName)
295                 return ok
296         return res