Salome HOME
b63c469eebcfb7606468b6a450c22ac0d3eec2f6
[tools/eficas.git] / InterfaceQT4 / monWidgetOptionnel.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
25 else :
26     from PyQt4.QtGui  import *
27     from PyQt4.QtCore import *
28
29 from Extensions.i18n import tr
30 from desWidgetOptionnel import Ui_WidgetOptionnel
31
32     
33 # Import des panels
34
35 class monButtonCustom(QCheckBox):
36
37    def __init__(self,texte,monOptionnel,parent=None):
38       QCheckBox.__init__(self,tr(texte),parent)
39       self.texte=texte
40       self.monOptionnel=monOptionnel
41
42    def mouseDoubleClickEvent(self, event):
43       #print "dans mouseDoubleClickEvent", self
44       if self not in self.monOptionnel.dicoCb.keys() : 
45          event.accept()
46          return
47       listeCheckedMC="+"+self.monOptionnel.dicoCb[self]
48       self.monOptionnel.parentMC.ajoutMC(listeCheckedMC)
49       self.setChecked(False)
50       event.accept()
51       
52
53    def mousePressEvent(self, event):
54       #print "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 MonWidgetOptionnel (QWidget,Ui_WidgetOptionnel):
64   """
65   """
66   def __init__(self,parentQt):
67      #print "dans init de monWidgetOptionnel ", parentQt, parentQt.node.item.nom
68      QWidget.__init__(self,None)
69      self.setupUi(self)
70      self.dicoCb={}
71      self.parentMC=None
72      self.listeChecked=[]
73      self.mousePressed=False
74      self.cbPressed=None
75      self.cb=None
76      self.parentQt=parentQt
77      #self.connect(self.bAjoutMC,SIGNAL("clicked()"), self.ajoutMC)
78      #print "fin init de monWidgetOptionnel ", parentQt, parentQt.node.item.nom
79
80      
81
82
83   def affiche(self,liste):
84      print "dans Optionnel ____ affiche", liste
85      self.show()
86      labeltext,fonte,couleur = self.parentMC.node.item.GetLabelText()
87      l=labeltext
88      li=[]
89      while len(l) > 25:
90          li.append(l[0:24])
91          l=l[24:]
92      li.append(l)
93      texte=""
94      for l in li : texte+=l+"\n"
95      texte=texte[0:-2]
96      self.GeneaLabel.setText(tr("Options pour \n") +texte)
97
98      for cb in self.dicoCb.keys():
99          #print 'je detruis', self.dicoCb[cb], cb
100          #print cb.close()
101          cb.close()
102
103      self.dicoCb={}
104      liste.reverse()
105      for mot in liste :
106          cb = monButtonCustom(mot,self)
107          #print "j ajoute ", mot, cb
108          self.dicoCb[cb]=mot
109          self.commandesOptionnellesLayout.insertWidget(0,cb)
110      self.scrollAreaCommandesOptionnelles.horizontalScrollBar().setSliderPosition(0)
111      print "Fin Optionnel ____ affiche", liste
112
113   def CBChecked(self):
114       # ordre ?
115       return
116       for cb in self.dicoCb.keys() :
117           if cb.isChecked()      and self.dicoCb[cb] not in self.listeChecked : self.listeChecked.append(self.dicoCb[cb])
118           if not(cb.isChecked()) and self.dicoCb[cb] in self.listeChecked     : self.listeChecked.remove(self.dicoCb[cb])
119       self.parentMC.recalculeListeMC(self.listeChecked)
120
121
122   def ajoutMC(self):
123      maListe=""
124      for cb in self.dicoCb.keys():
125          if cb.isChecked() : maListe+="+"+str(cb.text())
126      if maListe=="":return
127      #print "dans Optionnel __ ajout de ", maListe
128      self.parentMC.ajoutMC(maListe)
129
130   def hide(self):
131      self.parentQt.editor.saveSplitterSizes()
132      QWidget.hide(self)