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
20 from __future__ import absolute_import
22 from builtins import object
25 from PyQt5.QtWidgets import QAction, QMenu, QMessageBox
27 from Extensions.i18n import tr
32 #---------------------------#
33 class PopUpMenuRacine(object) :
34 #---------------------------#
37 def createPopUpMenu(self):
38 #print "createPopUpMenu"
39 self.ParamApres = QAction(tr('Parametre'),self.tree)
40 self.ParamApres.triggered.connect(self.addParametersApres)
41 self.ParamApres.setStatusTip(tr("Insere un parametre"))
42 self.menu = QMenu(self.tree)
43 self.menu.addAction(self.ParamApres)
44 self.menu.setStyleSheet("background:rgb(220,220,220); ")
47 def addParametersApres(self):
48 item= self.tree.currentItem()
49 item.addParameters(True)
51 #---------------------------#
52 class PopUpMenuNodeMinimal(object) :
53 #---------------------------#
55 def createPopUpMenu(self):
56 #print "createPopUpMenu"
57 #self.appliEficas.salome=True
59 self.menu = QMenu(self.tree)
60 #self.menu.setStyleSheet("background:rgb(235,235,235); QMenu::item:selected { background-color: red; }")
61 #ne fonctionne pas --> la ligne de commentaire devient rouge
62 self.menu.setStyleSheet("background:rgb(220,220,220); ")
64 self.menu.addAction(self.Supprime)
65 if hasattr(self.appliEficas, 'mesScripts'):
66 if self.editor.code in self.editor.appliEficas.mesScripts :
67 self.dict_commandes_mesScripts=self.appliEficas.mesScripts[self.editor.code].dict_commandes
68 if self.tree.currentItem().item.get_nom() in self.dict_commandes_mesScripts :
71 def ajoutScript(self):
73 # cochon mais je n arrive pas a faire mieux avec le mecanisme de plugin
74 if hasattr(self.appliEficas, 'mesScripts'):
75 if self.editor.code in self.editor.appliEficas.mesScripts :
76 self.dict_commandes_mesScripts=self.appliEficas.mesScripts[self.editor.code].dict_commandes
79 from Extensions import jdc_include
80 if isinstance(self.item.jdc,jdc_include.JDC_INCLUDE) : return
82 listeCommandes=self.dict_commandes_mesScripts[self.tree.currentItem().item.get_nom()]
83 if type(listeCommandes) != tuple: listeCommandes=(listeCommandes,)
85 for commande in listeCommandes :
86 conditionSalome=commande[3]
87 if (self.appliEficas.salome == 0 and conditionSalome == True): return
90 self.action=QAction(label,self.tree)
91 self.action.setStatusTip(tip)
92 if numero==4: self.action.triggered.connect(self.AppelleFonction4)
93 if numero==3: self.action.triggered.connect(self.AppelleFonction3); numero=4
94 if numero==2: self.action.triggered.connect(self.AppelleFonction2); numero=3
95 if numero==1: self.action.triggered.connect(self.AppelleFonction1); numero=2
96 if numero==0: self.action.triggered.connect(self.AppelleFonction0); numero=1
97 self.menu.addAction(self.action)
100 def AppelleFonction0(self):
101 self.AppelleFonction(0)
103 def AppelleFonction1(self):
104 self.AppelleFonction(1)
106 def AppelleFonction2(self):
107 self.AppelleFonction(2)
109 def AppelleFonction3(self):
110 self.AppelleFonction(3)
112 def AppelleFonction4(self):
113 self.AppelleFonction(4)
116 def AppelleFonction(self,numero,nodeTraite=None):
117 if nodeTraite==None : nodeTraite=self.tree.currentItem()
118 nomCmd=nodeTraite.item.get_nom()
119 if hasattr(self.appliEficas, 'mesScripts'):
120 if self.editor.code in self.editor.appliEficas.mesScripts :
121 self.dict_commandes_mesScripts=self.appliEficas.mesScripts[self.editor.code].dict_commandes
123 listeCommandes=self.dict_commandes_mesScripts[nomCmd]
124 commande=listeCommandes[numero]
125 conditionValid=commande[4]
128 if (nodeTraite.item.isvalid() == 0 and conditionValid == True):
129 QMessageBox.warning( None,
131 tr("l item doit etre valide"),)
134 listenomparam=commande[2]
136 for p in listenomparam:
137 if hasattr(nodeTraite,p):
138 listeparam.append(getattr(nodeTraite,p))
139 if p=="self" : listeparam.append(self)
142 res, commentaire= fonction(listeparam)
144 QMessageBox.warning( None,
145 tr("echec de la fonction"),
153 def createActionsQT4(self):
154 self.CommApres = QAction(tr('apres'),self.tree)
155 self.tree.connect(self.CommApres,SIGNAL("triggered()"),self.addCommApres)
156 self.CommApres.setStatusTip(tr("Insere un commentaire apres la commande "))
157 self.CommAvant = QAction(tr('avant'),self.tree)
158 self.tree.connect(self.CommAvant,SIGNAL("triggered()"),self.addCommAvant)
159 self.CommAvant.setStatusTip(tr("Insere un commentaire avant la commande "))
161 self.ParamApres = QAction(tr('apres'),self.tree)
162 self.tree.connect(self.ParamApres,SIGNAL("triggered()"),self.addParametersApres)
163 self.ParamApres.setStatusTip(tr("Insere un parametre apres la commande "))
164 self.ParamAvant = QAction(tr('avant'),self.tree)
165 self.tree.connect(self.ParamAvant,SIGNAL("triggered()"),self.addParametersAvant)
166 self.ParamAvant.setStatusTip(tr("Insere un parametre avant la commande "))
168 self.Supprime = QAction(tr('Supprimer'),self.tree)
169 self.tree.connect(self.Supprime,SIGNAL("triggered()"),self.supprimeNoeud)
170 self.Supprime.setStatusTip(tr("supprime le mot clef "))
171 self.Documentation = QAction(tr('Documentation'),self.tree)
172 self.tree.connect(self.Documentation,SIGNAL("triggered()"),self.viewDoc)
174 def createActions(self):
175 self.CommApres = QAction(tr('apres'),self.tree)
176 self.CommApres.triggered.connect(self.addCommApres)
177 self.CommApres.setStatusTip(tr("Insere un commentaire apres la commande "))
178 self.CommAvant = QAction(tr('avant'),self.tree)
179 self.CommAvant.triggered.connect(self.addCommAvant)
180 self.CommAvant.setStatusTip(tr("Insere un commentaire avant la commande "))
182 self.ParamApres = QAction(tr('apres'),self.tree)
183 self.ParamApres.triggered.connect(self.addParametersApres)
184 self.ParamApres.setStatusTip(tr("Insere un parametre apres la commande "))
185 self.ParamAvant = QAction(tr('avant'),self.tree)
186 self.ParamAvant.triggered.connect(self.addParametersAvant)
187 self.ParamAvant.setStatusTip(tr("Insere un parametre avant la commande "))
189 self.Supprime = QAction(tr('Supprimer'),self.tree)
190 self.Supprime.triggered.connect(self.supprimeNoeud)
191 self.Supprime.setStatusTip(tr("supprime le mot clef "))
192 self.Documentation = QAction(tr('Documentation'),self.tree)
193 self.Documentation.triggered.connect(self.viewDoc)
194 self.Documentation.setStatusTip(tr("documentation sur la commande "))
196 def supprimeNoeud(self):
197 item= self.tree.currentItem()
201 self.node=self.tree.currentItem()
202 cle_doc = self.node.item.get_docu()
204 QMessageBox.information( self.editor,tr( "Documentation Vide"), \
205 tr("Aucune documentation n'est associee a ce noeud"))
207 commande = self.editor.appliEficas.CONFIGURATION.exec_acrobat
209 f=open(commande,"rb")
211 texte=tr("impossible de trouver la commande ") + commande
212 QMessageBox.information( self.editor, tr("Lecteur PDF"), texte)
215 if cle_doc.startswith('http:'):
218 fichier = os.path.abspath(os.path.join(self.editor.CONFIGURATION.path_doc,
223 texte=tr("impossible d'ouvrir ") + fichier
224 QMessageBox.information( self.editor, tr("Documentation Vide"), texte)
229 os.spawnv(os.P_NOWAIT,commande,(commande,fichier,))
230 elif os.name == 'posix':
231 script ="#!/usr/bin/sh \n%s %s&" %(commande,fichier)
232 pid = os.system(script)
234 def addParametersApres(self):
235 item= self.tree.currentItem()
236 item.addParameters(True)
238 def addParametersAvant(self):
239 item= self.tree.currentItem()
240 item.addParameters(False)
242 def addCommApres(self):
243 item= self.tree.currentItem()
244 item.addComment(True)
246 def addCommAvant(self):
247 item= self.tree.currentItem()
248 item.addComment(False)
250 #--------------------------------------------#
251 class PopUpMenuNodePartiel (PopUpMenuNodeMinimal):
252 #---------------------------------------------#
253 def createPopUpMenu(self):
254 PopUpMenuNodeMinimal.createPopUpMenu(self)
256 self.commentMenu=self.menu.addMenu(tr('Commentaire'))
257 self.commentMenu.addAction(self.CommApres)
258 self.commentMenu.addAction(self.CommAvant)
260 self.paramMenu =self.menu.addMenu(tr('Parametre'))
261 self.paramMenu.addAction(self.ParamApres)
262 self.paramMenu.addAction(self.ParamAvant)
263 self.menu.addAction(self.Documentation)
264 self.menu.removeAction(self.Supprime)
265 self.menu.addAction(self.Supprime)
268 #-----------------------------------------#
269 class PopUpMenuNode(PopUpMenuNodePartiel) :
270 #-----------------------------------------#
271 def createPopUpMenu(self):
272 PopUpMenuNodePartiel.createPopUpMenu(self)
273 self.Commente = QAction(tr('ce noeud'),self.tree)
274 self.Commente.triggered.connect(self.Commenter)
275 self.Commente.setStatusTip(tr("commente le noeud "))
276 self.commentMenu.addAction(self.Commente)
277 self.menu.removeAction(self.Supprime)
278 self.menu.addAction(self.Supprime)
281 item= self.tree.currentItem()