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