]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/monGroupeOptionnel.py
Salome HOME
0a61ae64bd68322682a9141760dd9e228bac3c09
[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       maDefinition = self.monOptionnel.parentMC.definition.entites[self.texte]
72       maLangue =  self.monOptionnel.parentMC.jdc.lang
73       if hasattr(maDefinition,maLangue): 
74          monAide = getattr(maDefinition,self.monOptionnel.parentMC.jdc.lang)
75       else :
76          monAide = ""
77       self.monOptionnel.parentMC.editor.affiche_commentaire(monAide)
78   
79
80 class MonGroupeOptionnel (QWidget,Ui_groupeOptionnel):
81   """
82   """
83   def __init__(self,liste,parentQt,parentMC):
84      #print "dans init de monWidgetOptionnel ", parentQt, parentQt.node.item.nom
85      QWidget.__init__(self,None)
86      self.setupUi(self)
87      self.listeChecked=[]
88      self.dicoCb={}
89      self.mousePressed=False
90      self.cbPressed=None
91      self.cb=None
92      self.parentQt=parentQt
93      self.parentMC=parentMC
94      self.afficheTitre()
95      if liste != [] : self.affiche(liste)
96      else : self.MCOptionnelLayout.insertWidget(0,QLabel(tr('Pas de MC Optionnel')))
97
98
99   def afficheTitre(self):
100      labeltext,fonte,couleur = self.parentMC.node.item.GetLabelText()
101      l=tr(labeltext)
102      li=[]
103      while len(l) > 25:
104          li.append(l[0:24])
105          l=l[24:]
106      li.append(l)
107      texte=""
108      for l in li : texte+=l+"\n"
109      texte=texte[0:-2]
110      self.MCLabel.setText(texte)
111
112   def affiche(self,liste):
113      #print "dans Optionnel ____ affiche", liste
114      self.dicoCb={}
115      liste.reverse()
116      for mot in liste :
117          cb = monButtonCustom(mot,self)
118          if monEnvQT5:
119            cb.clicked.connect(cb.ajoutAideMC)
120          else :
121            self.connect(cb,SIGNAL("clicked()"), cb.ajoutAideMC)
122          self.MCOptionnelLayout.insertWidget(0,cb)
123          self.dicoCb[cb]=mot
124      self.scrollAreaCommandesOptionnelles.horizontalScrollBar().setSliderPosition(0)
125      #print "Fin Optionnel ____ affiche", liste
126
127       
128