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 PyQt4.QtGui import *
22 from PyQt4.QtCore import *
23 from Extensions.i18n import tr
28 #---------------------------#
29 class PopUpMenuRacine :
30 #---------------------------#
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)
42 def addParametersApres(self):
43 item= self.tree.currentItem()
44 item.addParameters(True)
46 #---------------------------#
47 class PopUpMenuNodeMinimal :
48 #---------------------------#
50 def createPopUpMenu(self):
51 print "createPopUpMenu"
52 #self.appliEficas.salome=True
54 self.menu = QMenu(self.tree)
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() :
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,)
66 for commande in listeCommandes :
67 conditionSalome=commande[3]
68 if (self.appliEficas.salome == 0 and conditionSalome == True): return
71 self.action=QAction(label,self.tree)
72 self.action.setStatusTip(tip)
74 self.tree.connect(self.action,SIGNAL("activated()"),self.AppelleFonction4)
76 self.tree.connect(self.action,SIGNAL("activated()"),self.AppelleFonction3)
79 self.tree.connect(self.action,SIGNAL("activated()"),self.AppelleFonction2)
82 self.tree.connect(self.action,SIGNAL("activated()"),self.AppelleFonction1)
85 self.tree.connect(self.action,SIGNAL("activated()"),self.AppelleFonction0)
87 self.menu.addAction(self.action)
90 def AppelleFonction0(self):
91 self.AppelleFonction(0)
93 def AppelleFonction1(self):
94 self.AppelleFonction(1)
96 def AppelleFonction2(self):
97 self.AppelleFonction(2)
99 def AppelleFonction3(self):
100 self.AppelleFonction(3)
102 def AppelleFonction4(self):
103 self.AppelleFonction(4)
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,
113 tr("l item doit etre valide"),
117 listenomparam=commande[2]
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)
124 fonction(listeparam,self.appliEficas)
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 "))
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 "))
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 "))
151 def supprimeNoeud(self):
152 item= self.tree.currentItem()
156 self.node=self.tree.currentItem()
157 cle_doc = self.node.item.get_docu()
159 QMessageBox.information( self.editor,tr( "Documentation Vide"), \
160 tr("Aucune documentation n'est associee a ce noeud"))
162 commande = self.editor.appliEficas.CONFIGURATION.exec_acrobat
164 f=open(commande,"rb")
166 texte=tr("impossible de trouver la commande ") + commande
167 QMessageBox.information( self.editor, tr("Lecteur PDF"), texte)
170 if cle_doc.startswith('http:'):
173 fichier = os.path.abspath(os.path.join(self.editor.CONFIGURATION.path_doc,
178 texte=tr("impossible d'ouvrir ") + fichier
179 QMessageBox.information( self.editor, tr("Documentation Vide"), texte)
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)
189 def addParametersApres(self):
190 item= self.tree.currentItem()
191 item.addParameters(True)
193 def addParametersAvant(self):
194 item= self.tree.currentItem()
195 item.addParameters(False)
197 def addCommApres(self):
198 item= self.tree.currentItem()
199 item.addComment(True)
201 def addCommAvant(self):
202 item= self.tree.currentItem()
203 item.addComment(False)
205 #--------------------------------------------#
206 class PopUpMenuNodePartiel (PopUpMenuNodeMinimal):
207 #---------------------------------------------#
208 def createPopUpMenu(self):
209 PopUpMenuNodeMinimal.createPopUpMenu(self)
211 self.commentMenu=self.menu.addMenu(tr('Commentaire'))
212 self.commentMenu.addAction(self.CommApres)
213 self.commentMenu.addAction(self.CommAvant)
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)
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)
236 item= self.tree.currentItem()