Salome HOME
CCAR: evolution demandee dans la fiche EO2001-066 : on peut specifier dans editeur.ini
[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 Pmw
29 import Tkinter
30
31 # Modules Eficas
32 import splash
33 import prefs
34 import fontes
35 import tooltip
36
37 VERSION="EFICAS v1.3"
38
39 class APPLI: 
40   def __init__ (self,master,code='ASTER',fichier=None) :
41       self.top=master
42       self.code=code
43       self.top.protocol("WM_DELETE_WINDOW",self.exitEFICAS)
44       self.top.minsize(900,500)
45       self.top.geometry("900x500")
46       self.top.title(VERSION + ' pour '+self.code)
47       self.top.withdraw()
48       self.initializeTk(master)
49       Pmw.initialise(master)
50       self.lecture_parametres()
51       self.format_fichier = Tkinter.StringVar()
52       self.message=''
53       self.cree_composants_graphiques()
54       self.load_appli_composants()
55       self.affiche_FAQ()
56       splash.fini_splash()
57
58   def send_message(self,message):
59       self.message=message
60
61   def exitEFICAS(self):
62       self.quit()
63
64   def quit(self):
65       self.top.quit()
66
67   def lecture_parametres(self):
68       """
69           Active la lecture des paramètres standards et utilisateur
70       """
71       splash._splash.configure(text = "Chargement des paramètres utilisateur")
72       import configuration
73       self.CONFIGURATION = configuration.make_config(self,prefs.REPINI)
74
75   def cree_composants_graphiques(self):
76       """
77           Cree les constituants de l'application :
78            - menubar
79            - tollbar
80            - bureau
81            - statusbar
82       """
83       splash._splash.configure(text = "Chargement de l'IHM")
84       splash._splash.configure(text = "Chargement de la menubar")
85       import menubar
86       self.menubar=menubar.MENUBAR(self,self.top)
87       splash._splash.configure(text = "Chargement de la toolbar")
88       import toolbar
89       self.toolbar=toolbar.TOOLBAR(self,self.top)
90       splash._splash.configure(text = "Chargement de la statusbar")
91       import statusbar
92       self.statusbar=statusbar.STATUSBAR(self.top)
93
94   def load_appli_composants(self):
95       splash._splash.configure(text = "Chargement des appli_composants")
96       for mname in self.appli_composants:
97          self.load_appli_composant(mname)
98
99   def load_appli_composant(self,mname):
100       module=__import__(mname,globals(),locals())
101       factory=getattr(module,mname.upper())
102       appli_composant=factory(self,self.top)
103       setattr(self,mname,appli_composant)
104       self.fill_menus(appli_composant,appli_composant.menu_defs)
105       self.toolbar.creer_boutons_appli_composant(appli_composant.button_defs,appli_composant)
106
107   def affiche_FAQ(self):
108       import faq
109       faq.affiche(self.top)
110
111   def affiche_infos(self,message):
112       self.statusbar.affiche_infos(message)
113       return
114
115   def  initializeTk(self, root):
116         """
117         Initialize platform specific options
118         """
119         if sys.platform == 'mac':
120             self.initializeTk_mac(root)
121         elif sys.platform == 'win32':
122             self.initializeTk_win32(root)
123         else:
124             self.initializeTk_unix(root)
125
126   def initializeTk_win32(self, root):
127         root.option_add('*Font', fontes.standard)
128         root.option_add('*EntryField.Entry.Font', fontes.standard)
129         root.option_add('*Listbox*Font',fontes.standard)
130
131   def initializeTk_colors_common(self, root):
132         root.option_add('*background', 'grey')
133         root.option_add('*foreground', 'black')
134         root.option_add('*EntryField.Entry.background', 'white')
135         root.option_add('*Entry*background', 'white')
136         root.option_add('*Listbox*background', 'white')
137         root.option_add('*Listbox*selectBackground', '#00008b')
138         root.option_add('*Listbox*selectForeground', 'white')
139
140   def initializeTk_mac(self, root):
141         self.initializeTk_colors_common(root)
142
143   def initializeTk_unix(self, root):
144       root.option_add('*Font', fontes.standard)
145       root.option_add('*EntryField.Entry.Font',fontes.standard )
146       root.option_add('*Listbox*Font', fontes.standard)
147       self.initializeTk_colors_common(root)
148
149   def get_texte_infos(self):
150       """
151           Retourne un texte d'informations sur la session courante d'EFICAS
152       """
153       texte = VERSION + '\n\n'
154       texte = texte + 'EFICAS est un produit développé par \nEDF-Division Stratégie et Développement\n'
155       texte = texte + 'Equipe : MTI/MMN\n\n'
156       texte = texte + 'Code utilisé : %s\n' %self.code
157       return texte
158
159   def efface_aide(self,event):
160       """
161           Efface la bulle d'aide d'un panneau
162       """
163       try:
164           self.aide.destroy()
165       except:
166           pass
167       return
168
169   def affiche_aide(self,event,aide):
170       """
171           Affiche l'aide concernant un panneau
172       """
173       x=event.x
174       y=event.y
175       widget=event.widget
176       self.aide=tooltip.TOOLTIP(widget)
177       self.aide.xoffset = 10
178       self.aide.yoffset = - widget.winfo_height()/2
179       self.aide.setText(aide)
180       self.aide._showTip()
181       return 
182
183   def fill_menus(self,appli_composant,defs):
184       menudict=self.menubar.menudict
185       for mname,itemlist in defs:
186           menu=menudict.get(mname)
187           if not menu:continue
188           for item in itemlist:
189              if not item :
190                 menu.add_separator()
191              else:
192                 label,method=item
193                 command=getattr(appli_composant,method)
194                 menu.add_command(label=label,command=command)
195                 
196