Salome HOME
sauve du 9 mai
[tools/eficas.git] / InterfaceQT4 / monChoixCommande.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 desChoixCommandes import Ui_ChoixCommandes
23 from determine import monEnvQT5
24 if monEnvQT5 :
25    from PyQt5.QtWidgets import QWidget, QAction ,QButtonGroup, QRadioButton, QLabel
26    from PyQt5.QtGui  import QIcon
27    from PyQt5.QtCore import QSize
28 else :
29    from PyQt4.QtGui  import *
30    from PyQt4.QtCore import *
31
32 from Extensions.i18n import tr
33 import os
34
35     
36 # Import des panels
37
38 class MonChoixCommande(Ui_ChoixCommandes,QWidget):
39   """
40   """
41   def __init__(self,node, jdc_item, editor):
42       QWidget.__init__(self,None)
43       self.setupUi(self)
44
45       self.repIcon=os.path.join( os.path.dirname(os.path.abspath(__file__)),'..','Editeur','icons')
46       iconeFile=os.path.join(self.repIcon,'lettreRblanc30.png')
47       icon = QIcon(iconeFile)
48       self.RBRegle.setIcon(icon)
49       self.RBRegle.setIconSize(QSize(21, 31))
50
51       self.item = jdc_item
52       self.node = node
53       self.editor = editor
54       self.jdc  = self.item.object.get_jdc_root()
55       debutTitre=self.editor.titre
56       self.listeWidget=[]
57       self.dicoCmd={}
58       if self.editor.fichier != None : 
59           nouveauTitre=debutTitre+" "+str(os.path.basename(self.editor.fichier))
60       else :
61           nouveauTitre=debutTitre
62       self.editor.appliEficas.setWindowTitle(nouveauTitre)
63
64       #print self.node.tree
65
66       if monEnvQT5 :
67          self.RBalpha.clicked.connect(self.afficheAlpha)
68          self.RBGroupe.clicked.connect(self.afficheGroupe)
69          self.RBOrdre.clicked.connect(self.afficheOrdre)
70          self.RBClear.clicked.connect(self.clearFiltre)
71          self.RBCasse.toggled.connect(self.ajouteRadioButtons)
72          self.LEFiltre.returnPressed.connect(self.ajouteRadioButtons)
73          self.LEFiltre.textChanged.connect(self.ajouteRadioButtons)
74       else :
75          self.connect(self.RBalpha,SIGNAL("clicked()"),self.afficheAlpha)
76          self.connect(self.RBGroupe,SIGNAL("clicked()"),self.afficheGroupe)
77          self.connect(self.RBOrdre,SIGNAL("clicked()"),self.afficheOrdre)
78          self.connect(self.RBClear,SIGNAL("clicked()"),self.clearFiltre)
79          self.connect(self.RBCasse,SIGNAL("toggled(bool)"),self.ajouteRadioButtons)
80          self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.ajouteRadioButtons)
81       if self.node.tree.item.get_regles() == () :
82          self.RBRegle.close()
83          self.labelRegle.close()
84       else : 
85         if monEnvQT5 : self.RBRegle.clicked.connect(self.afficheRegle)
86         else         : self.connect(self.RBRegle,SIGNAL("clicked()"),self.afficheRegle)
87
88       if self.editor.Ordre_Des_Commandes == None : self.RBOrdre.close()
89
90        
91       #self.editor.labelCommentaire.setText("")
92       if self.editor.widgetOptionnel!= None : 
93          self.editor.fermeOptionnel()
94          self.editor.widgetOptionnel=None
95       self.name=None
96
97       self.affiche_alpha=0
98       self.affiche_groupe=0
99       self.affiche_ordre=0
100       if self.editor.affiche=="alpha"  : 
101          self.affiche_alpha==1;  
102          self.RBalpha.setChecked(True);
103          self.afficheAlpha()
104       elif self.editor.affiche=="groupe" : 
105          self.affiche_groupe==1; 
106          self.RBGroupe.setChecked(True); 
107          self.afficheGroupe()
108       elif self.editor.affiche=="ordre"  : 
109          self.affiche_ordre==1;  
110          self.RBOrdre.setChecked(True);  
111          self.afficheOrdre()
112       if self.editor.code == "Adao" : self.frameAffichage.close()
113
114   def afficheRegle(self):
115       self.node.tree.AppelleBuildLBRegles()
116
117   def afficheAlpha(self):
118       self.affiche_alpha=1
119       self.affiche_groupe=0
120       self.affiche_ordre=0
121       self.ajouteRadioButtons()
122
123   def afficheGroupe(self):
124       self.affiche_alpha=0
125       self.affiche_groupe=1
126       self.affiche_ordre=0
127       self.ajouteRadioButtons()
128
129   def afficheOrdre(self):
130       self.affiche_alpha=0
131       self.affiche_groupe=0
132       self.affiche_ordre=1
133       self.ajouteRadioButtons()
134
135   def mouseDoubleClickEvent(self,event):
136       nodeCourrant=self.node.tree.currentItem()
137       if nodeCourrant==None: nodeCourrant=self.node.tree.racine
138       if self.name != None :
139          plier=self.editor.afficheCommandesPliees
140          if nodeCourrant==self.node : nouveau=self.node.append_child(self.name,'first',plier)
141          else : nouveau=nodeCourrant.append_brother(self.name,plier=plier)
142       else :
143          nouveau = 0
144       if nouveau == 0 : return # on n a pas insere le noeud
145       nouveau.setDeplie()
146       #if self.editor.afficheApresInsert==True : nouveau.plieToutEtReaffiche()
147       if self.editor.afficheApresInsert == True :
148            #if self.editor.affichePlie==True:  nouveau.plieToutEtReaffiche()
149            if self.editor.afficheCommandesPliees ==True:  nouveau.plieToutEtReaffiche()
150            else : nouveau.deplieToutEtReaffiche()
151            nouveau.fenetre.donnePremier()
152            #nouveau.deplieToutEtReaffiche()
153       else :
154            self.node.setSelected(False)
155            nouveau.setSelected(True)
156            self.node.tree.setCurrentItem(nouveau)
157       event.accept()
158       
159
160   def creeListeCommande(self,filtre):
161       listeGroupes,dictGroupes=self.jdc.get_groups()
162       sensibleALaCasse=self.RBCasse.isChecked()
163       if "CACHE" in dictGroupes.keys():
164          aExclure=dictGroupes["CACHE"]
165       else:
166          aExclure=()
167       listeACreer=[]
168       for l in self.jdc.get_liste_cmd():
169          if l not in aExclure : 
170             if sensibleALaCasse and (filtre != None and not filtre in l) : continue
171             if (not sensibleALaCasse) and filtre != None and (not filtre in l) and (not filtre.upper() in l) : continue
172             listeACreer.append(l)
173       return listeACreer
174
175   def ajouteRadioButtons(self):
176       filtre=str(self.LEFiltre.text())
177       if filtre==str("") : filtre=None
178       if hasattr(self,'buttonGroup') :
179          for b in self.buttonGroup.buttons():
180              self.buttonGroup.removeButton(b)
181              b.close()
182       else :
183          self.buttonGroup = QButtonGroup()
184       for w in self.listeWidget :
185          w.close()
186       self.listeWidget=[]
187       if self.affiche_alpha==1 :
188          liste=self.creeListeCommande(filtre)
189          for cmd in liste :
190            self.dicoCmd[tr(cmd)]=cmd
191            rbcmd=(QRadioButton(tr(cmd)))
192            self.buttonGroup.addButton(rbcmd)
193            self.commandesLayout.addWidget(rbcmd)
194            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
195            if monEnvQT5:
196               self.buttonGroup.buttonClicked.connect(self.rbClique) 
197            else :
198               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
199       elif  self.affiche_groupe==1 :
200          listeGroupes,dictGroupes=self.jdc.get_groups()
201          for grp in listeGroupes:
202            if grp == "CACHE" : continue
203            label=QLabel(self)
204            if monEnvQT5 :
205               text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
206            else :
207               text=QString.fromUtf8('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
208            label.setText(text)
209            self.listeWidget.append(label)
210            aAjouter=1
211            sensibleALaCasse=self.RBCasse.isChecked()
212            for cmd in  dictGroupes[grp]:
213               if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
214               if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
215               if aAjouter == 1 :
216                  self.commandesLayout.addWidget(label)
217                  aAjouter=0
218               self.dicoCmd[tr(cmd)]=cmd
219               rbcmd=(QRadioButton(tr(cmd)))
220               self.buttonGroup.addButton(rbcmd)
221               self.commandesLayout.addWidget(rbcmd)
222               rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
223               if monEnvQT5:
224                  self.buttonGroup.buttonClicked.connect(self.rbClique) 
225               else :
226                   self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
227            label2=QLabel(self)
228            label2.setText(" ")
229            self.listeWidget.append(label2)
230            self.commandesLayout.addWidget(label2)
231       elif  self.affiche_ordre==1 :
232          listeFiltre=self.creeListeCommande(filtre)
233          liste=[]
234          if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
235          else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
236          for cmd in Ordre_Des_Commandes :
237             if cmd in listeFiltre :
238                  liste.append(cmd)
239          for cmd in liste :
240            self.dicoCmd[tr(cmd)]=cmd
241            rbcmd=(QRadioButton(tr(cmd)))
242            self.buttonGroup.addButton(rbcmd)
243            self.commandesLayout.addWidget(rbcmd)
244            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
245            if monEnvQT5:
246               self.buttonGroup.buttonClicked.connect(self.rbClique) 
247            else :
248               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
249
250      
251
252   def clearFiltre(self):
253       self.LEFiltre.setText("")
254       self.ajouteRadioButtons()
255
256   def rbClique(self,id):
257       self.name=self.dicoCmd[str(id.text())]
258       definitionEtape=getattr(self.jdc.cata[0],self.name)
259       commentaire=getattr(definitionEtape,self.jdc.lang)
260       try :
261         commentaire=getattr(definitionEtape,self.jdc.lang)
262       except :
263         try :
264            commentaire=getattr(definitionEtape,"ang")
265         except :
266            commentaire=""
267       self.editor.affiche_commentaire(commentaire)
268
269
270
271   def setValide(self):
272       #PNPN a priori pas d icone mais peut-etre a faire
273       pass