log dans un fichier horodaté.
[minwii.git] / src / pgu / gui / misc.py
1 from const import *
2 import widget
3 import pguglobals
4
5 class ProgressBar(widget.Widget):
6 """A progress bar.
7
8 <pre>ProgressBar(value,min,max)</pre>
9
10 <dl>
11 <dt>value<dd>starting value
12 <dt>min<dd>minimum value rendered on the screen (usually 0)
13 <dt>max<dd>maximum value
14 </dl>
15
16 <strong>Example</strong>
17 <code>
18 w = gui.ProgressBar(0,0,100)
19 w.value = 25
20 </code>
21 """
22
23 def __init__(self,value,min,max,**params):
24 params.setdefault('cls','progressbar')
25 widget.Widget.__init__(self,**params)
26 self.min,self.max,self.value = min,max,value
27
28 def paint(self,s):
29 r = pygame.rect.Rect(0,0,self.rect.w,self.rect.h)
30 r.w = r.w*(self.value-self.min)/(self.max-self.min)
31 self.bar = r
32 pguglobals.app.theme.render(s,self.style.bar,r)
33
34 def __setattr__(self,k,v):
35 if k == 'value':
36 v = int(v)
37 v = max(v,self.min)
38 v = min(v,self.max)
39 _v = self.__dict__.get(k,NOATTR)
40 self.__dict__[k]=v
41 if k == 'value' and _v != NOATTR and _v != v:
42 self.send(CHANGE)
43 self.repaint()