2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
import wx
|
|
|
|
import wx.lib.throbber as throb
|
2003-03-25 01:35:27 -05:00
|
|
|
|
|
|
|
import throbImages # this was created using a modified version of img2py
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
from wx.lib.throbber import __doc__ as docString
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPanel(wx.Panel):
|
2003-03-25 01:35:27 -05:00
|
|
|
def __init__(self, parent, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2003-03-25 01:35:27 -05:00
|
|
|
self.log = log
|
|
|
|
|
|
|
|
# create the throbbers
|
|
|
|
self.throbbers = {
|
|
|
|
'plain': { 'throbber': None,
|
|
|
|
'text': "Plain throbber." },
|
|
|
|
'reverse': { 'throbber': None,
|
|
|
|
'text': "This throbber runs in reverse and faster." },
|
|
|
|
'autoreverse': { 'throbber': None,
|
|
|
|
'text': "This throbber switches direction." },
|
|
|
|
'label': { 'throbber': None,
|
|
|
|
'text': "With a label." },
|
|
|
|
'overlay': { 'throbber': None,
|
|
|
|
'text': "With an overlayed image." },
|
|
|
|
'overlay+text': { 'throbber': None,
|
|
|
|
'text': "With a label and an overlayed image." },
|
|
|
|
}
|
|
|
|
|
|
|
|
images = [throbImages.catalog[i].getBitmap()
|
|
|
|
for i in throbImages.index
|
|
|
|
if i not in ['eclouds', 'logo']]
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.throbbers['plain']['throbber'] = \
|
|
|
|
throb.Throbber(self, -1, images, size=(36, 36),frameDelay = 0.1)
|
|
|
|
|
|
|
|
self.throbbers['reverse']['throbber'] = \
|
|
|
|
throb.Throbber(self, -1, images, frameDelay = 0.07)
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
self.throbbers['reverse']['throbber'].Reverse()
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
self.throbbers['autoreverse']['throbber'] = \
|
|
|
|
throb.Throbber(self, -1, images, frameDelay = 0.1, reverse = True)
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
self.throbbers['autoreverse']['throbber'].sequence.append(0)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.throbbers['label']['throbber'] = \
|
|
|
|
throb.Throbber(self, -1, images, frameDelay = 0.1, label = 'Label')
|
|
|
|
|
|
|
|
self.throbbers['label']['throbber'].SetFont(wx.Font(
|
|
|
|
pointSize = 10, family = wx.DEFAULT, style = wx.NORMAL, weight = wx.BOLD
|
|
|
|
))
|
|
|
|
|
|
|
|
self.throbbers['overlay']['throbber'] = \
|
|
|
|
throb.Throbber(
|
|
|
|
self, -1, images, frameDelay = 0.1,
|
|
|
|
overlay = throbImages.catalog['logo'].getBitmap()
|
|
|
|
)
|
|
|
|
|
|
|
|
self.throbbers['overlay+text']['throbber'] = \
|
|
|
|
throb.Throbber(
|
|
|
|
self, -1, images, frameDelay = 0.1,
|
|
|
|
overlay = throbImages.catalog['logo'].getBitmap(), label = "Python!"
|
|
|
|
)
|
|
|
|
|
|
|
|
self.throbbers['overlay+text']['throbber'].SetFont(wx.Font(
|
|
|
|
pointSize = 8, family = wx.DEFAULT, style = wx.NORMAL, weight = wx.BOLD
|
|
|
|
))
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2005-12-30 18:02:03 -05:00
|
|
|
self.customThrobber = \
|
|
|
|
throb.Throbber(self, -1, images, size=(36, 36),
|
|
|
|
frameDelay = 0.1,
|
|
|
|
rest = 4,
|
|
|
|
sequence = [ 1, 5, 2, 7, 3, 6, 4, 4, 4, 4, 7, 2, 2, 0 ]
|
|
|
|
)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
box = wx.BoxSizer(wx.VERTICAL)
|
2004-01-12 22:17:17 -05:00
|
|
|
sizer = wx.GridBagSizer()
|
2003-12-08 20:23:28 -05:00
|
|
|
box.Add(sizer, 1, wx.EXPAND|wx.ALL, 5)
|
2003-03-25 01:35:27 -05:00
|
|
|
sizer.AddGrowableCol(1)
|
|
|
|
|
|
|
|
row = 2
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
# use a list so we can keep our order
|
|
|
|
for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
|
2003-12-08 20:23:28 -05:00
|
|
|
sizer.Add(
|
2004-01-12 22:17:17 -05:00
|
|
|
self.throbbers[t]['throbber'], (row, 0), (1, 1),
|
2003-12-08 20:23:28 -05:00
|
|
|
flag = wx.ALIGN_CENTER|wx.ALL, border=2
|
|
|
|
)
|
|
|
|
|
|
|
|
sizer.Add(
|
|
|
|
wx.StaticText(self, -1, self.throbbers[t]['text']),
|
2004-01-12 22:17:17 -05:00
|
|
|
(row, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
|
2003-12-08 20:23:28 -05:00
|
|
|
)
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
row += 1
|
|
|
|
|
2005-12-30 18:02:03 -05:00
|
|
|
# Add custom throbber to sizer.
|
|
|
|
row += 2
|
|
|
|
sizer.Add(
|
|
|
|
self.customThrobber, (row, 0), (1, 1),
|
|
|
|
flag = wx.ALIGN_CENTER|wx.ALL, border=2
|
|
|
|
)
|
|
|
|
|
|
|
|
sizer.Add(
|
|
|
|
wx.StaticText(self, -1, 'with custom & manual sequences'),
|
|
|
|
(row, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
|
|
|
|
)
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
# start and stop buttons
|
2003-12-08 20:23:28 -05:00
|
|
|
startButton = wx.Button(self, -1, "Start")
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnStartAnimation, startButton)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
stopButton = wx.Button(self, -1, "Stop")
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnStopAnimation, stopButton)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
buttonBox = wx.BoxSizer(wx.HORIZONTAL)
|
2003-03-25 01:35:27 -05:00
|
|
|
buttonBox.AddMany([
|
2003-12-08 20:23:28 -05:00
|
|
|
(startButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
|
|
|
|
(stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
|
2003-03-25 01:35:27 -05:00
|
|
|
])
|
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
sizer.Add(
|
2005-12-30 18:02:03 -05:00
|
|
|
buttonBox, (len(self.throbbers) + 2, 0), (1, 3), flag = wx.ALIGN_CENTER
|
2004-01-12 22:17:17 -05:00
|
|
|
)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2005-12-30 18:02:03 -05:00
|
|
|
# Buttoms for the custom throbber.
|
|
|
|
nextButton = wx.Button(self, -1, "Next")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnNext, nextButton)
|
|
|
|
|
|
|
|
prevButton = wx.Button(self, -1, "Previous")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnPrevious, prevButton)
|
|
|
|
|
|
|
|
incButton = wx.Button(self, -1, "Increment")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnIncrement, incButton)
|
|
|
|
|
|
|
|
decButton = wx.Button(self, -1, "Decrement")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnDecrement, decButton)
|
|
|
|
|
|
|
|
revButton = wx.Button(self, -1, "Reverse")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnReverse, revButton)
|
|
|
|
|
|
|
|
restButton = wx.Button(self, -1, "Rest")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnRest, restButton)
|
|
|
|
|
|
|
|
startButton = wx.Button(self, -1, "Start")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnStart, startButton)
|
|
|
|
|
|
|
|
stopButton = wx.Button(self, -1, "Stop")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnStop, stopButton)
|
|
|
|
|
|
|
|
customBox1 = wx.BoxSizer(wx.HORIZONTAL)
|
|
|
|
customBox1.AddMany([
|
|
|
|
(nextButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
|
|
|
|
(prevButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
|
|
|
|
(incButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
|
|
|
|
(decButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
|
|
|
|
(revButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
|
|
|
|
])
|
|
|
|
|
|
|
|
customBox2 = wx.BoxSizer(wx.HORIZONTAL)
|
|
|
|
customBox2.AddMany([
|
|
|
|
(restButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
|
|
|
|
(startButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
|
|
|
|
(stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
|
|
|
|
])
|
|
|
|
|
|
|
|
sizer.Add( customBox1, (len(self.throbbers) + 5, 0), (1, 3), flag = wx.ALIGN_CENTER )
|
|
|
|
sizer.Add( customBox2, (len(self.throbbers) + 6, 0), (1, 3), flag = wx.ALIGN_CENTER )
|
|
|
|
|
|
|
|
# Layout.
|
2003-03-25 01:35:27 -05:00
|
|
|
self.SetSizer(box)
|
|
|
|
self.SetAutoLayout(True)
|
|
|
|
self.Layout()
|
|
|
|
sizer.SetSizeHints(self)
|
|
|
|
sizer.Fit(self)
|
|
|
|
|
|
|
|
for t in self.throbbers.keys():
|
|
|
|
self.throbbers[t]['throbber'].Start()
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
|
|
|
def OnDestroy(self, event):
|
|
|
|
self.log.write("got destroy event")
|
|
|
|
event.Skip()
|
|
|
|
|
|
|
|
def OnStartAnimation(self, event):
|
|
|
|
for t in self.throbbers.keys():
|
|
|
|
self.throbbers[t]['throbber'].Start()
|
|
|
|
|
|
|
|
def OnStopAnimation(self, event):
|
|
|
|
for t in self.throbbers.keys():
|
|
|
|
self.throbbers[t]['throbber'].Rest()
|
|
|
|
|
2005-12-30 18:02:03 -05:00
|
|
|
def OnNext(self, event):
|
|
|
|
self.customThrobber.Next()
|
|
|
|
|
|
|
|
def OnPrevious(self, event):
|
|
|
|
self.customThrobber.Previous()
|
|
|
|
|
|
|
|
def OnIncrement(self, event):
|
|
|
|
self.customThrobber.Increment()
|
|
|
|
|
|
|
|
def OnDecrement(self, event):
|
|
|
|
self.customThrobber.Decrement()
|
|
|
|
|
|
|
|
def OnReverse(self, event):
|
|
|
|
self.customThrobber.Reverse()
|
|
|
|
|
|
|
|
def OnRest(self, event):
|
|
|
|
self.customThrobber.Rest()
|
|
|
|
|
|
|
|
def OnStart(self, event):
|
|
|
|
self.customThrobber.Start()
|
|
|
|
|
|
|
|
def OnStop(self, event):
|
|
|
|
self.customThrobber.Stop()
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
def ShutdownDemo(self):
|
|
|
|
for t in self.throbbers.keys():
|
|
|
|
self.throbbers[t]['throbber'].Rest()
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
2004-11-01 14:39:09 -05:00
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
2003-03-25 01:35:27 -05:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """<html><body>
|
|
|
|
<h4><center>Throbber</center></h4>
|
|
|
|
<p>%s</p>
|
|
|
|
</body></html>
|
|
|
|
""" % docString
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-04 19:06:33 -05:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|