Salome HOME
ajout pour accepter les accents sous python 2.3
[tools/eficas.git] / Editeur / 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 inactive_boutons(self):
51       """
52       Inactive les boutons de la liste self.l_boutons_a_activer
53       --> cette méthode est appelée dès qu'il n'y a pas de JDC courant
54       """
55       for but in self.l_boutons_a_activer:
56           but.configure(state='disabled')
57
58   def active_boutons(self):
59       """
60       Active les boutons de la liste self.l_boutons_a_activer
61       --> cette méthode est appelée dès qu'il y a un JDC courant
62       """
63       for but in self.l_boutons_a_activer:
64           but.configure(state='normal')
65
66   def affiche_balloon(self,event,bouton,bulle,pos='left'):
67       """
68       Affiche le balloon bulle associé au bouton bouton
69       """
70       etat = bouton.cget('state')
71       if etat != 'normal' : return
72       geom = bouton.winfo_geometry()
73       l_args = string.split(geom,'+')
74       x = eval(l_args[1])+event.x+10
75       self.balloon = Label(self.parent,
76                            text = bulle,
77                            background="yellow",
78                            borderwidth=2,
79                            relief='ridge')
80       if pos == 'left':
81           self.balloon.place(in_=self.parent,x=x,y=32)
82       else:
83           self.balloon.place(in_=self.parent,x=x,y=32,anchor='ne')
84
85   def efface_balloon(self,event=None):
86       """
87       Efface le balloon courant
88       """
89       if self.balloon :
90           self.balloon.destroy()
91           self.balloon = None
92
93   def view_infos(self):
94       """
95       Permet d'afficher des infos sur la session courante d'EFICAS
96       """
97       self.fen_infos = Pmw.Dialog(self.parent,
98                                   title = 'Informations session EFICAS',
99                                   buttons = ('Fermer',),
100                                   command = self.close_infos)
101       self.fen_infos.withdraw()
102       texte_infos = self.appli.get_texte_infos()
103       Label(self.fen_infos.interior(),
104             text = texte_infos,
105             anchor='center').pack(side='top',anchor='center')
106       self.fen_infos.activate(geometry = 'centerscreenalways')
107
108   def close_infos(self,lbl):
109       """
110       Ferme la fenêtre des infos
111       """
112       self.fen_infos.destroy()
113
114   def creer_boutons_appli_composant(self,l_boutons,appli_composant):
115       for bouton in l_boutons :
116           if not bouton :
117               # on veut afficher un bouton vide (=espace entre boutons)
118               Button(self.barreboutons,
119                      image = images.get_image('Sep'),
120                      state='disabled',
121                      relief = 'flat').pack(side='left')
122               continue
123           nom_fic,commande,texte,statut = bouton
124           commande=getattr(appli_composant,commande)
125           b = Button(self.barreboutons,
126                      image = images.get_image(nom_fic),
127                      command = commande,
128                      relief='flat')
129           b.pack(side='left')
130           b.bind("<Enter>",lambda e,s=self,but=b,t=texte : s.affiche_balloon(e,but,t))
131           b.bind("<Leave>", self.efface_balloon)
132           if statut != 'always':
133               self.l_boutons_a_activer.append(b)
134
135       # inactive les boutons qui doivent l'être tant qu'aucun JDC courant
136       self.inactive_boutons()
137
138