]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/gereIcones.py
Salome HOME
bug OCC 52962 and 52948
[tools/eficas.git] / InterfaceQT4 / gereIcones.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Modules Python
21 import string,types,os,re,sys
22 import traceback
23
24 from PyQt4 import *
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27 from Extensions.i18n import tr
28 listeSuffixe=('bmp','png','jpg' ,'txt','med')
29
30
31 class FacultatifOuOptionnel:
32
33   def setReglesEtAide(self):
34       listeRegles=()
35       try :
36          listeRegles     = self.node.item.get_regles()
37       except :
38          pass
39       if hasattr(self,"RBRegle"):
40         if listeRegles==() : self.RBRegle.close() 
41         else :
42            icon3=QIcon(self.repIcon+"/lettreRblanc30.png")
43            self.RBRegle.setIcon(icon3)
44            self.connect( self.RBRegle,SIGNAL("clicked()"),self.viewRegles)
45
46       cle_doc=None
47       if not hasattr(self,"RBInfo"):return
48       icon=QIcon(self.repIcon+"/point-interrogation30.png")
49       self.RBInfo.setIcon(icon)
50
51       from monWidgetCommande import MonWidgetCommande
52       if isinstance(self,MonWidgetCommande) and self.editor.code =="MAP":
53          self.cle_doc = self.chercheDocMAP()
54       else :
55          self.cle_doc = self.node.item.get_docu()
56       if self.cle_doc == None  : self.RBInfo.close()
57       else : self.connect (self.RBInfo,SIGNAL("clicked()"),self.viewDoc)
58
59
60   def chercheDocMAP(self):
61       try :
62         clef=self.editor.CONFIGURATION.adresse+"/"
63       except :
64         return None
65       for k in self.editor.readercata.cata[0].JdC.dict_groupes.keys():
66           if self.obj.nom in self.editor.readercata.cata[0].JdC.dict_groupes[k]:
67              clef+=k
68              break
69       clef+="/"+ self.obj.nom[0:-5].lower()+"/spec_"+self.obj.nom[0:-5].lower()+".html"
70
71       return clef
72  
73   def viewDoc(self):
74       try :
75           if sys.platform[0:5]=="linux" : cmd="xdg-open "+self.cle_doc
76           else                          : cmd="start "+self.cle_doc
77           os.system(cmd)
78       except:
79           QMessageBox.warning( self,tr( "Aide Indisponible"),tr( "l'aide n est pas installee "))
80
81   def viewRegles(self):
82       self.node.AppelleBuildLBRegles()
83
84
85   def setIconePoubelle(self):
86       if not(hasattr(self,"RBPoubelle")):return
87       if self.node.item.object.isoblig() : 
88          icon=QIcon(self.repIcon+"/deleteRondVide.png")
89          self.RBPoubelle.setIcon(icon)
90          return
91       icon=QIcon(self.repIcon+"/deleteRond.png")
92       self.RBPoubelle.setIcon(icon)
93       self.connect(self.RBPoubelle,SIGNAL("clicked()"),self.aDetruire)
94
95   def setIconesSalome(self):
96        if not (hasattr(self,"RBSalome")): return
97        from Accas import SalomeEntry
98        mc = self.node.item.get_definition()
99        mctype = mc.type[0]
100        enable_salome_selection = self.editor.salome and \
101          (('grma' in repr(mctype)) or ('grno' in repr(mctype)) or ('SalomeEntry' in repr(mctype)) or \
102          (hasattr(mctype, "enable_salome_selection") and mctype.enable_salome_selection))
103
104        if enable_salome_selection:
105           icon=QIcon(self.repIcon+"/flecheSalome.png")
106           self.RBSalome.setIcon(icon)
107           self.connect(self.RBSalome,SIGNAL("pressed()"),self.BSalomePressed)
108
109           if not(('grma' in repr(mctype)) or ('grno' in repr(mctype))) or not(self.editor.salome): 
110              self.BView2D.close()
111           else : 
112              icon1=QIcon(self.repIcon+"/eye.png")
113              self.RBSalomeVue.setIcon(icon1)
114              self.connect(self.RBSalomeVue,SIGNAL("clicked()"),self.BView2DPressed)
115        else:
116           self.RBSalome.close()
117           self.RBSalomeVue.close()
118
119      
120   def setIconesFichier(self):
121        if not ( hasattr(self,"BFichier")): return
122        mc = self.node.item.get_definition()
123        mctype = mc.type[0]
124        if mctype == "Repertoire":
125           self.BRepertoire=self.BFichier
126           self.connect(self.BRepertoire,SIGNAL("clicked()"),self.BRepertoirePressed)
127           self.BVisuFichier.close()
128        else :
129           self.connect(self.BFichier,SIGNAL("clicked()"),self.BFichierPressed)
130           self.connect(self.BVisuFichier,SIGNAL("clicked()"),self.BFichierVisu)
131
132
133
134   def setIconesGenerales(self):
135       repIcon=self.node.editor.appliEficas.repIcon
136       if hasattr(self,"BVisuListe") :
137          fichier=os.path.join(repIcon, 'plusnode.png')
138          icon = QIcon(fichier)
139          self.BVisuListe.setIcon(icon)
140       if hasattr(self,"RBDeplie") :
141          fichier=os.path.join(repIcon, 'plusnode.png')
142          icon = QIcon(fichier)
143          self.RBDeplie.setIcon(icon)
144       if hasattr(self,"RBPlie") :
145          fichier=os.path.join(repIcon, 'minusnode.png')
146          icon = QIcon(fichier)
147          self.RBPlie.setIcon(icon)
148
149       
150
151   def setRun(self):
152       if hasattr(self.editor.appliEficas, 'mesScripts'):
153          if hasattr(self.editor,'tree') and self.editor.tree.currentItem().item.get_nom() in self.appliEficas.mesScripts.dict_commandes.keys() :
154                print 'il faut programmer le self.ajoutScript()'
155                print '#PNPNPNPN'
156                return
157       if hasattr(self,"RBRun"): self.RBRun.close()
158
159
160   def aDetruire(self):
161       self.node.delete()
162
163   def setValide(self):
164       #print " c est le moment de gerer le passage au suivant"
165       if not(hasattr (self,'RBValide')) : return
166       icon = QIcon()
167       if self.node.item.object.isvalid() : 
168          icon=QIcon(self.repIcon+"/ast-green-ball.png")
169       else :
170          icon=QIcon(self.repIcon+"/ast-red-ball.png")
171       self.RBValide.setIcon(icon)
172
173   # il faut chercher la bonne fenetre
174   def rendVisible(self):
175       #print "je passe par rendVisible de FacultatifOuOptionnel"
176       #print self
177       #print self.node.fenetre
178       #print "return pour etre sure"
179       return
180       #PNPN
181       newNode=self.node.treeParent.chercheNoeudCorrespondant(self.node.item.object)
182       #print newNode
183       self.editor.fenetreCentraleAffichee.scrollAreaCommandes.ensureWidgetVisible(newNode.fenetre)
184       #newNode.fenetre.setFocus()
185
186
187 class ContientIcones:
188
189   def BFichierVisu(self):
190        fichier=self.lineEditVal.text()
191        if fichier == None or str(fichier)=="" : return
192        from monViewTexte import ViewText
193        try :
194          if sys.platform[0:5]=="linux" :
195            cmd="xdg-open "+ str(fichier)
196            os.system(cmd)
197          else                          :
198            os.startfile(str(fichier)) 
199        except:
200          try :
201             fp=open(fichier)
202             txt=fp.read()
203             nomFichier=QFileInfo(fichier).baseName()
204             maVue=ViewText(self,entete=nomFichier)
205             maVue.setText(txt)
206             maVue.show()
207             fp.close()
208          except:
209             QMessageBox.warning( None,
210                        tr("Visualisation Fichier "),
211                        tr("Impossibilite d'afficher le Fichier"),)
212
213   def BFichierPressed(self):
214       mctype = self.node.item.get_definition().type
215       if len(mctype) > 1:
216           filters = mctype[1]
217       elif hasattr(mctype[0], "filters"):
218           filters = mctype[0].filters
219       else:
220           filters = QString()
221       if len(mctype) > 2 and mctype[2] == "Sauvegarde":
222           fichier = QFileDialog.getSaveFileName(self.appliEficas,
223                               tr('Sauvegarder Fichier'),
224                               self.appliEficas.CONFIGURATION.savedir,
225                               filters)
226       else:
227           fichier = QFileDialog.getOpenFileName(self.appliEficas,
228                               tr('Ouvrir Fichier'),
229                               self.appliEficas.CONFIGURATION.savedir,
230                               filters)
231
232       if not(fichier.isNull()):
233          ulfile = os.path.abspath(unicode(fichier))
234          self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
235          self.lineEditVal.setText(fichier)
236          self.editor.affiche_commentaire(tr("Fichier selectionne"))
237          self.LEValeurPressed()
238          if (QFileInfo(fichier).suffix() in listeSuffixe ):
239              self.image=fichier
240              if (not hasattr(self,"BSelectInFile")):
241                self.BSelectInFile = QPushButton(self.Widget8)
242                self.BSelectInFile.setMinimumSize(QSize(140,40))
243                self.BSelectInFile.setObjectName("BSelectInFile")
244                self.gridLayout.addWidget(self.BSelectInFile,1,1,1,1)
245                self.BSelectInFile.setText(tr("Selection"))
246                self.connect(self.BSelectInFile,SIGNAL("clicked()"),self.BSelectInFilePressed)
247              else :
248                self.BSelectInFile.setVisible(1)
249          elif hasattr(self, "BSelectInFile"):
250              self.BSelectInFile.setVisible(0)
251
252   def BRepertoirePressed(self):
253       directory = QFileDialog.getExistingDirectory(self.appliEficas,
254             directory = self.appliEficas.CONFIGURATION.savedir,
255             options = QFileDialog.ShowDirsOnly)
256
257       if not directory.isNull():
258          absdir = os.path.abspath(unicode(directory))
259          self.appliEficas.CONFIGURATION.savedir = os.path.dirname(absdir)
260          self.lineEditVal.setText(directory)
261          self.LEValeurPressed()
262
263   def BSelectInFilePressed(self):
264       from monSelectImage import MonSelectImage
265       MonSelectImage(file=self.image,parent=self).show()
266
267           
268
269   def BSalomePressed(self):
270         self.editor.affiche_commentaire(QString(""))
271         selection=[]
272         commentaire=""
273         genea=self.node.item.get_genealogie()
274         kwType = self.node.item.get_definition().type[0]
275         for e in genea:
276             if "GROUP_NO" in e: kwType = "GROUP_NO"
277             if "GROUP_MA" in e: kwType = "GROUP_MA"
278
279         if 'grno' in repr(kwType): kwType = "GROUP_NO"
280         if 'grma' in repr(kwType): kwType = "GROUP_NO"
281
282         if kwType in ("GROUP_NO","GROUP_MA"):
283            selection, commentaire = self.appliEficas.selectGroupFromSalome(kwType,editor=self.editor)
284
285         mc = self.node.item.get_definition()
286
287         if  (isinstance(mc.type,types.TupleType) and len(mc.type) > 1 and "(*.med)" in mc.type[1] ):
288            selection, commentaire = self.appliEficas.selectMeshFile(editor=self.editor)
289            print selection, commentaire
290            if commentaire != "" : 
291                   QMessageBox.warning( None,
292                   tr("Export Med vers Fichier "),
293                   tr("Impossibilite d exporter le Fichier"),)
294                   return
295            else :
296                   self.lineEditVal.setText(QString(selection))
297                   return
298
299         from Accas import SalomeEntry
300         if isinstance(kwType, types.ClassType) and issubclass(kwType, SalomeEntry):
301            selection, commentaire = self.appliEficas.selectEntryFromSalome(kwType,editor=self.editor)
302
303         if commentaire !="" :
304             self.editor.affiche_infos(tr(QString(commentaire)))
305         monTexte=""
306         if selection == [] : return
307         for geomElt in selection:
308             monTexte=geomElt+","
309         monTexte= monTexte[0:-1]
310         self.lineEditVal.setText(QString(monTexte))
311
312   def BView2DPressed(self):
313         valeur=self.lineEditVal.text()
314         if valeur == QString("") : return
315         valeur = str(valeur)
316         if valeur :
317            ok, msgError = self.appliEficas.displayShape(valeur)
318            if not ok:
319               self.editor.affiche_infos(msgError,Qt.red)
320
321   def BParametresPressed(self):
322         liste=self.node.item.get_liste_param_possible()
323         from monListeParamPanel import MonListeParamPanel
324         MonListeParamPanel(liste=liste,parent=self).show()
325