Salome HOME
bug sur un mesage dans une exception sur un validator (cf JPA)
[tools/eficas.git] / InterfaceQT4 / compocomm.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021   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 from __future__ import absolute_import
22
23
24 from Editeur     import Objecttreeitem
25 from . import browser
26 from . import typeNode
27 from Extensions.i18n import tr
28 from Extensions.eficas_exception import EficasException
29
30
31 class Node(browser.JDCNode,typeNode.PopUpMenuNodePartiel):
32     def getPanel( self ):
33         """
34         """
35         from .monWidgetCommentaire import MonWidgetCommentaire
36         return MonWidgetCommentaire(self,self.editor,self.item.object)
37
38     def createPopUpMenu(self):
39         typeNode.PopUpMenuNodePartiel.createPopUpMenu(self)
40         from PyQt5.QtWidgets import QAction
41         self.Decommente = QAction(tr("decommenter"),self.tree)
42         self.Decommente.triggered.connect(self.decommenter)
43         self.Decommente.setStatusTip(tr("Decommente la commande "))
44
45         if hasattr(self.item,'unComment'):
46             self.menu.addAction(self.Decommente)
47
48     def decommenter(self) :
49         item= self.tree.currentItem()
50         item.unCommentIt()
51
52     def updateNodeLabel(self) :
53         """
54         """
55         debComm=self.item.getText()
56         self.setText(1,tr(debComm))
57
58
59 class COMMTreeItem(Objecttreeitem.ObjectTreeItem):
60     itemNode=Node
61
62     def init(self):
63         self.setFunction = self.setValeur
64
65     def getIconName(self):
66         """
67         Retourne le nom de l'icone associee au noeud qui porte self,
68         dependant de la validite de l'objet
69         NB : un commentaire est toujours valide ...
70         """
71         return "ast-white-percent"
72
73     def getLabelText(self):
74         """ Retourne 3 valeurs :
75         - le texte a afficher dans le noeud representant l'item
76         - la fonte dans laquelle afficher ce texte
77         - la couleur du texte
78         """
79         return tr('Commentaire'),None,None
80
81     def getValeur(self):
82         """
83         Retourne la valeur de l'objet Commentaire cad son texte
84         """
85         return self.object.getValeur() or ''
86
87     def getText(self):
88         texte = self.object.valeur
89         texte = texte.split('\n')[0]
90         if len(texte) < 25 :
91             return texte
92         else :
93             return texte[0:24]
94
95     def setValeur(self,valeur):
96         """
97         Affecte valeur a l'objet COMMENTAIRE
98         """
99         self.object.setValeur(valeur)
100
101     def getSubList(self):
102         """
103         Retourne la liste des fils de self
104         """
105         return []
106
107
108     def getObjetCommentarise(self):
109         """
110             La methode getObjetCommentarise() de la classe compocomm.COMMTreeItem
111             surcharge la methode getObjetCommentarise de la classe Objecttreeitem.ObjectTreeItem
112             elle a pour but d'empecher l'utilisateur final de commentariser un commentaire.
113         """
114         raise EficasException( 'Impossible de commentariser un commentaire' )
115
116 import Extensions
117 treeitem =COMMTreeItem
118 objet = Extensions.commentaire.COMMENTAIRE