Salome HOME
CCAR: Correction du pb AO2001-474, SD non nommée : impossible de la renommer ensuite
[tools/eficas.git] / Editeur / appli.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     Ce module contient la classe APPLI qui est la classe mère de
22     l'application EFICAS. Elle prend en charge l'organisation générale
23     des composants graphiques et l'initialisation Tk
24     L'aspect applicatif doit etre pris en charge par la classe dérivée
25 """
26 # Modules Python
27 import sys
28 import types
29 import Pmw
30 import Tkinter
31
32 # Modules Eficas
33 import splash
34 import prefs
35 import fontes
36 import tooltip
37
38 VERSION="EFICAS v1.3"
39
40 class APPLI: 
41   def __init__ (self,master,code='ASTER',fichier=None) :
42       self.top=master
43       self.code=code
44       self.top.protocol("WM_DELETE_WINDOW",self.exitEFICAS)
45       self.top.minsize(900,500)
46       self.top.geometry("900x500")
47       self.top.title(VERSION + ' pour '+self.code)
48       self.top.withdraw()
49       self.initializeTk(master)
50       Pmw.initialise(master)
51       self.lecture_parametres()
52       self.format_fichier = Tkinter.StringVar()
53       self.message=''
54       self.cree_composants_graphiques()
55       self.load_appli_composants()
56       self.affiche_FAQ()
57       splash.fini_splash()
58
59   def send_message(self,message):
60       self.message=message
61
62   def exitEFICAS(self):
63       self.quit()
64
65   def quit(self):
66       self.top.quit()
67
68   def lecture_parametres(self):
69       """
70           Active la lecture des paramètres standards et utilisateur
71       """
72       splash._splash.configure(text = "Chargement des paramètres utilisateur")
73       import configuration
74       self.CONFIGURATION = configuration.make_config(self,prefs.REPINI)
75
76   def cree_composants_graphiques(self):
77       """
78           Cree les constituants de l'application :
79            - menubar
80            - tollbar
81            - bureau
82            - statusbar
83       """
84       splash._splash.configure(text = "Chargement de l'IHM")
85       splash._splash.configure(text = "Chargement de la menubar")
86       import menubar
87       self.menubar=menubar.MENUBAR(self,self.top)
88       splash._splash.configure(text = "Chargement de la toolbar")
89       import toolbar
90       self.toolbar=toolbar.TOOLBAR(self,self.top)
91       splash._splash.configure(text = "Chargement de la statusbar")
92       import statusbar
93       self.statusbar=statusbar.STATUSBAR(self.top)
94
95   def load_appli_composants(self):
96       splash._splash.configure(text = "Chargement des appli_composants")
97       for mname in self.appli_composants:
98          self.load_appli_composant(mname)
99
100   def load_appli_composant(self,mname):
101       module=__import__(mname,globals(),locals())
102       factory=getattr(module,mname.upper())
103       appli_composant=factory(self,self.top)
104       setattr(self,mname,appli_composant)
105       self.fill_menus(appli_composant,appli_composant.menu_defs)
106       self.toolbar.creer_boutons_appli_composant(appli_composant.button_defs,appli_composant)
107
108   def affiche_FAQ(self):
109       import faq
110       faq.affiche(self.top)
111
112   def affiche_infos(self,message):
113       self.statusbar.affiche_infos(message)
114       return
115
116   def  initializeTk(self, root):
117         """
118         Initialize platform specific options
119         """
120         if sys.platform == 'mac':
121             self.initializeTk_mac(root)
122         elif sys.platform == 'win32':
123             self.initializeTk_win32(root)
124         else:
125             self.initializeTk_unix(root)
126
127   def initializeTk_win32(self, root):
128         root.option_add('*Font', fontes.standard)
129         root.option_add('*EntryField.Entry.Font', fontes.standard)
130         root.option_add('*Listbox*Font',fontes.standard)
131
132   def initializeTk_colors_common(self, root):
133         root.option_add('*background', 'grey')
134         root.option_add('*foreground', 'black')
135         root.option_add('*EntryField.Entry.background', 'white')
136         root.option_add('*Entry*background', 'white')
137         root.option_add('*Listbox*background', 'white')
138         root.option_add('*Listbox*selectBackground', '#00008b')
139         root.option_add('*Listbox*selectForeground', 'white')
140
141   def initializeTk_mac(self, root):
142         self.initializeTk_colors_common(root)
143
144   def initializeTk_unix(self, root):
145       root.option_add('*Font', fontes.standard)
146       root.option_add('*EntryField.Entry.Font',fontes.standard )
147       root.option_add('*Listbox*Font', fontes.standard)
148       self.initializeTk_colors_common(root)
149
150   def get_texte_infos(self):
151       """
152           Retourne un texte d'informations sur la session courante d'EFICAS
153       """
154       texte = VERSION + '\n\n'
155       texte = texte + 'EFICAS est un produit développé par \nEDF-Division Stratégie et Développement\n'
156       texte = texte + 'Equipe : MTI/MMN\n\n'
157       texte = texte + 'Code utilisé : %s\n' %self.code
158       return texte
159
160   def efface_aide(self,event):
161       """
162           Efface la bulle d'aide d'un panneau
163       """
164       try:
165           self.aide.destroy()
166       except:
167           pass
168       return
169
170   def affiche_aide(self,event,aide):
171       """
172           Affiche l'aide concernant un panneau
173       """
174       x=event.x
175       y=event.y
176       widget=event.widget
177       self.aide=tooltip.TOOLTIP(widget)
178       self.aide.xoffset = 10
179       self.aide.yoffset = - widget.winfo_height()/2
180       self.aide.setText(aide)
181       self.aide._showTip()
182       return 
183
184   def cree_menu(self,menu,itemlist,appli_composant):
185       """
186           Ajoute les items du tuple itemlist
187           dans le menu menu
188       """
189       number_item=0
190       radio=None
191       for item in itemlist:
192          number_item=number_item + 1
193          if not item :
194             menu.add_separator()
195          else:
196             label,method=item
197             if type(method) == types.TupleType:
198                # On a un tuple => on cree une cascade
199                menu_cascade=Tkinter.Menu(menu)
200                menu.add_cascade(label=label,menu=menu_cascade)
201                self.cree_menu(menu_cascade,method,appli_composant)
202             elif method[0] == '&':
203                # On a une chaine avec & en tete => on cree un radiobouton
204                command=getattr(appli_composant,method[1:])
205                menu.add_radiobutton(label=label,command=command)
206                if radio == None:radio=number_item
207             else:
208                command=getattr(appli_composant,method)
209                menu.add_command(label=label,command=command)
210       # Si au moins un radiobouton existe on invoke le premier
211       if radio:menu.invoke(radio)
212
213   def fill_menus(self,appli_composant,defs):
214       menudict=self.menubar.menudict
215       for mname,itemlist in defs:
216           menu=menudict.get(mname)
217           if not menu:continue
218           self.cree_menu(menu,itemlist,appli_composant)