2 # Throbber.py - Cliff Wells <clifford.wells@attbi.com>
5 from wxPython
.wx
import *
6 from wxPython
.lib
.rcsizer
import RowColSizer
7 from wxPython
.lib
.throbber
import Throbber
, __doc__
as docString
8 import throbImages
# this was created using a modified version of img2py
10 #----------------------------------------------------------------------
12 class TestPanel(wxPanel
):
13 def __init__(self
, parent
, log
):
14 wxPanel
.__init
__(self
, parent
, -1)
17 # create the throbbers
19 'plain': { 'throbber': None,
20 'text': "Plain throbber." },
21 'reverse': { 'throbber': None,
22 'text': "This throbber runs in reverse and faster." },
23 'autoreverse': { 'throbber': None,
24 'text': "This throbber switches direction." },
25 'label': { 'throbber': None,
26 'text': "With a label." },
27 'overlay': { 'throbber': None,
28 'text': "With an overlayed image." },
29 'overlay+text': { 'throbber': None,
30 'text': "With a label and an overlayed image." },
33 images
= [throbImages
.catalog
[i
].getBitmap()
34 for i
in throbImages
.index
35 if i
not in ['eclouds', 'logo']]
37 self
.throbbers
['plain']['throbber'] = Throbber(self
, -1,
38 images
, size
=(36, 36),
40 self
.throbbers
['reverse']['throbber'] = Throbber(self
, -1, images
, #size=(36, 36),
42 self
.throbbers
['reverse']['throbber'].Reverse()
43 self
.throbbers
['autoreverse']['throbber'] = Throbber(self
, -1,
44 images
, #size=(36, 36),
47 self
.throbbers
['autoreverse']['throbber'].sequence
.append(0)
48 self
.throbbers
['label']['throbber'] = Throbber(self
, -1,
49 images
, #size=(36, 36),
52 self
.throbbers
['label']['throbber'].SetFont(wxFont(pointSize
= 10,
56 self
.throbbers
['overlay']['throbber'] = Throbber(self
, -1,
57 images
, #size=(36, 36),
59 overlay
= throbImages
.catalog
['logo'].getBitmap())
60 self
.throbbers
['overlay+text']['throbber'] = Throbber(self
, -1,
61 images
, #size=(36, 36),
63 overlay
= throbImages
.catalog
['logo'].getBitmap(),
65 self
.throbbers
['overlay+text']['throbber'].SetFont(wxFont(pointSize
= 8,
71 # this throbber is created using a single, composite image
72 self
.otherThrobber
= Throbber(self
, -1,
73 throbImages
.catalog
['eclouds'].getBitmap(), #size=(48, 48),
80 EVT_LEFT_DOWN(self
.otherThrobber
, self
.OnClickThrobber
)
82 box
= wxBoxSizer(wxVERTICAL
)
84 box
.Add(sizer
, 1, wxEXPAND|wxALL
, 5)
85 sizer
.AddGrowableCol(1)
87 sizer
.Add(self
.otherThrobber
, row
= 0, col
= 2, rowspan
= 4, flag
= wxALIGN_CENTER_VERTICAL
)
90 # use a list so we can keep our order
91 for t
in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
92 sizer
.Add(self
.throbbers
[t
]['throbber'], row
= row
, col
= 0, flag
= wxALIGN_CENTER|wxALL
, border
=2)
93 sizer
.Add(wxStaticText(self
, -1, self
.throbbers
[t
]['text']), row
= row
, col
= 1,
94 flag
= wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT
)
97 # start and stop buttons
98 startButton
= wxButton(self
, -1, "Start")
99 EVT_BUTTON(self
, startButton
.GetId(), self
.OnStartAnimation
)
100 stopButton
= wxButton(self
, -1, "Stop")
101 EVT_BUTTON(self
, stopButton
.GetId(), self
.OnStopAnimation
)
103 buttonBox
= wxBoxSizer(wxHORIZONTAL
)
105 (startButton
, 0, wxALIGN_CENTER_HORIZONTAL | wxALL
, 5),
106 (stopButton
, 0, wxALIGN_CENTER_HORIZONTAL | wxALL
, 5),
110 row
= len(self
.throbbers
) + 3,
113 flag
= wxALIGN_CENTER
)
116 self
.SetAutoLayout(True)
118 sizer
.SetSizeHints(self
)
121 for t
in self
.throbbers
.keys():
122 self
.throbbers
[t
]['throbber'].Start()
123 self
.otherThrobber
.Start()
124 self
.otherThrobber
.Reverse()
126 EVT_WINDOW_DESTROY(self
, self
.OnDestroy
)
128 def OnDestroy(self
, event
):
129 self
.log
.write("got destroy event")
132 def OnStartAnimation(self
, event
):
133 for t
in self
.throbbers
.keys():
134 self
.throbbers
[t
]['throbber'].Start()
136 def OnStopAnimation(self
, event
):
137 for t
in self
.throbbers
.keys():
138 self
.throbbers
[t
]['throbber'].Rest()
140 def OnClickThrobber(self
, event
):
141 if self
.otherThrobber
.Running():
142 self
.otherThrobber
.Rest()
143 self
.otherThrobber
.SetLabel("Start")
145 self
.otherThrobber
.Start()
146 self
.otherThrobber
.SetLabel("Stop")
148 def ShutdownDemo(self
):
149 self
.otherThrobber
.Rest()
150 for t
in self
.throbbers
.keys():
151 self
.throbbers
[t
]['throbber'].Rest()
154 #----------------------------------------------------------------------
156 def runTest(frame
, nb
, log
):
157 if wxPlatform
== "__WXMAC__":
158 wxMessageBox("This demo currently fails on the Mac.",
162 win
= TestPanel(nb
, log
)
165 #----------------------------------------------------------------------
169 overview
= """<html><body>
170 <h4><center>Throbber</center></h4>
177 if __name__
== '__main__':
180 run
.main(['', os
.path
.basename(sys
.argv
[0])])