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 determine import monEnvQT5
22 from PyQt5.QtWidgets import QAction, QMenu, QMessageBox
24 from PyQt4.QtGui import *
25 from PyQt4.QtCore import *
27 from Extensions.i18n import tr
32 #---------------------------#
33 class PopUpMenuRacine :
34 #---------------------------#
37 def createPopUpMenu(self):
38 #print "createPopUpMenu"
39 self.ParamApres = QAction(tr('Parametre'),self.tree)
41 self.ParamApres.triggered.connect(self.addParametersApres)
43 self.tree.connect(self.ParamApres,SIGNAL("triggered()"),self.addParametersApres)
44 self.ParamApres.setStatusTip(tr("Insere un parametre"))
45 self.menu = QMenu(self.tree)
46 self.menu.addAction(self.ParamApres)
47 self.menu.setStyleSheet("background:rgb(220,220,220); ")
50 def addParametersApres(self):
51 item= self.tree.currentItem()
52 item.addParameters(True)
54 #---------------------------#
55 class PopUpMenuNodeMinimal :
56 #---------------------------#
58 def createPopUpMenu(self):
59 #print "createPopUpMenu"
60 #self.appliEficas.salome=True
61 if monEnvQT5 : self.createActions()
62 else : self.createActionsQT4()
63 self.menu = QMenu(self.tree)
64 #self.menu.setStyleSheet("background:rgb(235,235,235); QMenu::item:selected { background-color: red; }")
65 #ne fonctionne pas --> la ligne de commentaire devient rouge
66 self.menu.setStyleSheet("background:rgb(220,220,220); ")
68 self.menu.addAction(self.Supprime)
69 if hasattr(self.appliEficas, 'mesScripts'):
70 if self.editor.code in self.editor.appliEficas.mesScripts.keys() :
71 self.dict_commandes_mesScripts=self.appliEficas.mesScripts[self.editor.code].dict_commandes
72 if self.tree.currentItem().item.get_nom() in self.dict_commandes_mesScripts.keys() :
75 def ajoutScript(self):
77 # cochon mais je n arrive pas a faire mieux avec le mecanisme de plugin
78 if hasattr(self.appliEficas, 'mesScripts'):
79 if self.editor.code in self.editor.appliEficas.mesScripts.keys() :
80 self.dict_commandes_mesScripts=self.appliEficas.mesScripts[self.editor.code].dict_commandes
82 listeCommandes=self.dict_commandes_mesScripts[self.tree.currentItem().item.get_nom()]
83 if type(listeCommandes) != types.TupleType: 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)
94 self.action.triggered.connect(self.AppelleFonction4)
96 self.action.triggered.connect(self.AppelleFonction3)
99 self.action.triggered.connect(self.AppelleFonction2)
102 self.action.triggered.connect(self.AppelleFonction1)
105 self.action.triggered.connect(self.AppelleFonction0)
109 self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction4)
111 self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction3)
114 self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction2)
117 self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction1)
120 self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction0)
122 self.menu.addAction(self.action)
125 def AppelleFonction0(self):
126 self.AppelleFonction(0)
128 def AppelleFonction1(self):
129 self.AppelleFonction(1)
131 def AppelleFonction2(self):
132 self.AppelleFonction(2)
134 def AppelleFonction3(self):
135 self.AppelleFonction(3)
137 def AppelleFonction4(self):
138 self.AppelleFonction(4)
141 def AppelleFonction(self,numero,nodeTraite=None):
142 #print "AppelleFonction", self,numero,nodeTraite
143 if nodeTraite==None : nodeTraite=self.tree.currentItem()
144 nomCmd=nodeTraite.item.get_nom()
145 if hasattr(self.appliEficas, 'mesScripts'):
146 if self.editor.code in self.editor.appliEficas.mesScripts.keys() :
147 self.dict_commandes_mesScripts=self.appliEficas.mesScripts[self.editor.code].dict_commandes
149 listeCommandes=self.dict_commandes_mesScripts[nomCmd]
150 commande=listeCommandes[numero]
151 conditionValid=commande[4]
152 if (nodeTraite.item.isvalid() == 0 and conditionValid == True):
153 QMessageBox.warning( None,
155 tr("l item doit etre valide"),)
158 listenomparam=commande[2]
160 for p in listenomparam:
161 if hasattr(nodeTraite,p):
162 listeparam.append(getattr(nodeTraite,p))
163 if p=="self" : listeparam.append(self)
166 res, commentaire= fonction(listeparam)
168 QMessageBox.warning( None,
169 tr("echec de la fonction"),
177 def createActionsQT4(self):
178 self.CommApres = QAction(tr('apres'),self.tree)
179 self.tree.connect(self.CommApres,SIGNAL("triggered()"),self.addCommApres)
180 self.CommApres.setStatusTip(tr("Insere un commentaire apres la commande "))
181 self.CommAvant = QAction(tr('avant'),self.tree)
182 self.tree.connect(self.CommAvant,SIGNAL("triggered()"),self.addCommAvant)
183 self.CommAvant.setStatusTip(tr("Insere un commentaire avant la commande "))
185 self.ParamApres = QAction(tr('apres'),self.tree)
186 self.tree.connect(self.ParamApres,SIGNAL("triggered()"),self.addParametersApres)
187 self.ParamApres.setStatusTip(tr("Insere un parametre apres la commande "))
188 self.ParamAvant = QAction(tr('avant'),self.tree)
189 self.tree.connect(self.ParamAvant,SIGNAL("triggered()"),self.addParametersAvant)
190 self.ParamAvant.setStatusTip(tr("Insere un parametre avant la commande "))
192 self.Supprime = QAction(tr('Supprimer'),self.tree)
193 self.tree.connect(self.Supprime,SIGNAL("triggered()"),self.supprimeNoeud)
194 self.Supprime.setStatusTip(tr("supprime le mot clef "))
195 self.Documentation = QAction(tr('Documentation'),self.tree)
196 self.tree.connect(self.Documentation,SIGNAL("triggered()"),self.viewDoc)
198 def createActions(self):
199 self.CommApres = QAction(tr('apres'),self.tree)
200 self.CommApres.triggered.connect(self.addCommApres)
201 self.CommApres.setStatusTip(tr("Insere un commentaire apres la commande "))
202 self.CommAvant = QAction(tr('avant'),self.tree)
203 self.CommAvant.triggered.connect(self.addCommAvant)
204 self.CommAvant.setStatusTip(tr("Insere un commentaire avant la commande "))
206 self.ParamApres = QAction(tr('apres'),self.tree)
207 self.ParamApres.triggered.connect(self.addParametersApres)
208 self.ParamApres.setStatusTip(tr("Insere un parametre apres la commande "))
209 self.ParamAvant = QAction(tr('avant'),self.tree)
210 self.ParamAvant.triggered.connect(self.addParametersAvant)
211 self.ParamAvant.setStatusTip(tr("Insere un parametre avant la commande "))
213 self.Supprime = QAction(tr('Supprimer'),self.tree)
214 self.Supprime.triggered.connect(self.supprimeNoeud)
215 self.Supprime.setStatusTip(tr("supprime le mot clef "))
216 self.Documentation = QAction(tr('Documentation'),self.tree)
217 self.Documentation.triggered.connect(self.viewDoc)
218 self.Documentation.setStatusTip(tr("documentation sur la commande "))
220 def supprimeNoeud(self):
221 item= self.tree.currentItem()
225 self.node=self.tree.currentItem()
226 cle_doc = self.node.item.get_docu()
228 QMessageBox.information( self.editor,tr( "Documentation Vide"), \
229 tr("Aucune documentation n'est associee a ce noeud"))
231 commande = self.editor.appliEficas.CONFIGURATION.exec_acrobat
233 f=open(commande,"rb")
235 texte=tr("impossible de trouver la commande ") + commande
236 QMessageBox.information( self.editor, tr("Lecteur PDF"), texte)
239 if cle_doc.startswith('http:'):
242 fichier = os.path.abspath(os.path.join(self.editor.CONFIGURATION.path_doc,
247 texte=tr("impossible d'ouvrir ") + fichier
248 QMessageBox.information( self.editor, tr("Documentation Vide"), texte)
253 os.spawnv(os.P_NOWAIT,commande,(commande,fichier,))
254 elif os.name == 'posix':
255 script ="#!/usr/bin/sh \n%s %s&" %(commande,fichier)
256 pid = os.system(script)
258 def addParametersApres(self):
259 item= self.tree.currentItem()
260 item.addParameters(True)
262 def addParametersAvant(self):
263 item= self.tree.currentItem()
264 item.addParameters(False)
266 def addCommApres(self):
267 item= self.tree.currentItem()
268 item.addComment(True)
270 def addCommAvant(self):
271 item= self.tree.currentItem()
272 item.addComment(False)
274 #--------------------------------------------#
275 class PopUpMenuNodePartiel (PopUpMenuNodeMinimal):
276 #---------------------------------------------#
277 def createPopUpMenu(self):
278 PopUpMenuNodeMinimal.createPopUpMenu(self)
280 self.commentMenu=self.menu.addMenu(tr('Commentaire'))
281 self.commentMenu.addAction(self.CommApres)
282 self.commentMenu.addAction(self.CommAvant)
284 self.paramMenu =self.menu.addMenu(tr('Parametre'))
285 self.paramMenu.addAction(self.ParamApres)
286 self.paramMenu.addAction(self.ParamAvant)
287 self.menu.addAction(self.Documentation)
288 self.menu.removeAction(self.Supprime)
289 self.menu.addAction(self.Supprime)
292 #-----------------------------------------#
293 class PopUpMenuNode(PopUpMenuNodePartiel) :
294 #-----------------------------------------#
295 def createPopUpMenu(self):
296 PopUpMenuNodePartiel.createPopUpMenu(self)
297 self.Commente = QAction(tr('ce noeud'),self.tree)
298 self.Commente.triggered.connect(self.Commenter)
299 self.Commente.setStatusTip(tr("commente le noeud "))
300 self.commentMenu.addAction(self.Commente)
301 self.menu.removeAction(self.Supprime)
302 self.menu.addAction(self.Supprime)
305 item= self.tree.currentItem()