Salome HOME
pour elts de structure
[tools/eficas.git] / Editeur / splash.py
1 # -*- coding: utf-8 -*-
2 #            CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002  EDF R&D                  WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
9 #
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
14 #
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 #    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
18 #
19 #
20 # ======================================================================
21 """
22     Ce module permet de créer, mettre à jour et détruire
23     un écran Splash
24 """
25 from Tkinter import *
26
27 from centerwindow import centerwindow
28 from Tools.foztools.foztools import Slider
29 import fontes
30 import images
31
32 _splash=None
33
34 def init_splash(*pos,**args):
35    global _splash
36    _splash=SplashScreen(*pos,**args)
37
38 def fini_splash():
39    global _splash
40    _splash.quit()
41    _splash=None
42
43 class SplashScreen(Toplevel):
44     """ 
45         Provides a splash screen. Usage:
46         Subclass and override 'CreateWidgets()'
47         In constructor of main window/application call
48            - S = SplashScreen(main=self)        (if caller is Toplevel)
49            - S = SplashScreen(main=self.master) (if caller is Frame)
50            - S.quit()  after you are done creating your widgets etc.
51     """
52     def __init__(self, master=None,**args):
53         Toplevel.__init__(self, master, relief='groove',
54                           borderwidth=5)
55         self.main = master
56         if self.main != None :
57             self.main.iconify()
58         self.withdraw()
59         self.frame = Frame(self)
60         self.frame.pack(expand=1,fill='both')
61         self.init(args)
62         self.geometry("300x200")
63         self.resizable(0,0)
64         centerwindow(self)
65         self.CreateWidgets()
66         self.deiconify()
67
68     def init(self,args={}):
69         self.text = StringVar()
70         self.text.set('')
71         self.text2 = StringVar()
72         self.text2.set('')
73         self.icone = 'logo_edf.gif'
74         self.barre = 'non'
75         if args == {} : return
76         if args.has_key('text'):
77             self.text.set(args['text'])
78         if args.has_key('info'):
79             self.text2.set(args['info'])
80         if args.has_key('titre'):
81             self.title(args['titre'])
82         if args.has_key('code'):
83             self.code = args['code']
84         else:
85             self.code = 'inconnu'
86         if args.has_key('icone'):
87             self.icone = args['icone']
88         if self.code == 'ASTER' :
89             self.icone = 'code_aster.gif'
90         elif self.code == 'SATURNE':
91             self.icone = 'code_saturne.gif'
92         elif self.code == 'DESCARTES':
93             self.icone = 'code_descartes.gif'
94
95     def CreateWidgets(self):
96         self.catIcon = images.get_image(self.icone)
97         self.label = Label(self.frame, image=self.catIcon)
98         self.label.pack(side=TOP)
99         self.label = Label(self.frame, textvariable=self.text,font = fontes.standard_gras)
100         self.label.pack(side=TOP,expand=1,fill='both')
101         self.label2 = Label(self.frame, textvariable=self.text2,font = fontes.standard_italique)
102         self.label2.pack(side=TOP,expand=1,fill='both')
103         self.progress = Slider(self.frame,value=0,max=100,orientation='horizontal',
104                                fillColor='#00008b',width=200,height=30,
105                                background='white',labelColor='red')
106         centerwindow(self)
107
108     def update_barre(self,event=None):
109         """ Permet de faire avancer la barre de progression """
110         try:
111             self.progress.value = self.progress.value+self.increment
112             self.progress.update()
113         except:
114             pass
115
116     def configure_barre(self):
117         """ 
118              Calcule l'incrément de progression de la barre en fonction
119              du nombre d'opérations à effectuer afin que le compteur
120              soit à 100% à la fin des opérations
121         """
122         self.increment = 100./self.ratio
123         self.progress.update()
124
125     def configure(self,**args):
126         if args.has_key('text'):
127             self.text.set(args['text'])
128         if args.has_key('info'):
129             self.text2.set(args['info'])
130         if args.has_key('titre'):
131             self.title(args['titre'])
132         if args.has_key('barre'):
133             old = self.barre
134             self.barre = args['barre']
135             if self.barre == 'oui' and old == 'non':
136                 self.progress.frame.pack(in_=self.frame,side='top')
137             elif self.barre == 'non' and old == 'oui':
138                 self.progress.frame.pack_forget()
139         if args.has_key('ratio'):
140             self.ratio = args['ratio']
141             self.configure_barre()
142         self.update()
143
144     def quit(self):
145         self.progress = None
146         self.destroy()
147         if self.main:
148            centerwindow(self.main,parent='sans')
149            self.main.deiconify()
150