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
78 listeCommandes=self.dict_commandes_mesScripts[self.tree.currentItem().item.get_nom()]
79 if type(listeCommandes) != tuple: listeCommandes=(listeCommandes,)
81 for commande in listeCommandes :
82 conditionSalome=commande[3]
83 if (self.appliEficas.salome == 0 and conditionSalome == True): return
86 self.action=QAction(label,self.tree)
87 self.action.setStatusTip(tip)
88 if numero==4: self.action.triggered.connect(self.AppelleFonction4)
89 if numero==3: self.action.triggered.connect(self.AppelleFonction3); numero=4
90 if numero==2: self.action.triggered.connect(self.AppelleFonction2); numero=3
91 if numero==1: self.action.triggered.connect(self.AppelleFonction1); numero=2
92 if numero==0: self.action.triggered.connect(self.AppelleFonction0); numero=1
93 self.menu.addAction(self.action)
96 def AppelleFonction0(self):
97 self.AppelleFonction(0)
99 def AppelleFonction1(self):
100 self.AppelleFonction(1)
102 def AppelleFonction2(self):
103 self.AppelleFonction(2)
105 def AppelleFonction3(self):
106 self.AppelleFonction(3)
108 def AppelleFonction4(self):
109 self.AppelleFonction(4)
112 def AppelleFonction(self,numero,nodeTraite=None):
113 if nodeTraite==None : nodeTraite=self.tree.currentItem()
114 nomCmd=nodeTraite.item.get_nom()
115 if hasattr(self.appliEficas, 'mesScripts'):
116 if self.editor.code in self.editor.appliEficas.mesScripts :
117 self.dict_commandes_mesScripts=self.appliEficas.mesScripts[self.editor.code].dict_commandes
119 listeCommandes=self.dict_commandes_mesScripts[nomCmd]
120 commande=listeCommandes[numero]
121 conditionValid=commande[4]
122 if (nodeTraite.item.isvalid() == 0 and conditionValid == True):
123 QMessageBox.warning( None,
125 tr("l item doit etre valide"),)
128 listenomparam=commande[2]
130 for p in listenomparam:
131 if hasattr(nodeTraite,p):
132 listeparam.append(getattr(nodeTraite,p))
133 if p=="self" : listeparam.append(self)
136 res, commentaire= fonction(listeparam)
138 QMessageBox.warning( None,
139 tr("echec de la fonction"),
147 def createActionsQT4(self):
148 self.CommApres = QAction(tr('apres'),self.tree)
149 self.tree.connect(self.CommApres,SIGNAL("triggered()"),self.addCommApres)
150 self.CommApres.setStatusTip(tr("Insere un commentaire apres la commande "))
151 self.CommAvant = QAction(tr('avant'),self.tree)
152 self.tree.connect(self.CommAvant,SIGNAL("triggered()"),self.addCommAvant)
153 self.CommAvant.setStatusTip(tr("Insere un commentaire avant la commande "))
155 self.ParamApres = QAction(tr('apres'),self.tree)
156 self.tree.connect(self.ParamApres,SIGNAL("triggered()"),self.addParametersApres)
157 self.ParamApres.setStatusTip(tr("Insere un parametre apres la commande "))
158 self.ParamAvant = QAction(tr('avant'),self.tree)
159 self.tree.connect(self.ParamAvant,SIGNAL("triggered()"),self.addParametersAvant)
160 self.ParamAvant.setStatusTip(tr("Insere un parametre avant la commande "))
162 self.Supprime = QAction(tr('Supprimer'),self.tree)
163 self.tree.connect(self.Supprime,SIGNAL("triggered()"),self.supprimeNoeud)
164 self.Supprime.setStatusTip(tr("supprime le mot clef "))
165 self.Documentation = QAction(tr('Documentation'),self.tree)
166 self.tree.connect(self.Documentation,SIGNAL("triggered()"),self.viewDoc)
168 def createActions(self):
169 self.CommApres = QAction(tr('apres'),self.tree)
170 self.CommApres.triggered.connect(self.addCommApres)
171 self.CommApres.setStatusTip(tr("Insere un commentaire apres la commande "))
172 self.CommAvant = QAction(tr('avant'),self.tree)
173 self.CommAvant.triggered.connect(self.addCommAvant)
174 self.CommAvant.setStatusTip(tr("Insere un commentaire avant la commande "))
176 self.ParamApres = QAction(tr('apres'),self.tree)
177 self.ParamApres.triggered.connect(self.addParametersApres)
178 self.ParamApres.setStatusTip(tr("Insere un parametre apres la commande "))
179 self.ParamAvant = QAction(tr('avant'),self.tree)
180 self.ParamAvant.triggered.connect(self.addParametersAvant)
181 self.ParamAvant.setStatusTip(tr("Insere un parametre avant la commande "))
183 self.Supprime = QAction(tr('Supprimer'),self.tree)
184 self.Supprime.triggered.connect(self.supprimeNoeud)
185 self.Supprime.setStatusTip(tr("supprime le mot clef "))
186 self.Documentation = QAction(tr('Documentation'),self.tree)
187 self.Documentation.triggered.connect(self.viewDoc)
188 self.Documentation.setStatusTip(tr("documentation sur la commande "))
190 def supprimeNoeud(self):
191 item= self.tree.currentItem()
195 self.node=self.tree.currentItem()
196 cle_doc = self.node.item.get_docu()
198 QMessageBox.information( self.editor,tr( "Documentation Vide"), \
199 tr("Aucune documentation n'est associee a ce noeud"))
201 commande = self.editor.appliEficas.CONFIGURATION.exec_acrobat
203 f=open(commande,"rb")
205 texte=tr("impossible de trouver la commande ") + commande
206 QMessageBox.information( self.editor, tr("Lecteur PDF"), texte)
209 if cle_doc.startswith('http:'):
212 fichier = os.path.abspath(os.path.join(self.editor.CONFIGURATION.path_doc,
217 texte=tr("impossible d'ouvrir ") + fichier
218 QMessageBox.information( self.editor, tr("Documentation Vide"), texte)
223 os.spawnv(os.P_NOWAIT,commande,(commande,fichier,))
224 elif os.name == 'posix':
225 script ="#!/usr/bin/sh \n%s %s&" %(commande,fichier)
226 pid = os.system(script)
228 def addParametersApres(self):
229 item= self.tree.currentItem()
230 item.addParameters(True)
232 def addParametersAvant(self):
233 item= self.tree.currentItem()
234 item.addParameters(False)
236 def addCommApres(self):
237 item= self.tree.currentItem()
238 item.addComment(True)
240 def addCommAvant(self):
241 item= self.tree.currentItem()
242 item.addComment(False)
244 #--------------------------------------------#
245 class PopUpMenuNodePartiel (PopUpMenuNodeMinimal):
246 #---------------------------------------------#
247 def createPopUpMenu(self):
248 PopUpMenuNodeMinimal.createPopUpMenu(self)
250 self.commentMenu=self.menu.addMenu(tr('Commentaire'))
251 self.commentMenu.addAction(self.CommApres)
252 self.commentMenu.addAction(self.CommAvant)
254 self.paramMenu =self.menu.addMenu(tr('Parametre'))
255 self.paramMenu.addAction(self.ParamApres)
256 self.paramMenu.addAction(self.ParamAvant)
257 self.menu.addAction(self.Documentation)
258 self.menu.removeAction(self.Supprime)
259 self.menu.addAction(self.Supprime)
262 #-----------------------------------------#
263 class PopUpMenuNode(PopUpMenuNodePartiel) :
264 #-----------------------------------------#
265 def createPopUpMenu(self):
266 PopUpMenuNodePartiel.createPopUpMenu(self)
267 self.Commente = QAction(tr('ce noeud'),self.tree)
268 self.Commente.triggered.connect(self.Commenter)
269 self.Commente.setStatusTip(tr("commente le noeud "))
270 self.commentMenu.addAction(self.Commente)
271 self.menu.removeAction(self.Supprime)
272 self.menu.addAction(self.Supprime)
275 item= self.tree.currentItem()