]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/viewManager.py
Salome HOME
52650ead67fdf481aed2c014ad19243e10ac5ca6
[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.getOpenStartDir(),
48                         self.appliEficas.trUtf8('JDC Files (*.comm);;''All Files (*)'))
49             if fichier.isNull(): return
50        from utilitaires import normabspath
51        fichier = normabspath(unicode(fichier))
52        maPage=self.getEditor( fichier,units=units)
53
54    def handleClose(self,doitSauverRecent = 1):
55        print "passage dans handleClose"
56        print self.dict_editors
57        if doitSauverRecent : self.appliEficas.sauveRecents()
58        index=self.myQtab.currentIndex()
59        if index < 0 : return
60        self.checkDirty(self.dict_editors[index])
61        index=self.myQtab.currentIndex()
62        while index < len(self.dict_editors) -1 :
63              self.dict_editors[index]=self.dict_editors[index+1]
64              index = index + 1
65        del self.dict_editors[len (self.dict_editors) -1]
66        try :
67            del self.doubles[self.dict_editors[index]]
68        except :
69            pass
70        print self.dict_editors
71        self.myQtab.removeTab(index)
72        
73
74    def handleCloseAll(self):
75        self.appliEficas.sauveRecents()
76        print "passage dans CloseAll"
77        print "self.dict_editors", self.dict_editors
78        while len(self.dict_editors) > 0 :
79              self.myQtab.setCurrentIndex(0)
80              self.handleClose(0)
81         
82    def handleEditCopy(self):
83        print "passage dans handleEditCopy"
84        index=self.myQtab.currentIndex()
85        editor=self.dict_editors[index]
86        editor.handleEditCopy()
87
88    def handleEditCut(self):
89        print "passage dans handleEditCut"
90        index=self.myQtab.currentIndex()
91        editor=self.dict_editors[index]
92        editor.handleEditCut()
93
94    def handleEditPaste(self):
95        print "passage dans handleEditPaste"
96        index=self.myQtab.currentIndex()
97        editor=self.dict_editors[index]
98        editor.handleEditPaste()
99
100    def newEditor(self,include=0):
101        print "passage dans newEditor"
102        maPage=self.getEditor()
103
104    def newIncludeEditor(self):
105        self.newEditor(include=1)
106
107    def handleViewJdcFichierSource(self):
108        index=self.myQtab.currentIndex()
109        if index < 0 : return
110        self.dict_editors[index].viewJdcSource()
111
112    def handleViewJdcRapport(self):
113        index=self.myQtab.currentIndex()
114        if index < 0 : return
115        self.dict_editors[index].viewJdcRapport()
116
117    def handleViewJdcPy(self):
118        index=self.myQtab.currentIndex()
119        if index < 0 : return
120        self.dict_editors[index].viewJdcPy()
121
122    def saveCurrentEditor(self):
123        index=self.myQtab.currentIndex()
124        if index < 0 : return
125        editor=self.dict_editors[index]
126        if editor in self.doubles.keys() :
127            QMessageBox.warning(
128                      None,
129                      self.appliEficas.trUtf8("Fichier Duplique"),
130                      self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."),
131                      self.appliEficas.trUtf8("&Annuler"))
132            return
133        ok, newName = editor.saveFile()
134        if ok :
135            fileName=os.path.basename(unicode(newName))
136            self.myQtab.setTabText(index,fileName)
137
138    def saveAsCurrentEditor(self):
139        index=self.myQtab.currentIndex()
140        editor=self.dict_editors[index]
141        oldName=editor.fichier
142        ok,newName = editor.saveFileAs()
143        if ok :
144            fileName=os.path.basename(unicode(newName))
145            self.myQtab.setTabText(index,fileName)
146        if editor in self.doubles.keys():
147           if oldName != newName :
148              del self.doubles[editor]
149
150
151    def displayJDC(self,jdc,fn=None):
152         """
153         Public slot to display a file in an editor.
154         @param fn name of file to be opened
155         # insert filename into list of recently opened files
156         """
157         titre=None
158         if fn != None : titre=fn.split("/")[-1]
159         editor = self.getEditor(fichier= fn, jdc = jdc ,include=1)
160         self.appliEficas.addToRecentList(editor.getFileName())
161
162    def getEditor(self,fichier = None,jdc = None, units = None,include=0):
163        newWin = 0
164        double = None
165        indexEditor=0
166        for indexEditor in self.dict_editors.keys():
167            editor=self.dict_editors[indexEditor]
168            from utilitaires import samepath
169            if samepath(fichier, editor.getFileName()):
170               abort = QMessageBox.warning(self.appliEficas,
171                         self.appliEficas.trUtf8("Fichier"),
172                         self.appliEficas.trUtf8("Le fichier <b>%1</b> est deja ouvert.").arg(fichier),
173                         self.appliEficas.trUtf8("&Duplication"),
174                         self.appliEficas.trUtf8("&Abort"))
175               if abort: break
176               double=editor
177        else :
178             from editor import JDCEditor
179             editor = JDCEditor(fichier, jdc, self.myQtab,units=units,appli=self.appliEficas,vm = self,include=include)
180             if double != None :
181                self.doubles[editor]=double
182             if editor.jdc: # le fichier est bien un jdc
183                 self.editors.append(editor)
184                 newWin = 1
185             else:
186                 editor.closeIt()
187
188        if newWin:
189             self.addView(editor, fichier)
190        elif editor.jdc:
191             self.myQtab.setCurrentIndex(indexEditor)
192
193        index=self.myQtab.currentIndex()
194        if index != -1 :
195           self.dict_editors[index]=editor
196        return editor
197
198    def addView(self, win, fichier=None):
199         if fichier is None:
200             self.untitledCount += 1
201             self.myQtab.addTab(win, self.appliEficas.trUtf8("Untitled %1").arg(self.untitledCount))
202         else:
203             liste=fichier.split('/')
204             txt =  liste[-1]
205             if not QFileInfo(fichier).isWritable():
206                 txt = '%s (ro)' % txt
207             self.myQtab.addTab(win, txt)
208         self.myQtab.setCurrentWidget(win)
209         self.currentEditor=win
210         win.setFocus()
211
212    def getOpenStartDir(self) :
213        #PN --> Les Preferences
214         try :
215             userDir=os.path.expanduser("~/Eficas_install/")
216             return userDir
217         except :
218             return ""
219
220
221    def checkDirty(self, editor):
222         """
223         Private method to check dirty status and open a message window.
224         
225         @param editor editor window to check
226         @return flag indicating successful reset of the dirty flag (boolean)
227         """        
228      
229         print "checkDirty"
230         if (editor.modified) and (editor in self.doubles.keys()) :
231             res = QMessageBox.warning(
232                      None,
233                      self.appliEficas.trUtf8("Fichier Duplique"),
234                      self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."),
235                      self.appliEficas.trUtf8("&Quitter"), 
236                      self.appliEficas.trUtf8("&Annuler"))
237             if res == 0 : return 1
238             return 0
239         if editor.modified:
240             fn = editor.getFileName()
241             if fn is None:
242                 fn = self.appliEficas.trUtf8('Noname')
243             res = QMessageBox.warning(self.appliEficas, 
244                 self.appliEficas.trUtf8("Fichier Modifie"),
245                 self.appliEficas.trUtf8("Le fichier <b>%1</b> n a pas ete sauvegarde.")
246                     .arg(fn),
247                 self.appliEficas.trUtf8("&Sauvegarder"),
248                 self.appliEficas.trUtf8("&Quitter "),
249                 self.appliEficas.trUtf8("&Annuler"), 0, 2)
250             if res == 0:
251                 (ok, newName) = editor.saveFile()
252                 if ok:
253                     fileName=os.path.basename(unicode(newName))
254                     index=self.myQtab.currentIndex()
255                     self.myQtab.setTabText(index,fileName)
256                 return ok
257             elif res == 2:
258                 return  0
259         return 1
260