Salome HOME
mse a jour du 07/03/2016 pour sauvegarde
[tools/eficas.git] / InterfaceQT4 / compocomm.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import string
22
23 from determine import monEnvQT5
24 if monEnvQT5 :
25   from PyQt5.QtWidgets import QAction
26 else :
27   from PyQt4.QtGui import *
28   from PyQt4.QtCore import *
29
30 from Editeur     import Objecttreeitem
31 import browser
32 import typeNode
33 from Extensions.i18n import tr
34 from Extensions.eficas_exception import EficasException
35
36
37 class Node(browser.JDCNode,typeNode.PopUpMenuNodePartiel):
38     def getPanel( self ):
39         """
40         """
41         from monWidgetCommentaire import MonWidgetCommentaire
42         return MonWidgetCommentaire(self,self.editor,self.item.object)
43
44     def createPopUpMenu(self):
45         typeNode.PopUpMenuNodePartiel.createPopUpMenu(self)
46         self.Decommente = QAction(tr("Decommenter"),self.tree)
47         if monEnvQT5 : self.tree.connect(self.Decommente,SIGNAL("triggered()"),self.Decommenter)
48         else : self.Decommente.triggered(self.Decommenter)
49         self.Decommente.setStatusTip(tr("Decommente la commande "))
50
51         if hasattr(self.item,'uncomment'):
52            self.menu.addAction(self.Decommente)
53
54     def Decommenter(self) :
55         item= self.tree.currentItem()
56         item.unCommentIt()
57
58     def update_node_label(self) :
59         """
60         """
61         debComm=self.item.GetText()
62         self.setText(1,debComm)
63
64
65     
66 class COMMTreeItem(Objecttreeitem.ObjectTreeItem):
67     itemNode=Node    
68
69     def init(self):
70       self.setfunction = self.set_valeur
71
72     def GetIconName(self):
73       """
74       Retourne le nom de l'icône associée au noeud qui porte self,
75       dépendant de la validité de l'objet
76       NB : un commentaire est toujours valide ...
77       """
78       return "ast-white-percent"
79
80     def GetLabelText(self):
81         """ Retourne 3 valeurs :
82         - le texte à afficher dans le noeud représentant l'item
83         - la fonte dans laquelle afficher ce texte
84         - la couleur du texte
85         """
86         return tr('Commentaire'),None,None
87
88     def get_valeur(self):
89       """
90       Retourne la valeur de l'objet Commentaire cad son texte
91       """
92       return self.object.get_valeur() or ''
93     
94     def GetText(self):
95         texte = self.object.valeur
96         texte = string.split(texte,'\n')[0]
97         if len(texte) < 25 :
98             return texte
99         else :
100             return texte[0:24]
101
102     def set_valeur(self,valeur):
103       """
104       Afecte valeur à l'objet COMMENTAIRE
105       """
106       self.object.set_valeur(valeur)
107       
108     def GetSubList(self):
109       """
110       Retourne la liste des fils de self
111       """
112       return []
113
114
115     def get_objet_commentarise(self):
116        """
117            La méthode get_objet_commentarise() de la classe compocomm.COMMTreeItem
118            surcharge la méthode get_objet_commentarise de la classe Objecttreeitem.ObjectTreeItem
119            elle a pour but d'empecher l'utilisateur final de commentariser un commentaire.
120        """
121        raise EficasException( 'Impossible de commentariser un commentaire' )
122   
123 import Extensions
124 treeitem =COMMTreeItem
125 objet = Extensions.commentaire.COMMENTAIRE