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