Salome HOME
mise a jour du COPYRIGHT
[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       #self.creer_boutons()
50
51   def creer_boutons(self):
52       self.l_boutons = (('New24',self.appli.newJDC,"Création d'un nouveau fichier",'always'),
53                         ('Open24',self.appli.openJDC,"Ouverture d'un fichier existant",'always'),
54                         ('Save24',self.appli.saveJDC,"Sauvegarde du fichier courant",'always'),
55                         ('Zoom24',self.appli.visuJDC,"Visualisation du fichier de commandes",'always'),
56                         None,
57                         ('Copy24',self.appli.copy,"Copie l'objet courant",'jdc'),
58                         ('Cut24',self.appli.cut,"Coupe l'objet courant",'jdc'),
59                         ('Paste24',self.appli.paste,"Colle l'objet copié après l'objet courant",'jdc'),
60                         None,
61                         ('Delete24',self.appli.delete,"Supprime l'objet courant",'jdc'),
62                         ('Help24',self.appli.view_doc,"Documentation de l'objet courant",'jdc')
63                         )
64       # liste des boutons à activer quand statut != 'always'
65       self.l_boutons_a_activer = [] 
66
67       for bouton in self.l_boutons :
68           if not bouton :
69               # on veut afficher un bouton vide (=espace entre boutons)
70               Button(self.barreboutons,
71                      image = images.get_image('New24'),
72                      relief = 'flat').pack(side='left')
73               continue
74           nom_fic,commande,texte,statut = bouton
75           b = Button(self.barreboutons,
76                      image = images.get_image(nom_fic),
77                      command = commande,
78                      relief='flat')
79           b.pack(side='left')
80           b.bind("<Enter>",lambda e,s=self,but=b,t=texte : s.affiche_balloon(e,but,t))
81           b.bind("<Leave>", self.efface_balloon)
82           if statut != 'always':
83               self.l_boutons_a_activer.append(b)
84       # bouton Infos à l'extrême droite de la barre des boutons
85       b = Button(self.barreboutons,
86                  image = images.get_image('About24'),
87                  command = self.view_infos)
88       b.pack(side='right')
89       texte = "Infos EFICAS"
90       b.bind("<Enter>",lambda e,s=self,but=b,t=texte : s.affiche_balloon(e,but,t,pos='right'))
91       b.bind("<Leave>", self.efface_balloon)
92       # inactive les boutons qui doivent l'être tant qu'aucun JDC courant
93       self.inactive_boutons()
94
95   def inactive_boutons(self):
96       """
97       Inactive les boutons de la liste self.l_boutons_a_activer
98       --> cette méthode est appelée dès qu'il n'y a pas de JDC courant
99       """
100       for but in self.l_boutons_a_activer:
101           but.configure(state='disabled')
102
103   def active_boutons(self):
104       """
105       Active les boutons de la liste self.l_boutons_a_activer
106       --> cette méthode est appelée dès qu'il y a un JDC courant
107       """
108       for but in self.l_boutons_a_activer:
109           but.configure(state='normal')
110
111   def affiche_balloon(self,event,bouton,bulle,pos='left'):
112       """
113       Affiche le balloon bulle associé au bouton bouton
114       """
115       etat = bouton.cget('state')
116       if etat != 'normal' : return
117       geom = bouton.winfo_geometry()
118       l_args = string.split(geom,'+')
119       x = eval(l_args[1])+event.x+10
120       self.balloon = Label(self.parent,
121                            text = bulle,
122                            background="yellow",
123                            borderwidth=2,
124                            relief='ridge')
125       if pos == 'left':
126           self.balloon.place(in_=self.parent,x=x,y=32)
127       else:
128           self.balloon.place(in_=self.parent,x=x,y=32,anchor='ne')
129
130   def efface_balloon(self,event=None):
131       """
132       Efface le balloon courant
133       """
134       if self.balloon :
135           self.balloon.destroy()
136           self.balloon = None
137
138   def view_infos(self):
139       """
140       Permet d'afficher des infos sur la session courante d'EFICAS
141       """
142       self.fen_infos = Pmw.Dialog(self.parent,
143                                   title = 'Informations session EFICAS',
144                                   buttons = ('Fermer',),
145                                   command = self.close_infos)
146       self.fen_infos.withdraw()
147       texte_infos = self.appli.get_texte_infos()
148       Label(self.fen_infos.interior(),
149             text = texte_infos,
150             anchor='center').pack(side='top',anchor='center')
151       self.fen_infos.activate(geometry = 'centerscreenalways')
152
153   def close_infos(self,lbl):
154       """
155       Ferme la fenêtre des infos
156       """
157       self.fen_infos.destroy()
158
159   def creer_boutons_extension(self,l_boutons,extension):
160       for bouton in l_boutons :
161           if not bouton :
162               # on veut afficher un bouton vide (=espace entre boutons)
163               Button(self.barreboutons,
164                      image = images.get_image('New24'),
165                      relief = 'flat').pack(side='left')
166               continue
167           nom_fic,commande,texte,statut = bouton
168           commande=getattr(extension,commande)
169           b = Button(self.barreboutons,
170                      image = images.get_image(nom_fic),
171                      command = commande,
172                      relief='flat')
173           b.pack(side='left')
174           b.bind("<Enter>",lambda e,s=self,but=b,t=texte : s.affiche_balloon(e,but,t))
175           b.bind("<Leave>", self.efface_balloon)
176           if statut != 'always':
177               self.l_boutons_a_activer.append(b)
178
179       # inactive les boutons qui doivent l'être tant qu'aucun JDC courant
180       self.inactive_boutons()
181
182