Salome HOME
Merge V9 dans Master
[tools/eficas.git] / InterfaceQT4 / monWidgetNiveauFact.py
1 # Copyright (C) 2007-2017   EDF R&D
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 # Modules Python
20 # Modules Eficas
21
22 from __future__ import absolute_import
23 try :
24    from builtins import str
25 except : pass
26
27 import types
28
29 from desWidgetNiveauFact import Ui_WidgetNiveauFact
30 from InterfaceQT4.monWidgetOptionnel import MonWidgetOptionnel
31 from InterfaceQT4.groupe import Groupe
32
33 from PyQt5.QtWidgets  import  QWidget
34 from PyQt5.QtGui  import  QIcon
35
36
37 from Extensions.i18n import tr
38 import Accas 
39 import os
40
41     
42 # Import des panels
43
44 class MonWidgetNiveauFact(Ui_WidgetNiveauFact,Groupe):
45   """
46   """
47   def __init__(self,node,editor,definition,obj):
48       self.listeAffichageWidget=[]
49       self.listeBoutonAChanger=[]
50       Groupe.__init__(self,node,editor,None,definition,obj,1,self)
51       from InterfaceQT4 import composimp
52       if isinstance(self.node ,composimp.Node):
53          widget=self.node.getPanelGroupe(self,self.maCommande)
54          self.listeBoutonAChanger.append(widget.RBValide)
55       self.afficheOptionnel()
56       self.inhibe=False
57       self.labelDoc.setText(self.node.item.getFr())
58       self.labelNomCommande.setText(self.node.item.getLabelText()[0])
59
60   def reaffiche(self,nodeAVoir=None):
61       self.node.setDeplieChildren()
62       self.node.afficheCeNiveau()
63       self.editor.fenetreCentraleAffichee.labelDoc.setText(self.node.item.getFr())
64       self.editor.fenetreCentraleAffichee.labelNomCommande.setText(self.node.item.getLabelText()[0])
65
66   def getPanel(self):
67   # necessaire pour handleOnItem de browser.py
68   # non appele
69       pass 
70
71   def donnePremier(self):
72       #print "dans donnePremier"
73       QApplication.processEvents()
74       if self.listeAffichageWidget != [] :
75          self.listeAffichageWidget[0].setFocus(7)
76       QApplication.processEvents()
77       #print self.focusWidget()
78
79
80   def focusNextPrevChild(self, next):
81       # on s assure que ce n est pas un chgt de fenetre
82       #print "je passe dans focusNextPrevChild"
83       if self.editor.fenetreCentraleAffichee != self : return True
84       f=self.focusWidget()
85
86       if f not in self.listeAffichageWidget :
87          i=0
88          while not hasattr (f,'AAfficher') :
89            if f==None :i=-1; break
90            f=f.parentWidget()
91          if hasattr(f,'AAfficher') : f=f.AAfficher
92          if i != -1 : i=self.listeAffichageWidget.index(f)
93       else :i=self.listeAffichageWidget.index(f) 
94       if (i==len(self.listeAffichageWidget) -1) and next and not self.inhibe: 
95          try :
96            self.listeAffichageWidget[1].setFocus(7)
97            w=self.focusWidget()
98            self.inhibe=1
99            w.focusPreviousChild()
100            self.inhibe=0
101            return True
102          except : pass
103
104       if i==0 and next==False and not self.inhibe: 
105          if hasattr(self.editor.fenetreCentraleAffichee,'scrollArea'):
106             self.editor.fenetreCentraleAffichee.scrollArea.ensureWidgetVisible(self.listeAffichageWidget[-1])
107          self.listeAffichageWidget[-2].setFocus(7)
108          self.inhibe=1
109          w=self.focusWidget()
110          w.focusNextChild()
111          self.inhibe=0
112          return True
113
114       if i==0 and next==True and not self.inhibe:
115          self.listeAffichageWidget[0].setFocus(7)
116          self.inhibe=1
117          w=self.focusWidget()
118          w.focusNextChild()
119          self.inhibe=0
120          return True
121
122       if i>0 and next==False and not self.inhibe:
123          if isinstance(self.listeAffichageWidget[i-1],QRadioButton):
124            self.listeAffichageWidget[i-1].setFocus(7)
125            return True
126       return QWidget.focusNextPrevChild(self, next)
127
128   def etablitOrdre(self):
129       # si on boucle on perd l'ordre
130       i=0
131       while(i +1 < len(self.listeAffichageWidget)):
132          self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
133          i=i+1
134
135   def  afficheSuivant(self,f):
136       #print ('ds afficheSuivant')
137       try :
138         i=self.listeAffichageWidget.index(f) 
139         next=i+1
140       except :
141         next=1
142       if (next==len(self.listeAffichageWidget) ): next =0
143       try :
144         self.listeAffichageWidget[next].setFocus(7)
145       except :
146         pass
147
148
149   def afficheOptionnel(self):
150       # N a pas de parentQt. doit donc etre redefini
151       #print ('ds afficheOptionnel')
152       if self.editor.widgetOptionnel!= None :
153         self.monOptionnel=self.editor.widgetOptionnel
154       else :
155         self.editor.inhibeSplitter=1
156         self.monOptionnel=MonWidgetOptionnel(self.editor)
157         self.editor.widgetOptionnel=self.monOptionnel
158         self.editor.splitter.addWidget(self.monOptionnel)
159         self.editor.ajoutOptionnel()
160         self.editor.inhibeSplitter=0
161       self.monOptionnel.vireTous()
162
163       
164       liste,liste_rouge=self.ajouteMCOptionnelDesBlocs()
165       self.monOptionnel.parentCommande=self
166       self.monOptionnel.titre(self.obj.nom)
167       self.monGroupe=self.monOptionnel.afficheOptionnel(liste,liste_rouge,self)
168       
169   def setValide(self):
170      Groupe.setValide(self)
171      for bouton in self.listeBoutonAChanger:
172          couleur=self.node.item.getIconName()
173          monIcone = QIcon(self.repIcon+"/" + couleur + ".png")
174          bouton.setIcon(monIcone)
175
176 class MonWidgetNiveauFactTableau(MonWidgetNiveauFact):
177   def __init__(self,node,editor,definition,obj):
178       MonWidgetNiveauFact.__init__(self,node,editor,definition,obj)
179
180