Salome HOME
CCAR: merge de la version 1.14 dans la branche principale
[tools/eficas.git] / InterfaceTK / toolbar.py
1 # -*- coding: utf-8 -*-
2 #            CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002  EDF R&D                  WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
9 #
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
14 #
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 #    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
18 #
19 #
20 # ======================================================================
21 """
22 """
23 # Modules Python
24 import string
25 from Tkinter import *
26 import Pmw
27
28 # Modules Eficas
29 import images
30
31 class TOOLBAR:
32   def __init__(self,appli,parent):
33       # parent représente l'objet graphique parent
34       self.parent=parent
35       # appli représente l'objet application parent
36       self.appli=appli
37       self.balloon = None
38       self.l_boutons_a_activer = []
39       self.barreboutons=Frame(self.parent,relief='ridge',bd=2)
40       self.barreboutons.pack(anchor='nw',expand=0,fill=X)
41       # bouton Infos à l'extrême droite de la barre des boutons
42       b = Button(self.barreboutons,
43                  image = images.get_image('About24'),
44                  command = self.view_infos)
45       b.pack(side='right')
46       texte = "Infos EFICAS"
47       b.bind("<Enter>",lambda e,s=self,but=b,t=texte : s.affiche_balloon(e,but,t,pos='right'))
48       b.bind("<Leave>", self.efface_balloon)
49
50   def appelle_commande(self,e,b,c):
51       try :
52          c()
53       except :
54          pass
55
56   def inactive_boutons(self):
57       """
58       Inactive les boutons de la liste self.l_boutons_a_activer
59       --> cette méthode est appelée dès qu'il n'y a pas de JDC courant
60       """
61       for but in self.l_boutons_a_activer:
62           but.configure(state='disabled')
63
64   def active_boutons(self):
65       """
66       Active les boutons de la liste self.l_boutons_a_activer
67       --> cette méthode est appelée dès qu'il y a un JDC courant
68       """
69       for but in self.l_boutons_a_activer:
70           but.configure(state='normal')
71
72   def affiche_balloon(self,event,bouton,bulle,pos='left'):
73       """
74       Affiche le balloon bulle associé au bouton bouton
75       """
76       etat = bouton.cget('state')
77       if etat != 'normal' : return
78       geom = bouton.winfo_geometry()
79       l_args = string.split(geom,'+')
80       x = eval(l_args[1])+event.x+10
81       self.balloon = Label(self.parent,
82                            text = bulle,
83                            background="yellow",
84                            borderwidth=2,
85                            relief='ridge')
86       if pos == 'left':
87           self.balloon.place(in_=self.parent,x=x,y=32)
88       else:
89           self.balloon.place(in_=self.parent,x=x,y=32,anchor='ne')
90
91   def efface_balloon(self,event=None):
92       """
93       Efface le balloon courant
94       """
95       if self.balloon :
96           self.balloon.destroy()
97           self.balloon = None
98
99   def view_infos(self):
100       """
101       Permet d'afficher des infos sur la session courante d'EFICAS
102       """
103       self.fen_infos = Pmw.Dialog(self.parent,
104                                   title = 'Informations session EFICAS',
105                                   buttons = ('Fermer',),
106                                   command = self.close_infos)
107       self.fen_infos.withdraw()
108       texte_infos = self.appli.get_texte_infos()
109       Label(self.fen_infos.interior(),
110             text = texte_infos,
111             anchor='center').pack(side='top',anchor='center')
112       self.fen_infos.activate(geometry = 'centerscreenalways')
113
114   def close_infos(self,lbl):
115       """
116       Ferme la fenêtre des infos
117       """
118       self.fen_infos.destroy()
119
120   def creer_boutons_appli_composant(self,l_boutons,appli_composant):
121       for bouton in l_boutons :
122           if not bouton :
123               # on veut afficher un bouton vide (=espace entre boutons)
124               Button(self.barreboutons,
125                      image = images.get_image('Sep'),
126                      state='disabled',
127                      relief = 'flat').pack(side='left')
128               continue
129           nom_fic,commande,texte,statut = bouton
130           commande=getattr(appli_composant,commande)
131           b = Button(self.barreboutons,
132                      image = images.get_image(nom_fic),
133                      command = commande,
134                      relief='flat')
135           b.pack(side='left')
136           b.bind("<Enter>",lambda e,s=self,but=b,t=texte : s.affiche_balloon(e,but,t))
137           b.bind("<Leave>", self.efface_balloon)
138           b.bind("<Return>", lambda e,s=self,but=b,c=commande:s.appelle_commande(e,but,c))
139           if statut != 'always':
140               self.l_boutons_a_activer.append(b)
141
142       # inactive les boutons qui doivent l'être tant qu'aucun JDC courant
143       self.inactive_boutons()
144
145