Salome HOME
CCAR: Modified Files:
[tools/eficas.git] / Editeur / splash.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 permet de créer, mettre à jour et détruire
22     un écran Splash
23 """
24 from Tkinter import *
25
26 from centerwindow import centerwindow
27 from Tools.foztools.foztools import Slider
28 import fontes
29 import images
30
31 _splash=None
32
33 def init_splash(*pos,**args):
34    global _splash
35    _splash=SplashScreen(*pos,**args)
36
37 def fini_splash():
38    global _splash
39    _splash.quit()
40    _splash=None
41
42 class SplashScreen(Toplevel):
43     """ 
44         Provides a splash screen. Usage:
45         Subclass and override 'CreateWidgets()'
46         In constructor of main window/application call
47         - S = SplashScreen(main=self)        (if caller is Toplevel)
48         - S = SplashScreen(main=self.master) (if caller is Frame)
49         - S.quit()  after you are done creating your widgets etc.
50     """
51     def __init__(self, master=None,**args):
52         Toplevel.__init__(self, master, relief='groove',
53                           borderwidth=5)
54         self.main = master
55         if self.main != None :
56             self.main.iconify()
57         self.withdraw()
58         self.frame = Frame(self)
59         self.frame.pack(expand=1,fill='both')
60         self.init(args)
61         self.geometry("300x200")
62         self.resizable(0,0)
63         centerwindow(self)
64         self.CreateWidgets()
65         self.deiconify()
66
67     def init(self,args={}):
68         self.text = StringVar()
69         self.text.set('')
70         self.text2 = StringVar()
71         self.text2.set('')
72         self.icone = 'logo_edf.gif'
73         self.barre = 'non'
74         if args == {} : return
75         if args.has_key('text'):
76             self.text.set(args['text'])
77         if args.has_key('info'):
78             self.text2.set(args['info'])
79         if args.has_key('titre'):
80             self.title(args['titre'])
81         if args.has_key('code'):
82             self.code = args['code']
83         else:
84             self.code = 'inconnu'
85         if args.has_key('icone'):
86             self.icone = args['icone']
87         if self.code == 'ASTER' :
88             self.icone = 'code_aster.gif'
89         elif self.code == 'SATURNE':
90             self.icone = 'code_saturne.gif'
91         elif self.code == 'DESCARTES':
92             self.icone = 'code_descartes.gif'
93
94     def CreateWidgets(self):
95         self.catIcon = images.get_image(self.icone)
96         self.label = Label(self.frame, image=self.catIcon)
97         self.label.pack(side=TOP)
98         self.label = Label(self.frame, textvariable=self.text,font = fontes.standard_gras)
99         self.label.pack(side=TOP,expand=1,fill='both')
100         self.label2 = Label(self.frame, textvariable=self.text2,font = fontes.standard_italique)
101         self.label2.pack(side=TOP,expand=1,fill='both')
102         self.progress = Slider(self.frame,value=0,max=100,orientation='horizontal',
103                                fillColor='#00008b',width=200,height=30,
104                                background='white',labelColor='red')
105         centerwindow(self)
106
107     def update_barre(self,event=None):
108         """ Permet de faire avancer la barre de progression """
109         try:
110             self.progress.value = self.progress.value+self.increment
111             self.progress.update()
112         except:
113             pass
114
115     def configure_barre(self):
116         """ 
117              Calcule l'incrément de progression de la barre en fonction
118              du nombre d'opérations à effectuer afin que le compteur
119              soit à 100% à la fin des opérations
120         """
121         self.increment = 100./self.ratio
122         self.progress.update()
123
124     def configure(self,**args):
125         if args.has_key('text'):
126             self.text.set(args['text'])
127         if args.has_key('info'):
128             self.text2.set(args['info'])
129         if args.has_key('titre'):
130             self.title(args['titre'])
131         if args.has_key('barre'):
132             old = self.barre
133             self.barre = args['barre']
134             if self.barre == 'oui' and old == 'non':
135                 self.progress.frame.pack(in_=self.frame,side='top')
136             elif self.barre == 'non' and old == 'oui':
137                 self.progress.frame.pack_forget()
138         if args.has_key('ratio'):
139             self.ratio = args['ratio']
140             self.configure_barre()
141         self.update()
142
143     def quit(self):
144         self.progress = None
145         self.destroy()
146         if self.main:
147            self.main.update()
148            self.main.deiconify()
149            centerwindow(self.main,parent='sans')
150