Salome HOME
8711f2f46b75c2b0a84bb32c0cd39fb9533e9cca
[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.texte=texte
41       self.monOptionnel=monOptionnel
42
43    def mouseDoubleClickEvent(self, event):
44       #print "dans mouseDoubleClickEvent", self
45       if self not in self.monOptionnel.dicoCb.keys() : 
46          event.accept()
47          return
48       listeCheckedMC="+"+self.monOptionnel.dicoCb[self]
49       self.monOptionnel.parentMC.ajoutMC(listeCheckedMC)
50       event.accept()
51       
52
53    def mousePressEvent(self, event):
54       #rint "dans mousePressEvent"
55       self.mousePressed=True
56       if not( event.button() != Qt.RightButton)  : 
57          event.accept()
58          return
59       QCheckBox.mousePressEvent(self, event)
60       event.accept()
61
62
63 class MonGroupeOptionnel (QWidget,Ui_groupeOptionnel):
64   """
65   """
66   def __init__(self,liste,parentQt,parentMC):
67      #print "dans init de monWidgetOptionnel ", parentQt, parentQt.node.item.nom
68      QWidget.__init__(self,None)
69      self.setupUi(self)
70      self.listeChecked=[]
71      self.dicoCb={}
72      self.mousePressed=False
73      self.cbPressed=None
74      self.cb=None
75      self.parentQt=parentQt
76      self.parentMC=parentMC
77      self.afficheTitre()
78      if liste != [] : self.affiche(liste)
79      else : self.MCOptionnelLayout.insertWidget(0,QLabel(tr('Pas de MC Optionnel')))
80
81
82   def afficheTitre(self):
83      labeltext,fonte,couleur = self.parentMC.node.item.GetLabelText()
84      l=tr(labeltext)
85      li=[]
86      while len(l) > 25:
87          li.append(l[0:24])
88          l=l[24:]
89      li.append(l)
90      texte=""
91      for l in li : texte+=l+"\n"
92      texte=texte[0:-2]
93      self.MCLabel.setText(texte)
94
95   def affiche(self,liste):
96      #print "dans Optionnel ____ affiche", liste
97      self.dicoCb={}
98      liste.reverse()
99      for mot in liste :
100          cb = monButtonCustom(mot,self)
101          #if monEnvQT5:
102          #  cb.clicked.connect(self.ajoutMC)
103          #else :
104          #  self.connect(cb,SIGNAL("clicked()"), self.ajoutMC)
105          self.MCOptionnelLayout.insertWidget(0,cb)
106          self.dicoCb[cb]=mot
107      self.scrollAreaCommandesOptionnelles.horizontalScrollBar().setSliderPosition(0)
108      #print "Fin Optionnel ____ affiche", liste
109
110   def CBChecked(self):
111       # ordre ?
112       return
113       for cb in self.dicoCb.keys() :
114           if cb.isChecked()      and self.dicoCb[cb] not in self.listeChecked : self.listeChecked.append(self.dicoCb[cb])
115           if not(cb.isChecked()) and self.dicoCb[cb] in self.listeChecked     : self.listeChecked.remove(self.dicoCb[cb])
116       self.parentMC.recalculeListeMC(self.listeChecked)
117
118 #
119 #  def ajoutMC(self):
120 #     maListe=""
121 #     for cb in self.dicoCb.keys():
122 #         if cb.isChecked() : maListe+="+"+str(cb.text())
123 #     if maListe=="":return
124      #print "dans Optionnel __ ajout de ", maListe
125 #     self.parentMC.ajoutMC(maListe)
126 #