Salome HOME
onItem=Deplie
[tools/eficas.git] / InterfaceQT4 / compofact.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 from PyQt4 import *
22 from PyQt4.QtGui  import *
23 from PyQt4.QtCore import *
24 import browser
25 import typeNode
26 from Extensions.i18n import tr
27
28
29 from Editeur import Objecttreeitem
30
31
32 class Node(browser.JDCNode,typeNode.PopUpMenuNodePartiel):
33
34     def getPanelGroupe(self,parentQt,commande):
35         maDefinition=self.item.get_definition()
36         monObjet=self.item.object
37         monNom=self.item.nom
38         maCommande=commande
39         if hasattr(parentQt,'niveau'): self.niveau=parentQt.niveau+1
40         else : self.niveau=1
41         if  hasattr(self,'plie') :print self.item.nom, self.plie
42         if  hasattr(self,'plie') and self.plie==True : 
43            from monWidgetFactPlie import MonWidgetFactPlie
44            widget=MonWidgetFactPlie(self,self.editor,parentQt,maDefinition,monObjet,self.niveau,maCommande)
45         else:
46            from monWidgetFact import MonWidgetFact
47            widget=MonWidgetFact(self,self.editor,parentQt,maDefinition,monObjet,self.niveau,maCommande)
48         return widget
49
50
51     def createPopUpMenu(self):
52         typeNode.PopUpMenuNodeMinimal.createPopUpMenu(self)
53
54
55 class FACTTreeItem(Objecttreeitem.ObjectTreeItem):
56   itemNode=Node
57   
58   def IsExpandable(self):
59     return 1
60
61   def GetText(self):
62       return  ''
63
64   def GetLabelText(self):
65       """ Retourne 3 valeurs :
66         - le texte à afficher dans le noeud representant l'item
67         - la fonte dans laquelle afficher ce texte
68         - la couleur du texte
69       """
70       # None --> fonte et couleur par defaut
71       return self.object.getlabeltext(),None,None
72
73   def isvalid(self):
74     return self.object.isvalid()
75
76   def iscopiable(self):
77     return 1
78
79   def GetIconName(self):
80     if self.object.isvalid():
81       return "ast-green-los"
82     elif self.object.isoblig():
83       return "ast-red-los"
84     else:
85       return "ast-yel-los"
86
87   def keys(self):
88     keys=self.object.mc_dict.keys()
89     return keys
90
91   def GetSubList(self):
92       """
93          Reactualise la liste des items fils stockes dans self.sublist
94       """
95       liste=self.object.mc_liste
96       sublist=[None]*len(liste)
97       # suppression des items lies aux objets disparus
98       for item in self.sublist:
99          old_obj=item.getObject()
100          if old_obj in liste:
101             pos=liste.index(old_obj)
102             sublist[pos]=item
103          else:
104             pass # objets supprimes ignores
105       # ajout des items lies aux nouveaux objets
106       pos=0
107       for obj in liste:
108          if sublist[pos] is None:
109             # nouvel objet : on cree un nouvel item
110             def setfunction(value, object=obj):
111                 object.setval(value)
112             item = self.make_objecttreeitem(self.appli, obj.nom + " : ", obj, setfunction)
113             sublist[pos]=item
114          pos=pos+1
115
116       self.sublist=sublist
117       return self.sublist
118
119   def additem(self,name,pos):
120     objet = self.object.addentite(name,pos)
121     return objet
122
123   def suppitem(self,item) :
124       """ 
125          Cette methode a pour fonction de supprimer l'item passee en argument
126          des fils de l'item FACT qui est son pere
127            - item = item du MOCLE a supprimer du MOCLE pere
128            - item.getObject() = MCSIMP ou MCBLOC 
129       """
130       itemobject=item.getObject()
131       if itemobject.isoblig() :
132          #self.editor.affiche_infos(tr('Impossible de supprimer un mot-cle obligatoire '),Qt.red)
133          return (0, tr('Impossible de supprimer un mot-cle obligatoire '))
134
135       if self.object.suppentite(itemobject):
136          message = tr("Mot-cle %s supprime")+ unicode(itemobject.nom)
137          #self.editor.affiche_commentaire(message)
138          return (1, message)
139       else:
140          #self.editor.affiche_infos(tr('Pb interne : impossible de supprimer ce mot-cle'),Qt.red)
141          return (0,tr('Pb interne : impossible de supprimer ce mot-cle'))
142
143 import Accas
144 objet = Accas.MCFACT
145 treeitem = FACTTreeItem