1 # Copyright (C) 2007-2013 EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 from __future__ import absolute_import
23 from __future__ import print_function
24 from PyQt5.QtWidgets import QWidget
25 from PyQt5.QtCore import Qt
27 from Extensions.i18n import tr
29 from .gereIcones import FacultatifOuOptionnel
35 class Groupe(QWidget,FacultatifOuOptionnel):
38 def __init__(self,node,editor,parentQt,definition,obj,niveau,commande=None):
39 QWidget.__init__(self,None)
41 self.node.fenetre=self
42 #print "groupe : ",self.node.item.nom," ",self.node.fenetre
47 self.definition=definition
48 self.parentQt=parentQt
49 self.maCommande=commande
51 self.appliEficas=self.editor.appliEficas
52 self.repIcon=self.appliEficas.repIcon
53 self.jdc=self.node.item.get_jdc()
54 self.setIconePoubelle()
55 self.setIconesGenerales()
58 self.setReglesEtAide()
60 self.listeMCAAjouter=[]
61 self.dictMCVenantDesBlocs={}
62 if hasattr(self,'RBDeplie') : self.RBDeplie.clicked.connect(self.Deplie)
63 if hasattr(self,'RBPlie') : self.RBPlie.clicked.connect( self.Plie)
64 self.setAcceptDrops(True)
67 for fenetre in self.listeFocus:
68 if fenetre==None : return
69 if fenetre.node.item.isvalid() == 0 :
70 fenetre.prendLeFocus=1
75 def afficheMots(self):
76 #print "ds afficheMots ",self.node.item.nom
77 for node in self.node.children:
78 #if node.item.nom == "Background" :print "afficheMots ",node," " ,node.item.nom, " ",node.plie ," ", node.appartientAUnNoeudPlie,node.getPanelGroupe
79 #if node.item.nom == "BackgroundError" :print "afficheMots ",node," " ,node.item.nom, " ",node.plie ," ", node.appartientAUnNoeudPlie,node.getPanelGroupe
80 # non return mais continue car il faut tenir compte des blocs
81 if node.appartientAUnNoeudPlie==True : continue
82 #print "je suis apres le if pour ",node.item.nom
83 widget=node.getPanelGroupe(self,self.maCommande)
84 #print "widget pour ", node.item.nom, widget
85 self.listeFocus.append(node.fenetre)
86 #print "fin pour " , self.node.item.nom
89 def calculOptionnel(self):
91 genea =self.obj.get_genealogie()
92 # Attention : les mots clefs listes (+sieurs fact )
93 # n ont pas toutes ces methodes
95 self.liste_mc=self.obj.get_liste_mc_ordonnee(genea,self.jdc.cata_ordonne_dico)
99 def afficheOptionnel(self):
100 liste=self.ajouteMCOptionnelDesBlocs()
101 self.monOptionnel=self.editor.widgetOptionnel
102 self.monOptionnel.afficheOptionnel(liste,self)
103 #self.monOptionnel.affiche(liste)
106 def ajouteMCOptionnelDesBlocs(self):
107 #print "Je passe dans ajouteMCOptionnelDesBlocs pour", self.node.item.nom
108 self.dictMCVenantDesBlocs={}
110 self.calculOptionnel()
112 for MC in self.liste_mc : self.dictMCVenantDesBlocs[MC]=self
113 while i < self.commandesLayout.count():
114 from .monWidgetBloc import MonWidgetBloc
115 widget=self.commandesLayout.itemAt(i).widget()
117 if not(isinstance(widget,MonWidgetBloc)) : continue
118 widget.calculOptionnel()
119 listeW=widget.ajouteMCOptionnelDesBlocs()
120 for MC in widget.dictMCVenantDesBlocs:
121 if MC in self.dictMCVenantDesBlocs: print ("Pb Sur les MC" )
122 else : self.dictMCVenantDesBlocs[MC]=widget.dictMCVenantDesBlocs[MC]
127 def reaffiche(self,nodeAVoir=None):
128 #print "dans reaffiche de groupe.py", nodeAVoir
129 self.parentQt.reaffiche(nodeAVoir)
131 def recalculeListeMC(self,listeMC):
132 #print "pas si peu utile"
133 #on ajoute et on enleve
135 for name in listeMC :
136 nodeAEnlever=self.node.append_child(name)
137 if nodeAEnlever.item.isMCList():
138 nodeAEnlever=nodeAEnlever.children[-1]
139 listeNode.append(nodeAEnlever)
140 self.afficheOptionnel()
141 self.monOptionnel.affiche(self.liste_mc)
142 if len(listeNode) == 0 : return
143 if len(listeNode) == 1 :
144 listeNode[0].delete()
145 self.editor.affiche_infos("")
147 for noeud in listeNode:
148 noeud.treeParent.item.suppitem(noeud.item)
149 noeud.treeParent.build_children()
150 self.editor.affiche_infos("")
152 def ajoutMC(self,texteListeNom):
153 listeNom=texteListeNom.split("+")[1:]
156 if nom not in self.dictMCVenantDesBlocs:
157 #print "bizarre, bizarre"
158 self.editor.init_modif()
159 nouveau=self.node.append_child(nom)
161 self.editor.init_modif()
162 widget=self.dictMCVenantDesBlocs[nom]
163 nouveau=widget.node.append_child(nom)
164 if firstNode==None : firstNode=nouveau
165 if nouveau == None or nouveau == 0 :
166 self.editor.affiche_infos(tr('insertion impossible a cet endroit pour '+nom),Qt.red)
167 self.reaffiche(firstNode)
168 if firstNode!=None and firstNode !=0 and firstNode.item!=None :
174 self.reaffiche(self.node)
177 self.node.setDeplie()
178 self.reaffiche(self.node)
180 def traiteClicSurLabel(self,texte):
181 if self.editor.code != "CARMELCND" : self.afficheOptionnel()