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
|
2004-05-14 17:22:39 -04:00
|
|
|
##self.SetBackgroundColour("sky blue")
|
1999-12-11 02:59:23 -05:00
|
|
|
|
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)
|
2004-08-04 18:24:57 -04:00
|
|
|
b.SetMinSize(wx.DefaultSize)
|
2002-06-06 13:37:38 -04:00
|
|
|
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()
|
2004-05-01 22:41:33 -04:00
|
|
|
mask = wx.Mask(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()
|
2004-05-01 22:41:33 -04:00
|
|
|
mask = wx.Mask(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)
|
2006-10-31 03:50:17 -05:00
|
|
|
b.SetInitialSize()
|
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()
|
2004-05-01 22:41:33 -04:00
|
|
|
mask = wx.Mask(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()
|
2004-05-01 22:41:33 -04:00
|
|
|
mask = wx.Mask(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)
|
2006-10-31 03:50:17 -05:00
|
|
|
b.SetInitialSize()
|
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()
|
2004-05-01 22:41:33 -04:00
|
|
|
mask = wx.Mask(bmp, wx.BLUE)
|
2001-09-03 19:23:47 -04:00
|
|
|
bmp.SetMask(mask)
|
|
|
|
b.SetBitmapLabel(bmp)
|
|
|
|
bmp = images.getBulb2Bitmap()
|
2004-05-01 22:41:33 -04:00
|
|
|
mask = wx.Mask(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)
|
2006-10-31 03:50:17 -05:00
|
|
|
b.SetInitialSize()
|
2002-06-06 13:37:38 -04:00
|
|
|
sizer.Add(b)
|
|
|
|
|
2005-05-16 20:41:02 -04:00
|
|
|
|
|
|
|
# a flat text button
|
|
|
|
b = buttons.GenButton(self, -1, 'Flat buttons too!', style=wx.BORDER_NONE)
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
|
|
|
sizer.Add(b, flag=wx.ALIGN_CENTER_VERTICAL)
|
|
|
|
|
|
|
|
# A flat image button
|
|
|
|
bmp = images.getTest2Bitmap()
|
|
|
|
bmp.SetMaskColour("blue")
|
|
|
|
b = buttons.GenBitmapButton(self, -1, bmp, style=wx.BORDER_NONE)
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
|
|
|
sizer.Add(b)
|
|
|
|
##b.SetBackgroundColour("sky blue")
|
|
|
|
##b.SetBackgroundColour("pink")
|
|
|
|
|
|
|
|
|
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
|
2004-03-04 19:06:33 -05:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2003-03-25 01:35:27 -05:00
|
|
|
|