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