Salome HOME
b6c8d235affcfb81b7f1c3ac82b1d427943e0427
[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
65       #print self.node.tree
66
67       if monEnvQT5 :
68          self.RBalpha.clicked.connect(self.afficheAlpha)
69          self.RBGroupe.clicked.connect(self.afficheGroupe)
70          self.RBOrdre.clicked.connect(self.afficheOrdre)
71          self.RBClear.clicked.connect(self.clearFiltre)
72          self.RBCasse.toggled.connect(self.ajouteRadioButtons)
73          self.LEFiltre.returnPressed.connect(self.ajouteRadioButtons)
74          self.LEFiltre.textChanged.connect(self.ajouteRadioButtons)
75       else :
76          self.connect(self.RBalpha,SIGNAL("clicked()"),self.afficheAlpha)
77          self.connect(self.RBGroupe,SIGNAL("clicked()"),self.afficheGroupe)
78          self.connect(self.RBOrdre,SIGNAL("clicked()"),self.afficheOrdre)
79          self.connect(self.RBClear,SIGNAL("clicked()"),self.clearFiltre)
80          self.connect(self.RBCasse,SIGNAL("toggled(bool)"),self.ajouteRadioButtons)
81          self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.ajouteRadioButtons)
82       if self.node.tree.item.get_regles() == () :
83          self.RBRegle.close()
84          self.labelRegle.close()
85       else : 
86         if monEnvQT5 : self.RBRegle.clicked.connect(self.afficheRegle)
87         else         : self.connect(self.RBRegle,SIGNAL("clicked()"),self.afficheRegle)
88
89       if self.editor.Ordre_Des_Commandes == None : self.RBOrdre.close()
90
91        
92       #self.editor.labelCommentaire.setText("")
93       if self.editor.widgetOptionnel!= None : 
94          self.editor.fermeOptionnel()
95          self.editor.widgetOptionnel=None
96       self.name=None
97
98       self.affiche_alpha=0
99       self.affiche_groupe=0
100       self.affiche_ordre=0
101       if self.editor.affiche=="alpha"  : 
102          self.affiche_alpha==1;  
103          self.RBalpha.setChecked(True);
104          self.afficheAlpha()
105       elif self.editor.affiche=="groupe" : 
106          self.affiche_groupe==1; 
107          self.RBGroupe.setChecked(True); 
108          self.afficheGroupe()
109       elif self.editor.affiche=="ordre"  : 
110          self.affiche_ordre==1;  
111          self.RBOrdre.setChecked(True);  
112          self.afficheOrdre()
113       if self.editor.closeFrameRechercheCommande == True : self.frameAffichage.close()
114
115   def afficheRegle(self):
116       self.node.tree.AppelleBuildLBRegles()
117
118   def afficheAlpha(self):
119       self.affiche_alpha=1
120       self.affiche_groupe=0
121       self.affiche_ordre=0
122       self.ajouteRadioButtons()
123
124   def afficheGroupe(self):
125       self.affiche_alpha=0
126       self.affiche_groupe=1
127       self.affiche_ordre=0
128       self.ajouteRadioButtons()
129
130   def afficheOrdre(self):
131       self.affiche_alpha=0
132       self.affiche_groupe=0
133       self.affiche_ordre=1
134       self.ajouteRadioButtons()
135
136   def mouseDoubleClickEvent(self,event):
137       print self.editor.Classement_Commandes_Ds_Arbre
138       if self.editor.Classement_Commandes_Ds_Arbre!= () : self.chercheOu()
139       nodeCourrant=self.node.tree.currentItem()
140       if nodeCourrant==None: nodeCourrant=self.node.tree.racine
141       if self.name != None :
142          plier=self.editor.afficheCommandesPliees
143          if nodeCourrant==self.node : nouveau=self.node.append_child(self.name,'first',plier)
144          else : nouveau=nodeCourrant.append_brother(self.name,plier=plier)
145       else :
146          nouveau = 0
147       if nouveau == 0 : return # on n a pas insere le noeud
148       nouveau.setDeplie()
149       #if self.editor.afficheApresInsert==True : nouveau.plieToutEtReaffiche()
150       if self.editor.afficheApresInsert == True :
151            #if self.editor.affichePlie==True:  nouveau.plieToutEtReaffiche()
152            if self.editor.afficheCommandesPliees ==True:  nouveau.plieToutEtReaffiche()
153            else : nouveau.deplieToutEtReaffiche()
154            nouveau.fenetre.donnePremier()
155            #nouveau.deplieToutEtReaffiche()
156       else :
157            self.node.setSelected(False)
158            nouveau.setSelected(True)
159            self.node.tree.setCurrentItem(nouveau)
160       event.accept()
161       
162   def chercheOu(self):
163      if self.node.tree.racine.childrenComplete==[] : return None
164      listeNoeud=[]
165      for node in self.node.tree.racine.childrenComplete :
166          listeNoeud.append(node.item.object.nom)
167      indexAvant=-1
168      indexStop=self.editor.Classement_Commandes_Ds_Arbre.index(self.name)
169      for commande in self.editor.Classement_Commandes_Ds_Arbre[:indexStop]:
170          if commande in listeNoeud: indexAvant=indexAvant+1
171      if indexAvant==-1 : self.node.tree.setCurrentItem(None)
172      else :
173         nodeASelectionner=self.node.tree.racine.childrenComplete[indexAvant]
174         self.node.tree.setCurrentItem(nodeASelectionner)
175          
176
177   def creeListeCommande(self,filtre):
178       listeGroupes,dictGroupes=self.jdc.get_groups()
179       sensibleALaCasse=self.RBCasse.isChecked()
180       if "CACHE" in dictGroupes.keys():
181          aExclure=dictGroupes["CACHE"]
182       else:
183          aExclure=()
184       listeACreer=[]
185       for l in self.jdc.get_liste_cmd():
186          if l not in aExclure : 
187             if sensibleALaCasse and (filtre != None and not filtre in l) : continue
188             if (not sensibleALaCasse) and filtre != None and (not filtre in l) and (not filtre.upper() in l) : continue
189             listeACreer.append(l)
190       return listeACreer
191
192   def ajouteRadioButtons(self):
193       #print 'ds ajouteRadioButtons'
194       filtre=str(self.LEFiltre.text())
195       if filtre==str("") : filtre=None
196       if hasattr(self,'buttonGroup') :
197          for b in self.buttonGroup.buttons():
198              self.buttonGroup.removeButton(b)
199              b.setParent(None)
200              b.close()
201       else :
202          self.buttonGroup = QButtonGroup()
203       for w in self.listeWidget :
204          w.setParent(None)
205          w.close()
206       self.listeWidget=[]
207       if self.affiche_alpha==1 :
208          liste=self.creeListeCommande(filtre)
209          for cmd in liste :
210            self.dicoCmd[tr(cmd)]=cmd
211            rbcmd=(QRadioButton(tr(cmd)))
212            self.buttonGroup.addButton(rbcmd)
213            self.commandesLayout.addWidget(rbcmd)
214            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
215            if monEnvQT5:
216               self.buttonGroup.buttonClicked.connect(self.rbClique) 
217            else :
218               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique) 
219       elif  self.affiche_groupe==1 :
220          listeGroupes,dictGroupes=self.jdc.get_groups()
221          for grp in listeGroupes:
222            if grp == "CACHE" : continue
223            label=QLabel(self)
224            if monEnvQT5 :
225               text=tr('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
226            else :
227               text=QString.fromUtf8('<html><head/><body><p><span style=\" font-weight:600;\">Groupe : '+tr(grp)+'</span></p></body></html>')
228            label.setText(text)
229            self.listeWidget.append(label)
230            aAjouter=1
231            sensibleALaCasse=self.RBCasse.isChecked()
232            for cmd in  dictGroupes[grp]:
233               if sensibleALaCasse and (filtre != None and not filtre in cmd) : continue
234               if (not sensibleALaCasse) and filtre != None and (not filtre in cmd) and (not filtre.upper() in cmd) : continue
235               if aAjouter == 1 :
236                  self.commandesLayout.addWidget(label)
237                  aAjouter=0
238               self.dicoCmd[tr(cmd)]=cmd
239               rbcmd=(QRadioButton(tr(cmd)))
240               self.buttonGroup.addButton(rbcmd)
241               self.commandesLayout.addWidget(rbcmd)
242               rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
243               if monEnvQT5:
244                  self.buttonGroup.buttonClicked.connect(self.rbClique) 
245               else :
246                   self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
247            label2=QLabel(self)
248            label2.setText(" ")
249            self.listeWidget.append(label2)
250            self.commandesLayout.addWidget(label2)
251       elif  self.affiche_ordre==1 :
252          listeFiltre=self.creeListeCommande(filtre)
253          liste=[]
254          if self.editor.Ordre_Des_Commandes == None : Ordre_Des_Commandes=listeFiltre
255          else : Ordre_Des_Commandes=self.editor.Ordre_Des_Commandes
256          for cmd in Ordre_Des_Commandes :
257             if cmd in listeFiltre :
258                  liste.append(cmd)
259          for cmd in liste :
260            self.dicoCmd[tr(cmd)]=cmd
261            rbcmd=(QRadioButton(tr(cmd)))
262            self.buttonGroup.addButton(rbcmd)
263            self.commandesLayout.addWidget(rbcmd)
264            rbcmd.mouseDoubleClickEvent=self.mouseDoubleClickEvent
265            if monEnvQT5:
266               self.buttonGroup.buttonClicked.connect(self.rbClique) 
267            else :
268               self.connect(self.buttonGroup, SIGNAL("buttonClicked(QAbstractButton*)"),self.rbClique)
269
270      
271
272   def clearFiltre(self):
273       self.LEFiltre.setText("")
274       self.ajouteRadioButtons()
275
276   def rbClique(self,id):
277       self.name=self.dicoCmd[str(id.text())]
278       definitionEtape=getattr(self.jdc.cata[0],self.name)
279       commentaire=getattr(definitionEtape,self.jdc.lang)
280       try :
281         commentaire=getattr(definitionEtape,self.jdc.lang)
282       except :
283         try :
284            commentaire=getattr(definitionEtape,"ang")
285         except :
286            commentaire=""
287       self.editor.affiche_commentaire(commentaire)
288
289
290
291   def setValide(self):
292       #PNPN a priori pas d icone mais peut-etre a faire
293       pass