Salome HOME
5ca0b75e4f6af0d341529eb6f0260be6c16a95de
[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 PyQt4.QtGui import *
23 from PyQt4.QtCore import *
24 from Extensions.i18n import tr
25 from desWidgetOptionnel import Ui_WidgetOptionnel
26
27     
28 # Import des panels
29
30 class monButtonCustom(QCheckBox):
31
32    def __init__(self,texte,monOptionnel,parent=None):
33       QCheckBox.__init__(self,texte,parent)
34       self.monOptionnel=monOptionnel
35
36    def mouseDoubleClickEvent(self, event):
37       print "dans mouseDoubleClickEvent"
38       if self not in self.monOptionnel.dicoCb.keys() : return
39       listeCheckedMC="+"+self.monOptionnel.dicoCb[self]
40       self.monOptionnel.parentMC.ajoutMC(listeCheckedMC)
41       self.setChecked(False)
42
43    def mousePressEvent(self, event):
44       print "dans mousePressEvent"
45       self.mousePressed=True
46       if not( event.button() != Qt.RightButton)  : return
47       QCheckBox.mousePressEvent(self, event)
48
49
50 class MonWidgetOptionnel (QWidget,Ui_WidgetOptionnel):
51   """
52   """
53   def __init__(self,parentQt):
54      print "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
55      print "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
56      print "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
57      print "dans init de monWidgetOptionnel ", parentQt, parentQt.node.item.nom
58      QWidget.__init__(self,None)
59      self.setupUi(self)
60      self.dicoCb={}
61      self.parentMC=None
62      self.listeChecked=[]
63      self.mousePressed=False
64      self.cbPressed=None
65      self.cb=None
66      self.parentQt=parentQt
67      self.connect(self.bAjoutMC,SIGNAL("clicked()"), self.ajoutMC)
68
69      
70
71   def affiche(self,liste):
72      print "dans Optionnel ____ affiche", liste
73      self.show()
74      labeltext,fonte,couleur = self.parentMC.node.item.GetLabelText()
75      l=labeltext
76      li=[]
77      while len(l) > 25:
78          li.append(l[0:24])
79          l=l[24:]
80      li.append(l)
81      texte=""
82      for l in li : texte+=l+"\n"
83      texte=texte[0:-2]
84      self.GeneaLabel.setText(tr("Options pour \n") +texte)
85
86      for cb in self.dicoCb.keys():
87          #print 'je detruit', self.dicoCb[cb], cb
88          cb.close()
89      #print self.commandesOptionnellesLayout.children()
90      self.dicoCb={}
91      liste.reverse()
92      for mot in liste :
93          cb = monButtonCustom(QString(mot),self)
94          #print "j ajoute ", mot, cb
95          self.dicoCb[cb]=mot
96          self.commandesOptionnellesLayout.insertWidget(0,cb)
97
98   def CBChecked(self):
99       # ordre ?
100       #print "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
101       return
102       for cb in self.dicoCb.keys() :
103           if cb.isChecked()      and self.dicoCb[cb] not in self.listeChecked : self.listeChecked.append(self.dicoCb[cb])
104           if not(cb.isChecked()) and self.dicoCb[cb] in self.listeChecked     : self.listeChecked.remove(self.dicoCb[cb])
105       self.parentMC.recalculeListeMC(self.listeChecked)
106
107
108   def ajoutMC(self):
109      maListe=""
110      for cb in self.dicoCb.keys():
111          if cb.isChecked() : maListe+="+"+str(cb.text())
112      if maListe=="":return
113      print "dans Optionnel __ ajout de ", maListe
114      self.parentMC.ajoutMC(maListe)
115