Salome HOME
bug
[tools/eficas.git] / InterfaceQT4 / compocommandecomm.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017   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 from __future__ import absolute_import
21 import traceback
22
23 from Editeur import Objecttreeitem
24 from Extensions.eficas_exception import EficasException
25 from . import compocomm
26
27 class COMMANDE_COMMTreeItem(Objecttreeitem.ObjectTreeItem):
28     itemNode=compocomm.Node
29
30     def init(self):
31       self.setFunction = self.setValeur
32
33     def getIconName(self):
34       """
35       Retourne le nom de l'icone associee au noeud qui porte self,
36       dependant de la validite de l'objet
37       NB : une commande commentarisee est toujours valide ...
38       """
39       if self.isValid():
40           return "ast-green-percent"
41       else:
42           return "ast-red-percent"
43
44     def getLabelText(self):
45         """ Retourne 3 valeurs :
46         - le texte a afficher dans le noeud representant l'item
47         - la fonte dans laquelle afficher ce texte
48         - la couleur du texte
49         """
50         return 'commentaire'
51
52     def getValeur(self):
53       """
54       Retourne la valeur de la commande commentarisee cad son texte
55       """
56       return self.object.getValeur() or ''
57     
58     def getText(self):
59         texte = self.object.valeur
60         texte = texte.split('\n')[0]
61         if len(texte) < 25 :
62             return texte
63         else :
64             return texte[0:24]
65
66     def setValeur(self,valeur):
67       """
68       Afefcte valeur a l'objet commande commentarisee
69       """
70       self.object.setValeur(valeur)
71       
72     def getSubList(self):
73       """
74       Retourne la liste des fils de self
75       """
76       return []
77
78     def unComment(self):
79       """
80       Demande a l'objet commande commentarisee de se decommentariser.
81       Si l'operation s'effectue correctement, retourne l'objet commande
82       et eventuellement le nom de la sd produite, sinon leve une exception
83       """
84       try:
85         commande,nom = self.object.unComment()
86         #self.parent.children[pos].select()
87       except Exception as e:
88         traceback.print_exc()
89         raise EficasException(e)
90       return commande,nom
91   
92 import Accas
93 treeitem =COMMANDE_COMMTreeItem
94 objet = Accas.COMMANDE_COMM