Salome HOME
pb d accent. on les enleve en français
[tools/eficas.git] / InterfaceQT4 / typeNode.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 from PyQt4 import *
21 from PyQt4.QtGui import *
22 from PyQt4.QtCore import *
23 from Extensions.i18n import tr
24 import types
25
26
27
28 #---------------------------#
29 class PopUpMenuRacine :
30 #---------------------------#
31
32
33     def createPopUpMenu(self):
34         print "createPopUpMenu"
35         self.ParamApres = QAction(tr('Parametre'),self.tree)
36         self.tree.connect(self.ParamApres,SIGNAL("activated()"),self.addParametersApres)
37         self.ParamApres.setStatusTip(tr("Insere un parametre"))
38         self.menu = QMenu(self.tree)
39         self.menu.addAction(self.ParamApres)
40
41
42     def addParametersApres(self):
43         item= self.tree.currentItem()
44         item.addParameters(True)
45
46 #---------------------------#
47 class PopUpMenuNodeMinimal :
48 #---------------------------#
49
50     def createPopUpMenu(self):
51         print "createPopUpMenu"
52         #self.appliEficas.salome=True
53         self.createActions()
54         self.menu = QMenu(self.tree)
55         #items du menu
56         self.menu.addAction(self.Supprime)
57         if hasattr(self.appliEficas, 'mesScripts'):
58             if self.tree.currentItem().item.get_nom() in self.appliEficas.mesScripts.dict_commandes.keys() : 
59                self.ajoutScript()
60     
61     def ajoutScript(self):
62     # cochon mais je n arrive pas a faire mieux avec le mecanisme de plugin
63         listeCommandes=self.appliEficas.mesScripts.dict_commandes[self.tree.currentItem().item.get_nom()]
64         if type(listeCommandes) != types.TupleType: listeCommandes=(listeCommandes,)
65         numero=0
66         for commande in listeCommandes :
67            conditionSalome=commande[3]
68            if (self.appliEficas.salome == 0 and conditionSalome == True): return
69            label=commande[1]
70            tip=commande[5]
71            self.action=QAction(label,self.tree)
72            self.action.setStatusTip(tip)
73            if numero==4: 
74               self.tree.connect(self.action,SIGNAL("activated()"),self.AppelleFonction4)
75            if numero==3: 
76               self.tree.connect(self.action,SIGNAL("activated()"),self.AppelleFonction3)
77               numero=4
78            if numero==2: 
79               self.tree.connect(self.action,SIGNAL("activated()"),self.AppelleFonction2)
80               numero=3
81            if numero==1: 
82               self.tree.connect(self.action,SIGNAL("activated()"),self.AppelleFonction1)
83               numero=2
84            if numero==0: 
85               self.tree.connect(self.action,SIGNAL("activated()"),self.AppelleFonction0)
86               numero=1
87            self.menu.addAction(self.action)
88
89
90     def AppelleFonction0(self):
91         self.AppelleFonction(0)
92
93     def AppelleFonction1(self):
94         self.AppelleFonction(1)
95
96     def AppelleFonction2(self):
97         self.AppelleFonction(2)
98
99     def AppelleFonction3(self):
100         self.AppelleFonction(3)
101
102     def AppelleFonction4(self):
103         self.AppelleFonction(4)
104
105
106     def AppelleFonction(self,numero):
107         listeCommandes=self.appliEficas.mesScripts.dict_commandes[self.tree.currentItem().item.get_nom()]
108         commande=listeCommandes[numero]
109         conditionValid=commande[4]
110         if (self.tree.currentItem().item.isvalid() == 0 and conditionValid == True):
111                  QMessageBox.warning( None, 
112                              tr("item invalide"),
113                              tr("l item doit etre valide"),
114                              tr("&Ok"))
115                  return
116         fonction=commande[0]
117         listenomparam=commande[2]
118         listeparam=[]
119         for p in listenomparam:
120             if hasattr(self.tree.currentItem(),p):
121                listeparam.append(getattr(self.tree.currentItem(),p))
122             if p=="self" : listeparam.append(self)
123         try :
124            fonction(listeparam,self.appliEficas)
125         except :
126            fonction(listeparam)
127
128
129     def createActions(self):
130         self.CommApres = QAction(tr('apres'),self.tree)
131         self.tree.connect(self.CommApres,SIGNAL("activated()"),self.addCommApres)
132         self.CommApres.setStatusTip(tr("Insere un commentaire apres la commande "))
133         self.CommAvant = QAction(tr('avant'),self.tree)
134         self.tree.connect(self.CommAvant,SIGNAL("activated()"),self.addCommAvant)
135         self.CommAvant.setStatusTip(tr("Insere un commentaire avant la commande "))
136
137         self.ParamApres = QAction(tr('apres'),self.tree)
138         self.tree.connect(self.ParamApres,SIGNAL("activated()"),self.addParametersApres)
139         self.ParamApres.setStatusTip(tr("Insere un parametre apres la commande "))
140         self.ParamAvant = QAction(tr('avant'),self.tree)
141         self.tree.connect(self.ParamAvant,SIGNAL("activated()"),self.addParametersAvant)
142         self.ParamAvant.setStatusTip(tr("Insere un parametre avant la commande "))
143
144         self.Supprime = QAction(tr('Supprimer'),self.tree)
145         self.tree.connect(self.Supprime,SIGNAL("activated()"),self.supprimeNoeud)
146         self.Supprime.setStatusTip(tr("supprime le mot clef "))
147         self.Documentation = QAction(tr('Documentation'),self.tree)
148         self.tree.connect(self.Documentation,SIGNAL("activated()"),self.viewDoc)
149         self.Documentation.setStatusTip(tr("documentation sur la commande "))
150
151     def supprimeNoeud(self):
152         item= self.tree.currentItem()
153         item.delete()
154
155     def viewDoc(self):
156         self.node=self.tree.currentItem()
157         cle_doc = self.node.item.get_docu()
158         if cle_doc == None :
159             QMessageBox.information( self.editor,tr( "Documentation Vide"), \
160                                     tr("Aucune documentation n'est associee a ce noeud"))
161             return
162         commande = self.editor.appliEficas.CONFIGURATION.exec_acrobat
163         try :
164             f=open(commande,"rb")
165         except :
166              texte=tr("impossible de trouver la commande  ") + commande
167              QMessageBox.information( self.editor, tr("Lecteur PDF"), texte)
168              return
169         import os
170         if cle_doc.startswith('http:'):
171            fichier = cle_doc
172         else :
173             fichier = os.path.abspath(os.path.join(self.editor.CONFIGURATION.path_doc,
174                                        cle_doc))
175             try :
176                f=open(fichier,"rb")
177             except :
178                texte=tr("impossible d'ouvrir ") + fichier
179                QMessageBox.information( self.editor, tr("Documentation Vide"), texte)
180                return
181
182        
183         if os.name == 'nt':
184            os.spawnv(os.P_NOWAIT,commande,(commande,fichier,))
185         elif os.name == 'posix':
186             script ="#!/usr/bin/sh \n%s %s&" %(commande,fichier)
187             pid = os.system(script)
188
189     def addParametersApres(self):
190         item= self.tree.currentItem()
191         item.addParameters(True)
192
193     def addParametersAvant(self):
194         item= self.tree.currentItem()
195         item.addParameters(False)
196
197     def addCommApres(self):
198         item= self.tree.currentItem()
199         item.addComment(True)
200
201     def addCommAvant(self):
202         item= self.tree.currentItem()
203         item.addComment(False)
204
205 #--------------------------------------------#
206 class PopUpMenuNodePartiel (PopUpMenuNodeMinimal):
207 #---------------------------------------------#
208     def createPopUpMenu(self):
209         PopUpMenuNodeMinimal.createPopUpMenu(self)
210         #ss-menu Comment:
211         self.commentMenu=self.menu.addMenu(tr('Commentaire'))
212         self.commentMenu.addAction(self.CommApres)
213         self.commentMenu.addAction(self.CommAvant)
214         #ss-menu Parameters:
215         self.paramMenu =self.menu.addMenu(tr('Parametre')) 
216         self.paramMenu.addAction(self.ParamApres)
217         self.paramMenu.addAction(self.ParamAvant)
218         self.menu.addAction(self.Documentation)
219         self.menu.removeAction(self.Supprime)
220         self.menu.addAction(self.Supprime)
221
222
223 #-----------------------------------------#
224 class PopUpMenuNode(PopUpMenuNodePartiel) :
225 #-----------------------------------------#
226     def createPopUpMenu(self):
227         PopUpMenuNodePartiel.createPopUpMenu(self)
228         self.Commente = QAction(tr('ce noeud'),self.tree)
229         self.tree.connect(self.Commente,SIGNAL("activated()"),self.Commenter)
230         self.Commente.setStatusTip(tr("commente le noeud "))
231         self.commentMenu.addAction(self.Commente)
232         self.menu.removeAction(self.Supprime)
233         self.menu.addAction(self.Supprime)
234
235     def Commenter(self):
236         item= self.tree.currentItem()
237         item.commentIt()