2 # Throbber.py - Cliff Wells <clifford.wells@attbi.com>
4 # 11/23/2003 - Jeff Grimmett (grimmtooth@softhome.net)
6 # o Updated for wx namespace
10 import wx
.lib
.rcsizer
as rcs
11 import wx
.lib
.throbber
as throb
13 import throbImages
# this was created using a modified version of img2py
15 from wx
.lib
.throbber
import __doc__
as docString
17 #----------------------------------------------------------------------
19 class TestPanel(wx
.Panel
):
20 def __init__(self
, parent
, log
):
21 wx
.Panel
.__init
__(self
, parent
, -1)
24 # create the throbbers
26 'plain': { 'throbber': None,
27 'text': "Plain throbber." },
28 'reverse': { 'throbber': None,
29 'text': "This throbber runs in reverse and faster." },
30 'autoreverse': { 'throbber': None,
31 'text': "This throbber switches direction." },
32 'label': { 'throbber': None,
33 'text': "With a label." },
34 'overlay': { 'throbber': None,
35 'text': "With an overlayed image." },
36 'overlay+text': { 'throbber': None,
37 'text': "With a label and an overlayed image." },
40 images
= [throbImages
.catalog
[i
].getBitmap()
41 for i
in throbImages
.index
42 if i
not in ['eclouds', 'logo']]
44 self
.throbbers
['plain']['throbber'] = \
45 throb
.Throbber(self
, -1, images
, size
=(36, 36),frameDelay
= 0.1)
47 self
.throbbers
['reverse']['throbber'] = \
48 throb
.Throbber(self
, -1, images
, frameDelay
= 0.07)
50 self
.throbbers
['reverse']['throbber'].Reverse()
52 self
.throbbers
['autoreverse']['throbber'] = \
53 throb
.Throbber(self
, -1, images
, frameDelay
= 0.1, reverse
= True)
55 self
.throbbers
['autoreverse']['throbber'].sequence
.append(0)
57 self
.throbbers
['label']['throbber'] = \
58 throb
.Throbber(self
, -1, images
, frameDelay
= 0.1, label
= 'Label')
60 self
.throbbers
['label']['throbber'].SetFont(wx
.Font(
61 pointSize
= 10, family
= wx
.DEFAULT
, style
= wx
.NORMAL
, weight
= wx
.BOLD
64 self
.throbbers
['overlay']['throbber'] = \
66 self
, -1, images
, frameDelay
= 0.1,
67 overlay
= throbImages
.catalog
['logo'].getBitmap()
70 self
.throbbers
['overlay+text']['throbber'] = \
72 self
, -1, images
, frameDelay
= 0.1,
73 overlay
= throbImages
.catalog
['logo'].getBitmap(), label
= "Python!"
76 self
.throbbers
['overlay+text']['throbber'].SetFont(wx
.Font(
77 pointSize
= 8, family
= wx
.DEFAULT
, style
= wx
.NORMAL
, weight
= wx
.BOLD
80 # this throbber is created using a single, composite image
81 self
.otherThrobber
= throb
.Throbber(
82 self
, -1, throbImages
.catalog
['eclouds'].getBitmap(), frameDelay
= 0.15,
83 frames
= 12, frameWidth
= 48, label
= "Stop"
87 self
.otherThrobber
.Bind(wx
.EVT_LEFT_DOWN
, self
.OnClickThrobber
)
89 box
= wx
.BoxSizer(wx
.VERTICAL
)
90 sizer
= rcs
.RowColSizer()
91 box
.Add(sizer
, 1, wx
.EXPAND|wx
.ALL
, 5)
92 sizer
.AddGrowableCol(1)
95 self
.otherThrobber
, row
= 0, col
= 2, rowspan
= 4,
96 flag
= wx
.ALIGN_CENTER_VERTICAL
101 # use a list so we can keep our order
102 for t
in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
104 self
.throbbers
[t
]['throbber'], row
= row
, col
= 0,
105 flag
= wx
.ALIGN_CENTER|wx
.ALL
, border
=2
109 wx
.StaticText(self
, -1, self
.throbbers
[t
]['text']),
110 row
= row
, col
= 1, flag
= wx
.ALIGN_CENTER_VERTICAL | wx
.ALIGN_LEFT
115 # start and stop buttons
116 startButton
= wx
.Button(self
, -1, "Start")
117 self
.Bind(wx
.EVT_BUTTON
, self
.OnStartAnimation
, id=startButton
.GetId())
119 stopButton
= wx
.Button(self
, -1, "Stop")
120 self
.Bind(wx
.EVT_BUTTON
, self
.OnStopAnimation
, id=stopButton
.GetId())
122 buttonBox
= wx
.BoxSizer(wx
.HORIZONTAL
)
124 (startButton
, 0, wx
.ALIGN_CENTER_HORIZONTAL | wx
.ALL
, 5),
125 (stopButton
, 0, wx
.ALIGN_CENTER_HORIZONTAL | wx
.ALL
, 5),
129 row
= len(self
.throbbers
) + 3,
132 flag
= wx
.ALIGN_CENTER
136 self
.SetAutoLayout(True)
138 sizer
.SetSizeHints(self
)
141 for t
in self
.throbbers
.keys():
142 self
.throbbers
[t
]['throbber'].Start()
144 self
.otherThrobber
.Start()
145 self
.otherThrobber
.Reverse()
147 self
.Bind(wx
.EVT_WINDOW_DESTROY
, self
.OnDestroy
)
149 def OnDestroy(self
, event
):
150 self
.log
.write("got destroy event")
153 def OnStartAnimation(self
, event
):
154 for t
in self
.throbbers
.keys():
155 self
.throbbers
[t
]['throbber'].Start()
157 def OnStopAnimation(self
, event
):
158 for t
in self
.throbbers
.keys():
159 self
.throbbers
[t
]['throbber'].Rest()
161 def OnClickThrobber(self
, event
):
162 if self
.otherThrobber
.Running():
163 self
.otherThrobber
.Rest()
164 self
.otherThrobber
.SetLabel("Start")
166 self
.otherThrobber
.Start()
167 self
.otherThrobber
.SetLabel("Stop")
169 def ShutdownDemo(self
):
170 self
.otherThrobber
.Rest()
171 for t
in self
.throbbers
.keys():
172 self
.throbbers
[t
]['throbber'].Rest()
175 #----------------------------------------------------------------------
177 def runTest(frame
, nb
, log
):
178 if wx
.Platform
== "__WXMAC__":
179 wx
.MessageBox("This demo currently fails on the Mac.",
183 win
= TestPanel(nb
, log
)
186 #----------------------------------------------------------------------
190 overview
= """<html><body>
191 <h4><center>Throbber</center></h4>
198 if __name__
== '__main__':
201 run
.main(['', os
.path
.basename(sys
.argv
[0])])