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