]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Throbber.py
apparently the check for too small rect is needed not only with wxNB_MULTILINE (see...
[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 box = wx.BoxSizer(wx.VERTICAL)
73 sizer = wx.GridBagSizer()
74 box.Add(sizer, 1, wx.EXPAND|wx.ALL, 5)
75 sizer.AddGrowableCol(1)
76
77 row = 2
78
79 # use a list so we can keep our order
80 for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
81 sizer.Add(
82 self.throbbers[t]['throbber'], (row, 0), (1, 1),
83 flag = wx.ALIGN_CENTER|wx.ALL, border=2
84 )
85
86 sizer.Add(
87 wx.StaticText(self, -1, self.throbbers[t]['text']),
88 (row, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
89 )
90
91 row += 1
92
93 # start and stop buttons
94 startButton = wx.Button(self, -1, "Start")
95 self.Bind(wx.EVT_BUTTON, self.OnStartAnimation, startButton)
96
97 stopButton = wx.Button(self, -1, "Stop")
98 self.Bind(wx.EVT_BUTTON, self.OnStopAnimation, stopButton)
99
100 buttonBox = wx.BoxSizer(wx.HORIZONTAL)
101 buttonBox.AddMany([
102 (startButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
103 (stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
104 ])
105
106 sizer.Add(
107 buttonBox, (len(self.throbbers) + 3, 0), (1, 3), flag = wx.ALIGN_CENTER
108 )
109
110 self.SetSizer(box)
111 self.SetAutoLayout(True)
112 self.Layout()
113 sizer.SetSizeHints(self)
114 sizer.Fit(self)
115
116 for t in self.throbbers.keys():
117 self.throbbers[t]['throbber'].Start()
118
119 self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
120
121 def OnDestroy(self, event):
122 self.log.write("got destroy event")
123 event.Skip()
124
125 def OnStartAnimation(self, event):
126 for t in self.throbbers.keys():
127 self.throbbers[t]['throbber'].Start()
128
129 def OnStopAnimation(self, event):
130 for t in self.throbbers.keys():
131 self.throbbers[t]['throbber'].Rest()
132
133 def ShutdownDemo(self):
134 for t in self.throbbers.keys():
135 self.throbbers[t]['throbber'].Rest()
136
137
138 #----------------------------------------------------------------------
139
140 def runTest(frame, nb, log):
141 win = TestPanel(nb, log)
142 return win
143
144 #----------------------------------------------------------------------
145
146
147
148 overview = """<html><body>
149 <h4><center>Throbber</center></h4>
150 <p>%s</p>
151 </body></html>
152 """ % docString
153
154
155
156 if __name__ == '__main__':
157 import sys,os
158 import run
159 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])