Salome HOME
d9eb541daf6d6c853939ead4643ecabd8e15804a
[tools/eficas.git] / InterfaceQT4 / typeNode.py
1 # -*- coding: utf-8 -*-
2 from PyQt4 import *
3 from PyQt4.QtGui import *
4 from PyQt4.QtCore import *
5
6 #---------------------------#
7 class PopUpMenuNodeMinimal :
8 #---------------------------#
9     def createPopUpMenu(self):
10         self.createActions()
11         self.menu = QMenu(self.tree)
12         #items du menu
13         self.menu.addAction(self.Supprime)
14     
15     def createActions(self):
16         self.CommApres = QAction('après',self.tree)
17         self.tree.connect(self.CommApres,SIGNAL("activated()"),self.addCommApres)
18         self.CommApres.setStatusTip("Insere un commentaire apres la commande ")
19         self.CommAvant = QAction('avant',self.tree)
20         self.tree.connect(self.CommAvant,SIGNAL("activated()"),self.addCommAvant)
21         self.CommAvant.setStatusTip("Insere un commentaire avant la commande ")
22
23         self.ParamApres = QAction('après',self.tree)
24         self.tree.connect(self.ParamApres,SIGNAL("activated()"),self.addParametersApres)
25         self.ParamApres.setStatusTip("Insere un parametre apres la commande ")
26         self.ParamAvant = QAction('avant',self.tree)
27         self.tree.connect(self.ParamAvant,SIGNAL("activated()"),self.addParametersAvant)
28         self.ParamAvant.setStatusTip("Insere un parametre avant la commande ")
29
30         self.Supprime = QAction('Supprimer',self.tree)
31         self.tree.connect(self.Supprime,SIGNAL("activated()"),self.supprimeNoeud)
32         self.Supprime.setStatusTip("supprime le mot clef ")
33         self.Documentation = QAction('Documentation',self.tree)
34         self.tree.connect(self.Documentation,SIGNAL("activated()"),self.viewDoc)
35         self.Documentation.setStatusTip("documentation sur la commande ")
36
37     def supprimeNoeud(self):
38         item= self.tree.currentItem()
39         item.delete()
40
41     def viewDoc(self):
42         self.node=self.tree.currentItem()
43         cle_doc = self.node.item.get_docu()
44         if cle_doc == None :
45             QMessageBox.information( self.editor, "Documentation Vide", \
46                                     "Aucune documentation Aster n'est associée à ce noeud")
47             return
48         commande = self.editor.appliEficas.CONFIGURATION.exec_acrobat
49         try :
50             f=open(commande,"rb")
51         except :
52              texte="impossible de trouver la commande  " + commande
53              QMessageBox.information( self.editor, "Lecteur PDF", texte)
54              return
55         nom_fichier = cle_doc
56         import os
57         fichier = os.path.abspath(os.path.join(self.editor.CONFIGURATION.path_doc,
58                                        nom_fichier))
59         try :
60            f=open(fichier,"rb")
61         except :
62            texte="impossible d'ouvrir " + fichier
63            QMessageBox.information( self.editor, "Documentation Vide", texte)
64            return
65         if os.name == 'nt':
66            os.spawnv(os.P_NOWAIT,commande,(commande,fichier,))
67         elif os.name == 'posix':
68             script ="#!/usr/bin/sh \n%s %s&" %(commande,fichier)
69             pid = os.system(script)
70
71     def addParametersApres(self):
72         item= self.tree.currentItem()
73         item.addParameters(True)
74
75     def addParametersAvant(self):
76         item= self.tree.currentItem()
77         item.addParameters(False)
78
79     def addCommApres(self):
80         item= self.tree.currentItem()
81         item.addComment(True)
82
83     def addCommAvant(self):
84         item= self.tree.currentItem()
85         item.addComment(False)
86
87 #--------------------------------------------#
88 class PopUpMenuNodePartiel (PopUpMenuNodeMinimal):
89 #---------------------------------------------#
90     def createPopUpMenu(self):
91         PopUpMenuNodeMinimal.createPopUpMenu(self)
92         #ss-menu Comment:
93         self.commentMenu=self.menu.addMenu('Commentaire')
94         self.commentMenu.addAction(self.CommApres)
95         self.commentMenu.addAction(self.CommAvant)
96         #ss-menu Parameters:
97         self.paramMenu =self.menu.addMenu('Parametre') 
98         self.paramMenu.addAction(self.ParamApres)
99         self.paramMenu.addAction(self.ParamAvant)
100         self.menu.addAction(self.Documentation)
101         self.menu.removeAction(self.Supprime)
102         self.menu.addAction(self.Supprime)
103
104
105 #-----------------------------------------#
106 class PopUpMenuNode(PopUpMenuNodePartiel) :
107 #-----------------------------------------#
108     def createPopUpMenu(self):
109         PopUpMenuNodePartiel.createPopUpMenu(self)
110         self.Commente = QAction('ce noeud',self.tree)
111         self.tree.connect(self.Commente,SIGNAL("activated()"),self.Commenter)
112         self.Commente.setStatusTip("commente le noeud ")
113         self.commentMenu.addAction(self.Commente)
114         self.menu.removeAction(self.Supprime)
115         self.menu.addAction(self.Supprime)
116
117     def Commenter(self):
118         item= self.tree.currentItem()
119         item.commentIt()