Salome HOME
suite chgt copyright et menage
[tools/eficas.git] / InterfaceQT4 / monGroupeOptionnel.py
1 # Copyright (C) 2007-2017   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         else : 
74           monAide = ""
75       except :
76           monAide = ""
77       self.monOptionnel.parentMC.editor.affiche_commentaire(monAide)
78   
79 class monPBButtonCustom(QWidget,Ui_customPB):
80
81    def __init__(self,texte,monOptionnel,parent=None):
82       QWidget.__init__(self)
83       self.setupUi(self)
84       self.monPb.setText(texte)
85       self.monPb.clicked.connect(self.ajoutMC)
86
87       self.texte=texte
88       self.monOptionnel=monOptionnel
89       self.definitAideMC()
90       self.setToolTip(self.monAide)
91
92    def ajoutMC (self) :
93       listeCheckedMC="+"+self.monOptionnel.dicoCb[self]
94       self.monOptionnel.parentMC.ajoutMC(listeCheckedMC)
95
96    def definitAideMC(self):
97       try :
98         maDefinition = self.monOptionnel.parentMC.definition.entites[self.texte]
99         maLangue =  self.monOptionnel.parentMC.jdc.lang
100         if hasattr(maDefinition,maLangue): 
101           self.monAide = getattr(maDefinition,self.monOptionnel.parentMC.jdc.lang)
102       except :
103           self.monAide = ""
104         
105 class MonGroupeOptionnel (QWidget,Ui_groupeOptionnel):
106   """
107   """
108   def __init__(self,liste,parentQt,parentMC):
109      #print "dans init de monWidgetOptionnel ", parentQt, liste,parentMC
110      QWidget.__init__(self,None)
111      self.setupUi(self)
112      self.listeChecked=[]
113      self.dicoCb={}
114      self.mousePressed=False
115      self.cbPressed=None
116      self.cb=None
117      self.parentQt=parentQt
118      self.parentMC=parentMC
119      if liste != [] : 
120         self.affiche(liste)
121         self.afficheTitre()
122      elif self.parentQt.parentQt.afficheOptionnelVide != False : 
123         self.afficheTitre()
124         self.MCOptionnelLayout.insertWidget(0,QLabel(tr('Pas de MC Optionnel')))
125      else :
126         self.frameLabelMC.close()
127      #print "dans fin de monWidgetOptionnel ", parentQt
128
129
130   def afficheTitre(self):
131      labeltext,fonte,couleur = self.parentMC.node.item.GetLabelText()
132      #print (labeltext)
133      l=tr(labeltext)
134      li=[]
135      while len(l) > 25:
136          li.append(l[0:24])
137          l=l[24:]
138      li.append(l)
139      texte=""
140      for l in li : texte+=l+"\n"
141      texte=texte[0:-1]
142      self.MCLabel.setText(texte)
143
144   def affiche(self,liste):
145      #print "dans Optionnel ____ affiche", liste
146      self.dicoCb={}
147      liste.reverse()
148      for mot in liste :
149          if self.parentQt.parentQt.simpleClic == False :
150             cb = monRBButtonCustom(mot,self)
151             cb.clicked.connect(cb.ajoutAideMC)
152          else :
153             cb = monPBButtonCustom(mot,self)
154
155          self.MCOptionnelLayout.insertWidget(0,cb)
156          self.dicoCb[cb]=mot
157      self.scrollAreaCommandesOptionnelles.horizontalScrollBar().setSliderPosition(0)
158
159       
160