Salome HOME
fin portage python 3
[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, parentQt.node.item.nom
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      self.afficheTitre()
92      if liste != [] : self.affiche(liste)
93      else : self.MCOptionnelLayout.insertWidget(0,QLabel(tr('Pas de MC Optionnel')))
94
95
96   def afficheTitre(self):
97      labeltext,fonte,couleur = self.parentMC.node.item.GetLabelText()
98      print (labeltext)
99      l=tr(labeltext)
100      li=[]
101      while len(l) > 25:
102          li.append(l[0:24])
103          l=l[24:]
104      li.append(l)
105      texte=""
106      for l in li : texte+=l+"\n"
107      texte=texte[0:-1]
108      self.MCLabel.setText(texte)
109
110   def affiche(self,liste):
111      #print "dans Optionnel ____ affiche", liste
112      self.dicoCb={}
113      liste.reverse()
114      for mot in liste :
115          cb = monButtonCustom(mot,self)
116          cb.clicked.connect(cb.ajoutAideMC)
117          self.MCOptionnelLayout.insertWidget(0,cb)
118          self.dicoCb[cb]=mot
119      self.scrollAreaCommandesOptionnelles.horizontalScrollBar().setSliderPosition(0)
120      #print "Fin Optionnel ____ affiche", liste
121
122       
123