]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Throbber.py
Initialize m_privData before doign the assignment
[wxWidgets.git] / wxPython / demo / Throbber.py
1
2 import wx
3 import wx.lib.throbber as throb
4
5 import throbImages # this was created using a modified version of img2py
6
7 from wx.lib.throbber import __doc__ as docString
8
9 #----------------------------------------------------------------------
10
11 class TestPanel(wx.Panel):
12 def __init__(self, parent, log):
13 wx.Panel.__init__(self, parent, -1)
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
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
42 self.throbbers['reverse']['throbber'].Reverse()
43
44 self.throbbers['autoreverse']['throbber'] = \
45 throb.Throbber(self, -1, images, frameDelay = 0.1, reverse = True)
46
47 self.throbbers['autoreverse']['throbber'].sequence.append(0)
48
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 ))
71
72 # this throbber is created using a single, composite image
73 self.otherThrobber = throb.Throbber(
74 self, -1, throbImages.catalog['eclouds'].getBitmap(), frameDelay = 0.15,
75 frames = 12, frameWidth = 48, label = "Stop"
76 )
77
78
79 self.otherThrobber.Bind(wx.EVT_LEFT_DOWN, self.OnClickThrobber)
80
81 box = wx.BoxSizer(wx.VERTICAL)
82 sizer = wx.GridBagSizer()
83 box.Add(sizer, 1, wx.EXPAND|wx.ALL, 5)
84 sizer.AddGrowableCol(1)
85
86 sizer.Add(self.otherThrobber, (0, 2), (4, 1),flag = wx.ALIGN_CENTER_VERTICAL)
87
88 row = 2
89
90 # use a list so we can keep our order
91 for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
92 sizer.Add(
93 self.throbbers[t]['throbber'], (row, 0), (1, 1),
94 flag = wx.ALIGN_CENTER|wx.ALL, border=2
95 )
96
97 sizer.Add(
98 wx.StaticText(self, -1, self.throbbers[t]['text']),
99 (row, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
100 )
101
102 row += 1
103
104 # start and stop buttons
105 startButton = wx.Button(self, -1, "Start")
106 self.Bind(wx.EVT_BUTTON, self.OnStartAnimation, startButton)
107
108 stopButton = wx.Button(self, -1, "Stop")
109 self.Bind(wx.EVT_BUTTON, self.OnStopAnimation, stopButton)
110
111 buttonBox = wx.BoxSizer(wx.HORIZONTAL)
112 buttonBox.AddMany([
113 (startButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
114 (stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
115 ])
116
117 sizer.Add(
118 buttonBox, (len(self.throbbers) + 3, 0), (1, 3), flag = wx.ALIGN_CENTER
119 )
120
121 self.SetSizer(box)
122 self.SetAutoLayout(True)
123 self.Layout()
124 sizer.SetSizeHints(self)
125 sizer.Fit(self)
126
127 for t in self.throbbers.keys():
128 self.throbbers[t]['throbber'].Start()
129
130 self.otherThrobber.Start()
131 self.otherThrobber.Reverse()
132
133 self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
134
135 def OnDestroy(self, event):
136 self.log.write("got destroy event")
137 event.Skip()
138
139 def OnStartAnimation(self, event):
140 for t in self.throbbers.keys():
141 self.throbbers[t]['throbber'].Start()
142
143 def OnStopAnimation(self, event):
144 for t in self.throbbers.keys():
145 self.throbbers[t]['throbber'].Rest()
146
147 def OnClickThrobber(self, event):
148 if self.otherThrobber.Running():
149 self.otherThrobber.Rest()
150 self.otherThrobber.SetLabel("Start")
151 else:
152 self.otherThrobber.Start()
153 self.otherThrobber.SetLabel("Stop")
154
155 def ShutdownDemo(self):
156 self.otherThrobber.Rest()
157 for t in self.throbbers.keys():
158 self.throbbers[t]['throbber'].Rest()
159
160
161 #----------------------------------------------------------------------
162
163 def runTest(frame, nb, log):
164 win = TestPanel(nb, log)
165 return win
166
167 #----------------------------------------------------------------------
168
169
170
171 overview = """<html><body>
172 <h4><center>Throbber</center></h4>
173 <p>%s</p>
174 </body></html>
175 """ % docString
176
177
178
179 if __name__ == '__main__':
180 import sys,os
181 import run
182 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])