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