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