]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/Throbber.py
Updated the description of wx.PopupTransientWindow
[wxWidgets.git] / wxPython / demo / Throbber.py
CommitLineData
1e4a197e
RD
1#
2# Throbber.py - Cliff Wells <clifford.wells@attbi.com>
3#
8fa876ca
RD
4# 11/23/2003 - Jeff Grimmett (grimmtooth@softhome.net)
5#
6# o Updated for wx namespace
7#
8
9import wx
10import wx.lib.rcsizer as rcs
11import wx.lib.throbber as throb
1e4a197e 12
1e4a197e
RD
13import throbImages # this was created using a modified version of img2py
14
8fa876ca
RD
15from wx.lib.throbber import __doc__ as docString
16
1e4a197e
RD
17#----------------------------------------------------------------------
18
8fa876ca 19class TestPanel(wx.Panel):
1e4a197e 20 def __init__(self, parent, log):
8fa876ca 21 wx.Panel.__init__(self, parent, -1)
1e4a197e
RD
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
8fa876ca
RD
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
1e4a197e 50 self.throbbers['reverse']['throbber'].Reverse()
8fa876ca
RD
51
52 self.throbbers['autoreverse']['throbber'] = \
53 throb.Throbber(self, -1, images, frameDelay = 0.1, reverse = True)
54
1e4a197e 55 self.throbbers['autoreverse']['throbber'].sequence.append(0)
1e4a197e 56
8fa876ca
RD
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 ))
1e4a197e
RD
79
80 # this throbber is created using a single, composite image
8fa876ca
RD
81 self.otherThrobber = throb.Throbber(
82 self, -1, throbImages.catalog['eclouds'].getBitmap(), frameDelay = 0.15,
83 frames = 12, frameWidth = 48, label = "Stop"
84 )
1e4a197e
RD
85
86
8fa876ca 87 self.otherThrobber.Bind(wx.EVT_LEFT_DOWN, self.OnClickThrobber)
1e4a197e 88
8fa876ca
RD
89 box = wx.BoxSizer(wx.VERTICAL)
90 sizer = rcs.RowColSizer()
91 box.Add(sizer, 1, wx.EXPAND|wx.ALL, 5)
1e4a197e
RD
92 sizer.AddGrowableCol(1)
93
8fa876ca
RD
94 sizer.Add(
95 self.otherThrobber, row = 0, col = 2, rowspan = 4,
96 flag = wx.ALIGN_CENTER_VERTICAL
97 )
1e4a197e
RD
98
99 row = 2
8fa876ca 100
1e4a197e
RD
101 # use a list so we can keep our order
102 for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
8fa876ca
RD
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
1e4a197e
RD
113 row += 1
114
115 # start and stop buttons
8fa876ca
RD
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())
1e4a197e 121
8fa876ca 122 buttonBox = wx.BoxSizer(wx.HORIZONTAL)
1e4a197e 123 buttonBox.AddMany([
8fa876ca
RD
124 (startButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
125 (stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
1e4a197e
RD
126 ])
127
128 sizer.Add(buttonBox,
129 row = len(self.throbbers) + 3,
130 col = 0,
131 colspan = 3,
8fa876ca
RD
132 flag = wx.ALIGN_CENTER
133 )
1e4a197e
RD
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()
8fa876ca 143
1e4a197e
RD
144 self.otherThrobber.Start()
145 self.otherThrobber.Reverse()
146
8fa876ca 147 self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
1e4a197e
RD
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
177def runTest(frame, nb, log):
8fa876ca
RD
178 if wx.Platform == "__WXMAC__":
179 wx.MessageBox("This demo currently fails on the Mac.",
1e4a197e
RD
180 "Sorry")
181 return
182 else:
183 win = TestPanel(nb, log)
184 return win
185
186#----------------------------------------------------------------------
187
188
189
190overview = """<html><body>
191<h4><center>Throbber</center></h4>
192<p>%s</p>
193</body></html>
194""" % docString
195
196
197
198if __name__ == '__main__':
199 import sys,os
200 import run
201 run.main(['', os.path.basename(sys.argv[0])])