Salome HOME
legere difference ds VARIABLES_TO_BE...
[tools/eficas.git] / InterfaceQT4 / monGroupeOptionnel.py
1 # Copyright (C) 2007-2013   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 from PyQt5.QtWidgets import QCheckBox, QWidget, QLabel, QPushButton
24 from PyQt5.QtCore import Qt, QRect
25
26 from Extensions.i18n import tr
27 from desGroupeOptionnel import Ui_groupeOptionnel
28 from desPBOptionnelMT import Ui_customPB
29
30     
31 # Import des panels
32
33 class monRBButtonCustom(QCheckBox):
34
35    def __init__(self,texte,monOptionnel,parent=None):
36       QCheckBox.__init__(self,tr(texte),parent)
37       self.mousePressed=True
38       self.texte=texte
39       self.monOptionnel=monOptionnel
40       self.setToolTip(tr("clicker: affichage aide, double-click: ajout"))
41
42    def mouseDoubleClickEvent(self, event):
43       #print "dans mouseDoubleClickEvent", self
44       if self not in self.monOptionnel.dicoCb: 
45          event.accept()
46          return
47       listeCheckedMC="+"+self.monOptionnel.dicoCb[self]
48       self.monOptionnel.parentMC.ajoutMC(listeCheckedMC)
49       event.accept()
50       
51
52    def mousePressEvent(self, event):
53       if not( event.button() != Qt.RightButton)  : 
54          event.accept()
55          return
56       if self.monOptionnel.cbPressed != None :
57          self.monOptionnel.cbPressed.setChecked(False)
58       self.monOptionnel.cbPressed=self
59       if self.mousePressed == False :
60          self.mousePressed=True
61       else :
62          self.mousePressed=False
63          self.ajoutAideMC()
64       QCheckBox.mousePressEvent(self, event)
65       event.accept()
66
67    def ajoutAideMC(self):
68       try :
69         maDefinition = self.monOptionnel.parentMC.definition.entites[self.texte]
70         maLangue =  self.monOptionnel.parentMC.jdc.lang
71         if hasattr(maDefinition,maLangue): 
72           monAide = getattr(maDefinition,self.monOptionnel.parentMC.jdc.lang)
73       except :
74           monAide = ""
75       self.monOptionnel.parentMC.editor.affiche_commentaire(monAide)
76   
77 class monPBButtonCustom(QWidget,Ui_customPB):
78
79    def __init__(self,texte,monOptionnel,parent=None):
80       QWidget.__init__(self)
81       self.setupUi(self)
82       self.monPb.setText(texte)
83       self.monPb.clicked.connect(self.ajoutMC)
84
85       self.texte=texte
86       self.monOptionnel=monOptionnel
87       self.definitAideMC()
88       self.setToolTip(self.monAide)
89
90    def ajoutMC (self) :
91       listeCheckedMC="+"+self.monOptionnel.dicoCb[self]
92       self.monOptionnel.parentMC.ajoutMC(listeCheckedMC)
93
94    def definitAideMC(self):
95       try :
96         maDefinition = self.monOptionnel.parentMC.definition.entites[self.texte]
97         maLangue =  self.monOptionnel.parentMC.jdc.lang
98         if hasattr(maDefinition,maLangue): 
99           self.monAide = getattr(maDefinition,self.monOptionnel.parentMC.jdc.lang)
100       except :
101           self.monAide = ""
102         
103 class MonGroupeOptionnel (QWidget,Ui_groupeOptionnel):
104   """
105   """
106   def __init__(self,liste,parentQt,parentMC):
107      #print "dans init de monWidgetOptionnel ", parentQt, liste,parentMC
108      QWidget.__init__(self,None)
109      self.setupUi(self)
110      self.listeChecked=[]
111      self.dicoCb={}
112      self.mousePressed=False
113      self.cbPressed=None
114      self.cb=None
115      self.parentQt=parentQt
116      self.parentMC=parentMC
117      if liste != [] : 
118         self.affiche(liste)
119         self.afficheTitre()
120      elif self.parentQt.parentQt.afficheOptionnelVide != False : 
121         self.afficheTitre()
122         self.MCOptionnelLayout.insertWidget(0,QLabel(tr('Pas de MC Optionnel')))
123      else :
124         self.frameLabelMC.close()
125      #print "dans fin de monWidgetOptionnel ", parentQt
126
127
128   def afficheTitre(self):
129      labeltext,fonte,couleur = self.parentMC.node.item.GetLabelText()
130      #print (labeltext)
131      l=tr(labeltext)
132      li=[]
133      while len(l) > 25:
134          li.append(l[0:24])
135          l=l[24:]
136      li.append(l)
137      texte=""
138      for l in li : texte+=l+"\n"
139      texte=texte[0:-1]
140      self.MCLabel.setText(texte)
141
142   def affiche(self,liste):
143      #print "dans Optionnel ____ affiche", liste
144      self.dicoCb={}
145      liste.reverse()
146      for mot in liste :
147          if self.parentQt.parentQt.simpleClic == False :
148             cb = monRBButtonCustom(mot,self)
149             cb.clicked.connect(cb.ajoutAideMC)
150          else :
151             cb = monPBButtonCustom(mot,self)
152
153          self.MCOptionnelLayout.insertWidget(0,cb)
154          self.dicoCb[cb]=mot
155      self.scrollAreaCommandesOptionnelles.horizontalScrollBar().setSliderPosition(0)
156
157       
158