1999-12-11 02:59:23 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
import wx
|
|
|
|
import wx.lib.buttons as buttons
|
1999-12-11 02:59:23 -05:00
|
|
|
|
2001-04-09 15:36:36 -04:00
|
|
|
import images
|
1999-12-11 02:59:23 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
#----------------------------------------------------------------------
|
1999-12-11 02:59:23 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPanel(wx.Panel):
|
1999-12-11 02:59:23 -05:00
|
|
|
def __init__(self, parent, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
1999-12-11 02:59:23 -05:00
|
|
|
self.log = log
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
sizer = wx.FlexGridSizer(1, 3, 20, 20)
|
|
|
|
|
|
|
|
# A regular button, selected as the default button
|
|
|
|
b = wx.Button(self, -1, "A real button")
|
1999-12-11 02:59:23 -05:00
|
|
|
b.SetDefault()
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
2002-06-06 13:37:38 -04:00
|
|
|
sizer.Add(b)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# Same thing, but NOT set as the default button
|
|
|
|
b = wx.Button(self, -1, "non-default")
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
2002-06-06 13:37:38 -04:00
|
|
|
sizer.Add(b)
|
2003-11-21 02:36:53 -05:00
|
|
|
sizer.Add((10,10))
|
1999-12-11 02:59:23 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# Plain old text button based off GenButton()
|
|
|
|
b = buttons.GenButton(self, -1, 'Hello')
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
2002-06-06 13:37:38 -04:00
|
|
|
sizer.Add(b)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# Plain old text button, disabled.
|
|
|
|
b = buttons.GenButton(self, -1, 'disabled')
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
2003-03-25 01:35:27 -05:00
|
|
|
b.Enable(False)
|
2002-06-06 13:37:38 -04:00
|
|
|
sizer.Add(b)
|
1999-12-11 02:59:23 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# This time, we let the botton be as big as it can be.
|
|
|
|
# Also, this one is fancier, with custom colors and bezel size.
|
|
|
|
b = buttons.GenButton(self, -1, 'bigger')
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnBiggerButton, b)
|
2003-12-08 20:23:28 -05:00
|
|
|
b.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.BOLD, False))
|
1999-12-11 02:59:23 -05:00
|
|
|
b.SetBezelWidth(5)
|
2002-06-06 13:37:38 -04:00
|
|
|
###b.SetBestSize()
|
|
|
|
b.SetBackgroundColour("Navy")
|
2003-12-08 20:23:28 -05:00
|
|
|
b.SetForegroundColour(wx.WHITE)
|
2000-11-20 22:44:14 -05:00
|
|
|
b.SetToolTipString("This is a BIG button...")
|
2003-12-08 20:23:28 -05:00
|
|
|
# let the sizer set best size
|
|
|
|
sizer.Add(b, flag=wx.ADJUST_MINSIZE)
|
1999-12-11 02:59:23 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# An image button
|
2001-04-09 15:36:36 -04:00
|
|
|
bmp = images.getTest2Bitmap()
|
2003-12-08 20:23:28 -05:00
|
|
|
b = buttons.GenBitmapButton(self, -1, bmp)
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
2002-06-06 13:37:38 -04:00
|
|
|
sizer.Add(b)
|
1999-12-11 02:59:23 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# An image button, disabled.
|
2003-03-25 01:35:27 -05:00
|
|
|
bmp = images.getTest2Bitmap()
|
2003-12-08 20:23:28 -05:00
|
|
|
b = buttons.GenBitmapButton(self, -1, bmp)
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
2003-03-25 01:35:27 -05:00
|
|
|
sizer.Add(b)
|
|
|
|
b.Enable(False)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# An image button, using a mask to get rid of the
|
|
|
|
# undesireable part of the image
|
|
|
|
b = buttons.GenBitmapButton(self, -1, None)
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
2001-04-09 15:36:36 -04:00
|
|
|
bmp = images.getBulb1Bitmap()
|
2003-12-08 20:23:28 -05:00
|
|
|
mask = wx.MaskColour(bmp, wx.BLUE)
|
1999-12-29 17:10:32 -05:00
|
|
|
bmp.SetMask(mask)
|
1999-12-11 02:59:23 -05:00
|
|
|
b.SetBitmapLabel(bmp)
|
2001-04-09 15:36:36 -04:00
|
|
|
bmp = images.getBulb2Bitmap()
|
2003-12-08 20:23:28 -05:00
|
|
|
mask = wx.MaskColour(bmp, wx.BLUE)
|
1999-12-29 17:10:32 -05:00
|
|
|
bmp.SetMask(mask)
|
1999-12-11 02:59:23 -05:00
|
|
|
b.SetBitmapSelected(bmp)
|
1999-12-14 01:38:17 -05:00
|
|
|
b.SetBestSize()
|
2002-06-06 13:37:38 -04:00
|
|
|
sizer.Add(b)
|
1999-12-11 02:59:23 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# A toggle button
|
|
|
|
b = buttons.GenToggleButton(self, -1, "Toggle Button")
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnToggleButton, b)
|
2002-06-06 13:37:38 -04:00
|
|
|
sizer.Add(b)
|
1999-12-11 02:59:23 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# An image toggle button
|
|
|
|
b = buttons.GenBitmapToggleButton(self, -1, None)
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnToggleButton, b)
|
2001-04-09 15:36:36 -04:00
|
|
|
bmp = images.getBulb1Bitmap()
|
2003-12-08 20:23:28 -05:00
|
|
|
mask = wx.MaskColour(bmp, wx.BLUE)
|
1999-12-29 17:10:32 -05:00
|
|
|
bmp.SetMask(mask)
|
1999-12-11 02:59:23 -05:00
|
|
|
b.SetBitmapLabel(bmp)
|
2001-04-09 15:36:36 -04:00
|
|
|
bmp = images.getBulb2Bitmap()
|
2003-12-08 20:23:28 -05:00
|
|
|
mask = wx.MaskColour(bmp, wx.BLUE)
|
1999-12-29 17:10:32 -05:00
|
|
|
bmp.SetMask(mask)
|
1999-12-11 02:59:23 -05:00
|
|
|
b.SetBitmapSelected(bmp)
|
2003-03-25 01:35:27 -05:00
|
|
|
b.SetToggle(True)
|
1999-12-14 01:38:17 -05:00
|
|
|
b.SetBestSize()
|
2002-06-06 13:37:38 -04:00
|
|
|
sizer.Add(b)
|
1999-12-11 02:59:23 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# A bitmap button with text.
|
|
|
|
b = buttons.GenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45))
|
2004-01-12 22:17:17 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
2001-09-03 19:23:47 -04:00
|
|
|
bmp = images.getBulb1Bitmap()
|
2003-12-08 20:23:28 -05:00
|
|
|
mask = wx.MaskColour(bmp, wx.BLUE)
|
2001-09-03 19:23:47 -04:00
|
|
|
bmp.SetMask(mask)
|
|
|
|
b.SetBitmapLabel(bmp)
|
|
|
|
bmp = images.getBulb2Bitmap()
|
2003-12-08 20:23:28 -05:00
|
|
|
mask = wx.MaskColour(bmp, wx.BLUE)
|
2001-09-03 19:23:47 -04:00
|
|
|
bmp.SetMask(mask)
|
|
|
|
b.SetBitmapSelected(bmp)
|
2003-03-25 01:35:27 -05:00
|
|
|
b.SetUseFocusIndicator(False)
|
2001-09-03 19:23:47 -04:00
|
|
|
b.SetBestSize()
|
2002-06-06 13:37:38 -04:00
|
|
|
sizer.Add(b)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
border = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
border.Add(sizer, 0, wx.ALL, 25)
|
2002-06-06 13:37:38 -04:00
|
|
|
self.SetSizer(border)
|
2001-09-03 19:23:47 -04:00
|
|
|
|
1999-12-11 02:59:23 -05:00
|
|
|
|
|
|
|
def OnButton(self, event):
|
|
|
|
self.log.WriteText("Button Clicked: %d\n" % event.GetId())
|
|
|
|
|
2002-06-06 13:37:38 -04:00
|
|
|
|
|
|
|
def OnBiggerButton(self, event):
|
|
|
|
self.log.WriteText("Bigger Button Clicked: %d\n" % event.GetId())
|
|
|
|
b = event.GetEventObject()
|
|
|
|
txt = "big " + b.GetLabel()
|
|
|
|
b.SetLabel(txt)
|
|
|
|
self.GetSizer().Layout()
|
|
|
|
|
|
|
|
|
1999-12-11 02:59:23 -05:00
|
|
|
def OnToggleButton(self, event):
|
|
|
|
msg = (event.GetIsDown() and "on") or "off"
|
|
|
|
self.log.WriteText("Button %d Toggled: %s\n" % (event.GetId(), msg))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
overview = buttons.__doc__
|
2003-03-25 01:35:27 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])])
|
|
|
|
|