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("triggered()"),self.addParametersApres)
37 self.ParamApres.setStatusTip(tr("Insere un parametre"))
38 self.menu = QMenu(self.tree)
39 self.menu.addAction(self.ParamApres)
40 self.menu.setStyleSheet("background:rgb(220,220,220); ")
43 def addParametersApres(self):
44 item= self.tree.currentItem()
45 item.addParameters(True)
47 #---------------------------#
48 class PopUpMenuNodeMinimal :
49 #---------------------------#
51 def createPopUpMenu(self):
52 #print "createPopUpMenu"
53 #self.appliEficas.salome=True
55 self.menu = QMenu(self.tree)
56 #self.menu.setStyleSheet("background:rgb(235,235,235); QMenu::item:selected { background-color: red; }")
57 #ne fonctionne pas --> la ligne de commentaire devient rouge
58 self.menu.setStyleSheet("background:rgb(220,220,220); ")
60 self.menu.addAction(self.Supprime)
61 if hasattr(self.appliEficas, 'mesScripts'):
62 if self.tree.currentItem().item.get_nom() in self.appliEficas.mesScripts.dict_commandes.keys() :
65 def ajoutScript(self):
66 # cochon mais je n arrive pas a faire mieux avec le mecanisme de plugin
67 listeCommandes=self.appliEficas.mesScripts.dict_commandes[self.tree.currentItem().item.get_nom()]
68 if type(listeCommandes) != types.TupleType: listeCommandes=(listeCommandes,)
70 for commande in listeCommandes :
71 conditionSalome=commande[3]
72 if (self.appliEficas.salome == 0 and conditionSalome == True): return
75 self.action=QAction(label,self.tree)
76 self.action.setStatusTip(tip)
78 self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction4)
80 self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction3)
83 self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction2)
86 self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction1)
89 self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction0)
91 self.menu.addAction(self.action)
94 def AppelleFonction0(self):
95 self.AppelleFonction(0)
97 def AppelleFonction1(self):
98 self.AppelleFonction(1)
100 def AppelleFonction2(self):
101 self.AppelleFonction(2)
103 def AppelleFonction3(self):
104 self.AppelleFonction(3)
106 def AppelleFonction4(self):
107 self.AppelleFonction(4)
110 def AppelleFonction(self,numero):
111 listeCommandes=self.appliEficas.mesScripts.dict_commandes[self.tree.currentItem().item.get_nom()]
112 commande=listeCommandes[numero]
113 conditionValid=commande[4]
114 if (self.tree.currentItem().item.isvalid() == 0 and conditionValid == True):
115 QMessageBox.warning( None,
117 tr("l item doit etre valide"),
121 listenomparam=commande[2]
123 for p in listenomparam:
124 if hasattr(self.tree.currentItem(),p):
125 listeparam.append(getattr(self.tree.currentItem(),p))
126 if p=="self" : listeparam.append(self)
128 fonction(listeparam,self.appliEficas)
133 def createActions(self):
134 self.CommApres = QAction(tr('apres'),self.tree)
135 self.tree.connect(self.CommApres,SIGNAL("triggered()"),self.addCommApres)
136 self.CommApres.setStatusTip(tr("Insere un commentaire apres la commande "))
137 self.CommAvant = QAction(tr('avant'),self.tree)
138 self.tree.connect(self.CommAvant,SIGNAL("triggered()"),self.addCommAvant)
139 self.CommAvant.setStatusTip(tr("Insere un commentaire avant la commande "))
141 self.ParamApres = QAction(tr('apres'),self.tree)
142 self.tree.connect(self.ParamApres,SIGNAL("triggered()"),self.addParametersApres)
143 self.ParamApres.setStatusTip(tr("Insere un parametre apres la commande "))
144 self.ParamAvant = QAction(tr('avant'),self.tree)
145 self.tree.connect(self.ParamAvant,SIGNAL("triggered()"),self.addParametersAvant)
146 self.ParamAvant.setStatusTip(tr("Insere un parametre avant la commande "))
148 self.Supprime = QAction(tr('Supprimer'),self.tree)
149 self.tree.connect(self.Supprime,SIGNAL("triggered()"),self.supprimeNoeud)
150 self.Supprime.setStatusTip(tr("supprime le mot clef "))
151 self.Documentation = QAction(tr('Documentation'),self.tree)
152 self.tree.connect(self.Documentation,SIGNAL("triggered()"),self.viewDoc)
153 self.Documentation.setStatusTip(tr("documentation sur la commande "))
155 def supprimeNoeud(self):
156 item= self.tree.currentItem()
160 self.node=self.tree.currentItem()
161 cle_doc = self.node.item.get_docu()
163 QMessageBox.information( self.editor,tr( "Documentation Vide"), \
164 tr("Aucune documentation n'est associee a ce noeud"))
166 commande = self.editor.appliEficas.CONFIGURATION.exec_acrobat
168 f=open(commande,"rb")
170 texte=tr("impossible de trouver la commande ") + commande
171 QMessageBox.information( self.editor, tr("Lecteur PDF"), texte)
174 if cle_doc.startswith('http:'):
177 fichier = os.path.abspath(os.path.join(self.editor.CONFIGURATION.path_doc,
182 texte=tr("impossible d'ouvrir ") + fichier
183 QMessageBox.information( self.editor, tr("Documentation Vide"), texte)
188 os.spawnv(os.P_NOWAIT,commande,(commande,fichier,))
189 elif os.name == 'posix':
190 script ="#!/usr/bin/sh \n%s %s&" %(commande,fichier)
191 pid = os.system(script)
193 def addParametersApres(self):
194 item= self.tree.currentItem()
195 item.addParameters(True)
197 def addParametersAvant(self):
198 item= self.tree.currentItem()
199 item.addParameters(False)
201 def addCommApres(self):
202 item= self.tree.currentItem()
203 item.addComment(True)
205 def addCommAvant(self):
206 item= self.tree.currentItem()
207 item.addComment(False)
209 #--------------------------------------------#
210 class PopUpMenuNodePartiel (PopUpMenuNodeMinimal):
211 #---------------------------------------------#
212 def createPopUpMenu(self):
213 PopUpMenuNodeMinimal.createPopUpMenu(self)
215 self.commentMenu=self.menu.addMenu(tr('Commentaire'))
216 self.commentMenu.addAction(self.CommApres)
217 self.commentMenu.addAction(self.CommAvant)
219 self.paramMenu =self.menu.addMenu(tr('Parametre'))
220 self.paramMenu.addAction(self.ParamApres)
221 self.paramMenu.addAction(self.ParamAvant)
222 self.menu.addAction(self.Documentation)
223 self.menu.removeAction(self.Supprime)
224 self.menu.addAction(self.Supprime)
227 #-----------------------------------------#
228 class PopUpMenuNode(PopUpMenuNodePartiel) :
229 #-----------------------------------------#
230 def createPopUpMenu(self):
231 PopUpMenuNodePartiel.createPopUpMenu(self)
232 self.Commente = QAction(tr('ce noeud'),self.tree)
233 self.tree.connect(self.Commente,SIGNAL("triggered()"),self.Commenter)
234 self.Commente.setStatusTip(tr("commente le noeud "))
235 self.commentMenu.addAction(self.Commente)
236 self.menu.removeAction(self.Supprime)
237 self.menu.addAction(self.Supprime)
240 item= self.tree.currentItem()