]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Throbber.py
fixed enumerating of entries/groups under '/' in wxRegConfig
[wxWidgets.git] / wxPython / demo / Throbber.py
1 #
2 # Throbber.py - Cliff Wells <clifford.wells@attbi.com>
3 #
4
5 from wxPython.wx import *
6 from wxPython.lib.rcsizer import RowColSizer
7 from wxPython.lib.throbber import Throbber, __doc__ as docString
8 import throbImages # this was created using a modified version of img2py
9
10 #----------------------------------------------------------------------
11
12 class TestPanel(wxPanel):
13 def __init__(self, parent, log):
14 wxPanel.__init__(self, parent, -1)
15 self.log = log
16
17 # create the throbbers
18 self.throbbers = {
19 'plain': { 'throbber': None,
20 'text': "Plain throbber." },
21 'reverse': { 'throbber': None,
22 'text': "This throbber runs in reverse and faster." },
23 'autoreverse': { 'throbber': None,
24 'text': "This throbber switches direction." },
25 'label': { 'throbber': None,
26 'text': "With a label." },
27 'overlay': { 'throbber': None,
28 'text': "With an overlayed image." },
29 'overlay+text': { 'throbber': None,
30 'text': "With a label and an overlayed image." },
31 }
32
33 images = [throbImages.catalog[i].getBitmap()
34 for i in throbImages.index
35 if i not in ['eclouds', 'logo']]
36
37 self.throbbers['plain']['throbber'] = Throbber(self, -1,
38 images, size=(36, 36),
39 frameDelay = 0.1)
40 self.throbbers['reverse']['throbber'] = Throbber(self, -1, images, #size=(36, 36),
41 frameDelay = 0.07)
42 self.throbbers['reverse']['throbber'].Reverse()
43 self.throbbers['autoreverse']['throbber'] = Throbber(self, -1,
44 images, #size=(36, 36),
45 frameDelay = 0.1,
46 reverse = True)
47 self.throbbers['autoreverse']['throbber'].sequence.append(0)
48 self.throbbers['label']['throbber'] = Throbber(self, -1,
49 images, #size=(36, 36),
50 frameDelay = 0.1,
51 label = 'Label')
52 self.throbbers['label']['throbber'].SetFont(wxFont(pointSize = 10,
53 family = wxDEFAULT,
54 style = wxNORMAL,
55 weight = wxBOLD))
56 self.throbbers['overlay']['throbber'] = Throbber(self, -1,
57 images, #size=(36, 36),
58 frameDelay = 0.1,
59 overlay = throbImages.catalog['logo'].getBitmap())
60 self.throbbers['overlay+text']['throbber'] = Throbber(self, -1,
61 images, #size=(36, 36),
62 frameDelay = 0.1,
63 overlay = throbImages.catalog['logo'].getBitmap(),
64 label = "Python!")
65 self.throbbers['overlay+text']['throbber'].SetFont(wxFont(pointSize = 8,
66 family = wxDEFAULT,
67 style = wxNORMAL,
68 weight = wxBOLD))
69
70
71 # this throbber is created using a single, composite image
72 self.otherThrobber = Throbber(self, -1,
73 throbImages.catalog['eclouds'].getBitmap(), #size=(48, 48),
74 frameDelay = 0.15,
75 frames = 12,
76 frameWidth = 48,
77 label = "Stop")
78
79
80 EVT_LEFT_DOWN(self.otherThrobber, self.OnClickThrobber)
81
82 box = wxBoxSizer(wxVERTICAL)
83 sizer = RowColSizer()
84 box.Add(sizer, 1, wxEXPAND|wxALL, 5)
85 sizer.AddGrowableCol(1)
86
87 sizer.Add(self.otherThrobber, row = 0, col = 2, rowspan = 4, flag = wxALIGN_CENTER_VERTICAL)
88
89 row = 2
90 # use a list so we can keep our order
91 for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
92 sizer.Add(self.throbbers[t]['throbber'], row = row, col = 0, flag = wxALIGN_CENTER|wxALL, border=2)
93 sizer.Add(wxStaticText(self, -1, self.throbbers[t]['text']), row = row, col = 1,
94 flag = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT)
95 row += 1
96
97 # start and stop buttons
98 startButton = wxButton(self, -1, "Start")
99 EVT_BUTTON(self, startButton.GetId(), self.OnStartAnimation)
100 stopButton = wxButton(self, -1, "Stop")
101 EVT_BUTTON(self, stopButton.GetId(), self.OnStopAnimation)
102
103 buttonBox = wxBoxSizer(wxHORIZONTAL)
104 buttonBox.AddMany([
105 (startButton, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5),
106 (stopButton, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5),
107 ])
108
109 sizer.Add(buttonBox,
110 row = len(self.throbbers) + 3,
111 col = 0,
112 colspan = 3,
113 flag = wxALIGN_CENTER)
114
115 self.SetSizer(box)
116 self.SetAutoLayout(True)
117 self.Layout()
118 sizer.SetSizeHints(self)
119 sizer.Fit(self)
120
121 for t in self.throbbers.keys():
122 self.throbbers[t]['throbber'].Start()
123 self.otherThrobber.Start()
124 self.otherThrobber.Reverse()
125
126 EVT_WINDOW_DESTROY(self, self.OnDestroy)
127
128 def OnDestroy(self, event):
129 self.log.write("got destroy event")
130 event.Skip()
131
132 def OnStartAnimation(self, event):
133 for t in self.throbbers.keys():
134 self.throbbers[t]['throbber'].Start()
135
136 def OnStopAnimation(self, event):
137 for t in self.throbbers.keys():
138 self.throbbers[t]['throbber'].Rest()
139
140 def OnClickThrobber(self, event):
141 if self.otherThrobber.Running():
142 self.otherThrobber.Rest()
143 self.otherThrobber.SetLabel("Start")
144 else:
145 self.otherThrobber.Start()
146 self.otherThrobber.SetLabel("Stop")
147
148 def ShutdownDemo(self):
149 self.otherThrobber.Rest()
150 for t in self.throbbers.keys():
151 self.throbbers[t]['throbber'].Rest()
152
153
154 #----------------------------------------------------------------------
155
156 def runTest(frame, nb, log):
157 if wxPlatform == "__WXMAC__":
158 wxMessageBox("This demo currently fails on the Mac.",
159 "Sorry")
160 return
161 else:
162 win = TestPanel(nb, log)
163 return win
164
165 #----------------------------------------------------------------------
166
167
168
169 overview = """<html><body>
170 <h4><center>Throbber</center></h4>
171 <p>%s</p>
172 </body></html>
173 """ % docString
174
175
176
177 if __name__ == '__main__':
178 import sys,os
179 import run
180 run.main(['', os.path.basename(sys.argv[0])])