]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Throbber.py
It *does* work now
[wxWidgets.git] / wxPython / demo / Throbber.py
1 #
2 # Throbber.py - Cliff Wells <clifford.wells@attbi.com>
3 #
4 # 11/23/2003 - Jeff Grimmett (grimmtooth@softhome.net)
5 #
6 # o Updated for wx namespace
7 #
8
9 import wx
10 import wx.lib.rcsizer as rcs
11 import wx.lib.throbber as throb
12
13 import throbImages # this was created using a modified version of img2py
14
15 from wx.lib.throbber import __doc__ as docString
16
17 #----------------------------------------------------------------------
18
19 class TestPanel(wx.Panel):
20 def __init__(self, parent, log):
21 wx.Panel.__init__(self, parent, -1)
22 self.log = log
23
24 # create the throbbers
25 self.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." },
38 }
39
40 images = [throbImages.catalog[i].getBitmap()
41 for i in throbImages.index
42 if i not in ['eclouds', 'logo']]
43
44 self.throbbers['plain']['throbber'] = \
45 throb.Throbber(self, -1, images, size=(36, 36),frameDelay = 0.1)
46
47 self.throbbers['reverse']['throbber'] = \
48 throb.Throbber(self, -1, images, frameDelay = 0.07)
49
50 self.throbbers['reverse']['throbber'].Reverse()
51
52 self.throbbers['autoreverse']['throbber'] = \
53 throb.Throbber(self, -1, images, frameDelay = 0.1, reverse = True)
54
55 self.throbbers['autoreverse']['throbber'].sequence.append(0)
56
57 self.throbbers['label']['throbber'] = \
58 throb.Throbber(self, -1, images, frameDelay = 0.1, label = 'Label')
59
60 self.throbbers['label']['throbber'].SetFont(wx.Font(
61 pointSize = 10, family = wx.DEFAULT, style = wx.NORMAL, weight = wx.BOLD
62 ))
63
64 self.throbbers['overlay']['throbber'] = \
65 throb.Throbber(
66 self, -1, images, frameDelay = 0.1,
67 overlay = throbImages.catalog['logo'].getBitmap()
68 )
69
70 self.throbbers['overlay+text']['throbber'] = \
71 throb.Throbber(
72 self, -1, images, frameDelay = 0.1,
73 overlay = throbImages.catalog['logo'].getBitmap(), label = "Python!"
74 )
75
76 self.throbbers['overlay+text']['throbber'].SetFont(wx.Font(
77 pointSize = 8, family = wx.DEFAULT, style = wx.NORMAL, weight = wx.BOLD
78 ))
79
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"
84 )
85
86
87 self.otherThrobber.Bind(wx.EVT_LEFT_DOWN, self.OnClickThrobber)
88
89 box = wx.BoxSizer(wx.VERTICAL)
90 sizer = rcs.RowColSizer()
91 box.Add(sizer, 1, wx.EXPAND|wx.ALL, 5)
92 sizer.AddGrowableCol(1)
93
94 sizer.Add(
95 self.otherThrobber, row = 0, col = 2, rowspan = 4,
96 flag = wx.ALIGN_CENTER_VERTICAL
97 )
98
99 row = 2
100
101 # use a list so we can keep our order
102 for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
103 sizer.Add(
104 self.throbbers[t]['throbber'], row = row, col = 0,
105 flag = wx.ALIGN_CENTER|wx.ALL, border=2
106 )
107
108 sizer.Add(
109 wx.StaticText(self, -1, self.throbbers[t]['text']),
110 row = row, col = 1, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
111 )
112
113 row += 1
114
115 # start and stop buttons
116 startButton = wx.Button(self, -1, "Start")
117 self.Bind(wx.EVT_BUTTON, self.OnStartAnimation, id=startButton.GetId())
118
119 stopButton = wx.Button(self, -1, "Stop")
120 self.Bind(wx.EVT_BUTTON, self.OnStopAnimation, id=stopButton.GetId())
121
122 buttonBox = wx.BoxSizer(wx.HORIZONTAL)
123 buttonBox.AddMany([
124 (startButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
125 (stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
126 ])
127
128 sizer.Add(buttonBox,
129 row = len(self.throbbers) + 3,
130 col = 0,
131 colspan = 3,
132 flag = wx.ALIGN_CENTER
133 )
134
135 self.SetSizer(box)
136 self.SetAutoLayout(True)
137 self.Layout()
138 sizer.SetSizeHints(self)
139 sizer.Fit(self)
140
141 for t in self.throbbers.keys():
142 self.throbbers[t]['throbber'].Start()
143
144 self.otherThrobber.Start()
145 self.otherThrobber.Reverse()
146
147 self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
148
149 def OnDestroy(self, event):
150 self.log.write("got destroy event")
151 event.Skip()
152
153 def OnStartAnimation(self, event):
154 for t in self.throbbers.keys():
155 self.throbbers[t]['throbber'].Start()
156
157 def OnStopAnimation(self, event):
158 for t in self.throbbers.keys():
159 self.throbbers[t]['throbber'].Rest()
160
161 def OnClickThrobber(self, event):
162 if self.otherThrobber.Running():
163 self.otherThrobber.Rest()
164 self.otherThrobber.SetLabel("Start")
165 else:
166 self.otherThrobber.Start()
167 self.otherThrobber.SetLabel("Stop")
168
169 def ShutdownDemo(self):
170 self.otherThrobber.Rest()
171 for t in self.throbbers.keys():
172 self.throbbers[t]['throbber'].Rest()
173
174
175 #----------------------------------------------------------------------
176
177 def runTest(frame, nb, log):
178 if wx.Platform == "__WXMAC__":
179 wx.MessageBox("This demo currently fails on the Mac.",
180 "Sorry")
181 return
182 else:
183 win = TestPanel(nb, log)
184 return win
185
186 #----------------------------------------------------------------------
187
188
189
190 overview = """<html><body>
191 <h4><center>Throbber</center></h4>
192 <p>%s</p>
193 </body></html>
194 """ % docString
195
196
197
198 if __name__ == '__main__':
199 import sys,os
200 import run
201 run.main(['', os.path.basename(sys.argv[0])])