]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/Throbber.py
Don't decref if the interpreter is not initialized, (eg. it's in its
[wxWidgets.git] / wxPython / demo / Throbber.py
CommitLineData
8fa876ca
RD
1
2import wx
8fa876ca 3import wx.lib.throbber as throb
1e4a197e 4
1e4a197e
RD
5import throbImages # this was created using a modified version of img2py
6
8fa876ca
RD
7from wx.lib.throbber import __doc__ as docString
8
1e4a197e
RD
9#----------------------------------------------------------------------
10
8fa876ca 11class TestPanel(wx.Panel):
1e4a197e 12 def __init__(self, parent, log):
8fa876ca 13 wx.Panel.__init__(self, parent, -1)
1e4a197e
RD
14 self.log = log
15
16 # create the throbbers
17 self.throbbers = {
18 'plain': { 'throbber': None,
19 'text': "Plain throbber." },
20 'reverse': { 'throbber': None,
21 'text': "This throbber runs in reverse and faster." },
22 'autoreverse': { 'throbber': None,
23 'text': "This throbber switches direction." },
24 'label': { 'throbber': None,
25 'text': "With a label." },
26 'overlay': { 'throbber': None,
27 'text': "With an overlayed image." },
28 'overlay+text': { 'throbber': None,
29 'text': "With a label and an overlayed image." },
30 }
31
32 images = [throbImages.catalog[i].getBitmap()
33 for i in throbImages.index
34 if i not in ['eclouds', 'logo']]
35
8fa876ca
RD
36 self.throbbers['plain']['throbber'] = \
37 throb.Throbber(self, -1, images, size=(36, 36),frameDelay = 0.1)
38
39 self.throbbers['reverse']['throbber'] = \
40 throb.Throbber(self, -1, images, frameDelay = 0.07)
41
1e4a197e 42 self.throbbers['reverse']['throbber'].Reverse()
8fa876ca
RD
43
44 self.throbbers['autoreverse']['throbber'] = \
45 throb.Throbber(self, -1, images, frameDelay = 0.1, reverse = True)
46
1e4a197e 47 self.throbbers['autoreverse']['throbber'].sequence.append(0)
1e4a197e 48
8fa876ca
RD
49 self.throbbers['label']['throbber'] = \
50 throb.Throbber(self, -1, images, frameDelay = 0.1, label = 'Label')
51
52 self.throbbers['label']['throbber'].SetFont(wx.Font(
53 pointSize = 10, family = wx.DEFAULT, style = wx.NORMAL, weight = wx.BOLD
54 ))
55
56 self.throbbers['overlay']['throbber'] = \
57 throb.Throbber(
58 self, -1, images, frameDelay = 0.1,
59 overlay = throbImages.catalog['logo'].getBitmap()
60 )
61
62 self.throbbers['overlay+text']['throbber'] = \
63 throb.Throbber(
64 self, -1, images, frameDelay = 0.1,
65 overlay = throbImages.catalog['logo'].getBitmap(), label = "Python!"
66 )
67
68 self.throbbers['overlay+text']['throbber'].SetFont(wx.Font(
69 pointSize = 8, family = wx.DEFAULT, style = wx.NORMAL, weight = wx.BOLD
70 ))
1e4a197e 71
02b800ce
RD
72 self.customThrobber = \
73 throb.Throbber(self, -1, images, size=(36, 36),
74 frameDelay = 0.1,
75 rest = 4,
76 sequence = [ 1, 5, 2, 7, 3, 6, 4, 4, 4, 4, 7, 2, 2, 0 ]
77 )
78
8fa876ca 79 box = wx.BoxSizer(wx.VERTICAL)
95bfd958 80 sizer = wx.GridBagSizer()
8fa876ca 81 box.Add(sizer, 1, wx.EXPAND|wx.ALL, 5)
1e4a197e
RD
82 sizer.AddGrowableCol(1)
83
1e4a197e 84 row = 2
8fa876ca 85
1e4a197e
RD
86 # use a list so we can keep our order
87 for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
8fa876ca 88 sizer.Add(
95bfd958 89 self.throbbers[t]['throbber'], (row, 0), (1, 1),
8fa876ca
RD
90 flag = wx.ALIGN_CENTER|wx.ALL, border=2
91 )
92
93 sizer.Add(
94 wx.StaticText(self, -1, self.throbbers[t]['text']),
95bfd958 95 (row, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
8fa876ca
RD
96 )
97
1e4a197e
RD
98 row += 1
99
02b800ce
RD
100 # Add custom throbber to sizer.
101 row += 2
102 sizer.Add(
103 self.customThrobber, (row, 0), (1, 1),
104 flag = wx.ALIGN_CENTER|wx.ALL, border=2
105 )
106
107 sizer.Add(
108 wx.StaticText(self, -1, 'with custom & manual sequences'),
109 (row, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
110 )
111
1e4a197e 112 # start and stop buttons
8fa876ca 113 startButton = wx.Button(self, -1, "Start")
95bfd958 114 self.Bind(wx.EVT_BUTTON, self.OnStartAnimation, startButton)
8fa876ca
RD
115
116 stopButton = wx.Button(self, -1, "Stop")
95bfd958 117 self.Bind(wx.EVT_BUTTON, self.OnStopAnimation, stopButton)
1e4a197e 118
8fa876ca 119 buttonBox = wx.BoxSizer(wx.HORIZONTAL)
1e4a197e 120 buttonBox.AddMany([
8fa876ca
RD
121 (startButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
122 (stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
1e4a197e
RD
123 ])
124
95bfd958 125 sizer.Add(
02b800ce 126 buttonBox, (len(self.throbbers) + 2, 0), (1, 3), flag = wx.ALIGN_CENTER
95bfd958 127 )
1e4a197e 128
02b800ce
RD
129 # Buttoms for the custom throbber.
130 nextButton = wx.Button(self, -1, "Next")
131 self.Bind(wx.EVT_BUTTON, self.OnNext, nextButton)
132
133 prevButton = wx.Button(self, -1, "Previous")
134 self.Bind(wx.EVT_BUTTON, self.OnPrevious, prevButton)
135
136 incButton = wx.Button(self, -1, "Increment")
137 self.Bind(wx.EVT_BUTTON, self.OnIncrement, incButton)
138
139 decButton = wx.Button(self, -1, "Decrement")
140 self.Bind(wx.EVT_BUTTON, self.OnDecrement, decButton)
141
142 revButton = wx.Button(self, -1, "Reverse")
143 self.Bind(wx.EVT_BUTTON, self.OnReverse, revButton)
144
145 restButton = wx.Button(self, -1, "Rest")
146 self.Bind(wx.EVT_BUTTON, self.OnRest, restButton)
147
148 startButton = wx.Button(self, -1, "Start")
149 self.Bind(wx.EVT_BUTTON, self.OnStart, startButton)
150
151 stopButton = wx.Button(self, -1, "Stop")
152 self.Bind(wx.EVT_BUTTON, self.OnStop, stopButton)
153
154 customBox1 = wx.BoxSizer(wx.HORIZONTAL)
155 customBox1.AddMany([
156 (nextButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
157 (prevButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
158 (incButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
159 (decButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
160 (revButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
161 ])
162
163 customBox2 = wx.BoxSizer(wx.HORIZONTAL)
164 customBox2.AddMany([
165 (restButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
166 (startButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
167 (stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
168 ])
169
170 sizer.Add( customBox1, (len(self.throbbers) + 5, 0), (1, 3), flag = wx.ALIGN_CENTER )
171 sizer.Add( customBox2, (len(self.throbbers) + 6, 0), (1, 3), flag = wx.ALIGN_CENTER )
172
173 # Layout.
1e4a197e
RD
174 self.SetSizer(box)
175 self.SetAutoLayout(True)
176 self.Layout()
177 sizer.SetSizeHints(self)
178 sizer.Fit(self)
179
180 for t in self.throbbers.keys():
181 self.throbbers[t]['throbber'].Start()
8fa876ca 182
8fa876ca 183 self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
1e4a197e
RD
184
185 def OnDestroy(self, event):
186 self.log.write("got destroy event")
187 event.Skip()
188
189 def OnStartAnimation(self, event):
190 for t in self.throbbers.keys():
191 self.throbbers[t]['throbber'].Start()
192
193 def OnStopAnimation(self, event):
194 for t in self.throbbers.keys():
195 self.throbbers[t]['throbber'].Rest()
196
02b800ce
RD
197 def OnNext(self, event):
198 self.customThrobber.Next()
199
200 def OnPrevious(self, event):
201 self.customThrobber.Previous()
202
203 def OnIncrement(self, event):
204 self.customThrobber.Increment()
205
206 def OnDecrement(self, event):
207 self.customThrobber.Decrement()
208
209 def OnReverse(self, event):
210 self.customThrobber.Reverse()
211
212 def OnRest(self, event):
213 self.customThrobber.Rest()
214
215 def OnStart(self, event):
216 self.customThrobber.Start()
217
218 def OnStop(self, event):
219 self.customThrobber.Stop()
220
1e4a197e 221 def ShutdownDemo(self):
1e4a197e
RD
222 for t in self.throbbers.keys():
223 self.throbbers[t]['throbber'].Rest()
224
225
226#----------------------------------------------------------------------
227
228def runTest(frame, nb, log):
c4ef95da
RD
229 win = TestPanel(nb, log)
230 return win
1e4a197e
RD
231
232#----------------------------------------------------------------------
233
234
235
236overview = """<html><body>
237<h4><center>Throbber</center></h4>
238<p>%s</p>
239</body></html>
240""" % docString
241
242
243
244if __name__ == '__main__':
245 import sys,os
246 import run
8eca4fef 247 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])