Salome HOME
*** empty log message ***
[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         #cle_doc = string.replace(cle_doc,'.','')
49         #cle_doc = string.replace(cle_doc,'-','')
50         #print dir(self)
51         commande = self.editor.appliEficas.CONFIGURATION.exec_acrobat
52         try :
53             f=open(commande,"rb")
54         except :
55              texte="impossible de trouver la commande  " + commande
56              QMessageBox.information( self.editor, "Lecteur PDF", texte)
57              return
58         nom_fichier = cle_doc+".pdf"
59         fichier = os.path.abspath(os.path.join(self.editor.CONFIGURATION.path_doc,
60                                        nom_fichier))
61         try :
62            f=open(fichier,"rb")
63         except :
64            texte="impossible d'ouvrir " + fichier
65            QMessageBox.information( self.editor, "Documentation Vide", texte)
66            return
67         if os.name == 'nt':
68            os.spawnv(os.P_NOWAIT,commande,(commande,fichier,))
69         elif os.name == 'posix':
70             script ="#!/usr/bin/sh \n%s %s&" %(commande,fichier)
71             pid = os.system(script)
72
73     def addParametersApres(self):
74         item= self.tree.currentItem()
75         item.addParameters(True)
76
77     def addParametersAvant(self):
78         item= self.tree.currentItem()
79         item.addParameters(False)
80
81     def addCommApres(self):
82         item= self.tree.currentItem()
83         item.addComment(True)
84
85     def addCommAvant(self):
86         item= self.tree.currentItem()
87         item.addComment(False)
88
89 #--------------------------------------------#
90 class PopUpMenuNodePartiel (PopUpMenuNodeMinimal):
91 #---------------------------------------------#
92     def createPopUpMenu(self):
93         PopUpMenuNodeMinimal.createPopUpMenu(self)
94         #ss-menu Comment:
95         self.commentMenu=self.menu.addMenu('Commentaire')
96         self.commentMenu.addAction(self.CommApres)
97         self.commentMenu.addAction(self.CommAvant)
98         #ss-menu Parameters:
99         self.paramMenu =self.menu.addMenu('Parametre') 
100         self.paramMenu.addAction(self.ParamApres)
101         self.paramMenu.addAction(self.ParamAvant)
102         self.menu.addAction(self.Documentation)
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
115     def Commenter(self):
116         item= self.tree.currentItem()
117         item.commentIt()