1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021 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
30 #---------------------------#
31 class PopUpMenuRacine(object) :
32 #---------------------------#
34 def createPopUpMenu(self):
35 #print "createPopUpMenu"
36 self.ParamApres = QAction(tr('Parametre'),self.tree)
37 self.ParamApres.triggered.connect(self.addParametersApres)
38 self.ParamApres.setStatusTip(tr("Insere un parametre"))
39 self.menu = QMenu(self.tree)
40 self.menu.addAction(self.ParamApres)
41 self.menu.setStyleSheet("background:rgb(220,220,220); ")
44 def addParametersApres(self):
45 item= self.tree.currentItem()
46 item.addParameters(True)
48 #---------------------------#
49 class PopUpMenuNodeMinimal(object) :
50 #---------------------------#
52 def createPopUpMenu(self):
53 #print ("createPopUpMenu")
54 #self.appliEficas.salome=True
56 self.menu = QMenu(self.tree)
57 #self.menu.setStyleSheet("background:rgb(235,235,235); QMenu::item:selected { background-color: red; }")
58 #ne fonctionne pas --> la ligne de commentaire devient rouge
59 self.menu.setStyleSheet("background:rgb(220,220,220); ")
61 self.menu.addAction(self.Supprime)
62 if hasattr(self.appliEficas, 'mesScripts'):
63 if self.editor.code in self.editor.appliEficas.mesScripts :
64 self.dict_commandes_mesScripts=self.appliEficas.mesScripts[self.editor.code].dict_commandes
65 if self.tree.currentItem().item.getNom() in self.dict_commandes_mesScripts :
68 def ajoutScript(self):
69 # cochon mais je n arrive pas a faire mieux avec le mecanisme de plugin
70 # a revoir avec un menu et un connect sur le triggered sur le menu ?
71 if hasattr(self.appliEficas, 'mesScripts'):
72 if self.editor.code in self.editor.appliEficas.mesScripts :
73 self.dict_commandes_mesScripts=self.appliEficas.mesScripts[self.editor.code].dict_commandes
76 from Extensions import jdc_include
77 if isinstance(self.item.jdc,jdc_include.JDC_INCLUDE) : return
79 listeCommandes=self.dict_commandes_mesScripts[self.tree.currentItem().item.getNom()]
80 if type(listeCommandes) != tuple: listeCommandes=(listeCommandes,)
82 for commande in listeCommandes :
83 conditionSalome=commande[3]
84 if (self.appliEficas.salome == 0 and conditionSalome == True): return
87 self.action=QAction(label,self.tree)
88 self.action.setStatusTip(tip)
89 if numero==4: self.action.triggered.connect(self.appelleFonction4)
90 if numero==3: self.action.triggered.connect(self.appelleFonction3); numero=4
91 if numero==2: self.action.triggered.connect(self.appelleFonction2); numero=3
92 if numero==1: self.action.triggered.connect(self.appelleFonction1); numero=2
93 if numero==0: self.action.triggered.connect(self.appelleFonction0); numero=1
94 self.menu.addAction(self.action)
97 def appelleFonction0(self):
98 self.appelleFonction(0)
100 def appelleFonction1(self):
101 self.appelleFonction(1)
103 def appelleFonction2(self):
104 self.appelleFonction(2)
106 def appelleFonction3(self):
107 self.appelleFonction(3)
109 def appelleFonction4(self):
110 self.appelleFonction(4)
112 def appelleFonction(self,numero,nodeTraite=None):
113 if nodeTraite==None : nodeTraite=self.tree.currentItem()
114 nomCmd=nodeTraite.item.getNom()
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]
124 if (nodeTraite.item.isValid() == 0 and conditionValid == True):
125 QMessageBox.warning( None,
127 tr("l item doit etre valide"),)
130 listenomparam=commande[2]
132 for p in listenomparam:
133 if hasattr(nodeTraite,p):
134 listeparam.append(getattr(nodeTraite,p))
135 if p=="self" : listeparam.append(self)
138 res, commentaire= fonction(listeparam)
140 QMessageBox.warning( None,
141 tr("echec de la fonction"),
150 def createActions(self):
151 self.CommApres = QAction(tr('apres'),self.tree)
152 self.CommApres.triggered.connect(self.addCommApres)
153 self.CommApres.setStatusTip(tr("Insere un commentaire apres la commande "))
154 self.CommAvant = QAction(tr('avant'),self.tree)
155 self.CommAvant.triggered.connect(self.addCommAvant)
156 self.CommAvant.setStatusTip(tr("Insere un commentaire avant la commande "))
158 self.ParamApres = QAction(tr('apres'),self.tree)
159 self.ParamApres.triggered.connect(self.addParametersApres)
160 self.ParamApres.setStatusTip(tr("Insere un parametre apres la commande "))
161 self.ParamAvant = QAction(tr('avant'),self.tree)
162 self.ParamAvant.triggered.connect(self.addParametersAvant)
163 self.ParamAvant.setStatusTip(tr("Insere un parametre avant la commande "))
165 self.Supprime = QAction(tr('Supprimer'),self.tree)
166 self.Supprime.triggered.connect(self.supprimeNoeud)
167 self.Supprime.setStatusTip(tr("supprime le mot clef "))
168 self.Documentation = QAction(tr('Documentation'),self.tree)
169 self.Documentation.triggered.connect(self.viewDoc)
170 self.Documentation.setStatusTip(tr("documentation sur la commande "))
172 def supprimeNoeud(self):
173 item= self.tree.currentItem()
177 self.node=self.tree.currentItem()
178 cle_doc = self.node.item.getDocu()
180 QMessageBox.information( self.editor,tr( "Documentation Vide"), \
181 tr("Aucune documentation n'est associee a ce noeud"))
183 commande = self.editor.appliEficas.maConfiguration.exec_acrobat
185 f=open(commande,"rb")
187 texte=tr("impossible de trouver la commande ") + commande
188 QMessageBox.information( self.editor, tr("Lecteur PDF"), texte)
191 if cle_doc.startswith('http:'):
194 fichier = os.path.abspath(os.path.join(self.editor.maConfiguration.path_doc,
199 texte=tr("impossible d'ouvrir ") + fichier
200 QMessageBox.information( self.editor, tr("Documentation Vide"), texte)
205 os.spawnv(os.P_NOWAIT,commande,(commande,fichier,))
206 elif os.name == 'posix':
207 script ="#!/usr/bin/sh \n%s %s&" %(commande,fichier)
208 pid = os.system(script)
210 def addParametersApres(self):
211 item= self.tree.currentItem()
212 item.addParameters(True)
214 def addParametersAvant(self):
215 item= self.tree.currentItem()
216 item.addParameters(False)
218 def addCommApres(self):
219 item= self.tree.currentItem()
220 item.addComment(True)
222 def addCommAvant(self):
223 item= self.tree.currentItem()
224 item.addComment(False)
226 def deplieCeNiveau(self):
227 item= self.tree.currentItem()
228 item.deplieCeNiveau()
230 #--------------------------------------------#
231 class PopUpMenuNodePartiel (PopUpMenuNodeMinimal):
232 #---------------------------------------------#
233 def createPopUpMenu(self):
234 PopUpMenuNodeMinimal.createPopUpMenu(self)
236 self.commentMenu=self.menu.addMenu(tr('Commentaire'))
237 self.commentMenu.addAction(self.CommApres)
238 self.commentMenu.addAction(self.CommAvant)
240 self.paramMenu =self.menu.addMenu(tr('Parametre'))
241 self.paramMenu.addAction(self.ParamApres)
242 self.paramMenu.addAction(self.ParamAvant)
243 self.menu.addAction(self.Documentation)
244 self.menu.removeAction(self.Supprime)
245 self.menu.addAction(self.Supprime)
248 #-----------------------------------------#
249 class PopUpMenuNode(PopUpMenuNodePartiel) :
250 #-----------------------------------------#
251 def createPopUpMenu(self):
252 PopUpMenuNodePartiel.createPopUpMenu(self)
253 self.Commente = QAction(tr('ce noeud'),self.tree)
254 self.Commente.triggered.connect(self.commenter)
255 self.Commente.setStatusTip(tr("commente le noeud "))
256 self.commentMenu.addAction(self.Commente)
257 self.menu.removeAction(self.Supprime)
258 self.menu.addAction(self.Supprime)
261 item= self.tree.currentItem()