1999-12-11 07:59:23 +00:00
|
|
|
|
|
|
|
from wxPython.wx import *
|
2001-09-03 23:23:47 +00:00
|
|
|
from wxPython.lib.buttons import *
|
1999-12-11 07:59:23 +00:00
|
|
|
|
2001-04-09 19:36:36 +00:00
|
|
|
import images
|
1999-12-11 07:59:23 +00:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
class TestPanel(wxPanel):
|
|
|
|
def __init__(self, parent, log):
|
|
|
|
wxPanel.__init__(self, parent, -1)
|
|
|
|
self.log = log
|
|
|
|
|
2002-06-06 17:37:38 +00:00
|
|
|
sizer = wxFlexGridSizer(1, 3, 20, 20)
|
|
|
|
b = wxButton(self, -1, "A real button")
|
1999-12-11 07:59:23 +00:00
|
|
|
b.SetDefault()
|
|
|
|
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
2002-06-06 17:37:38 +00:00
|
|
|
sizer.Add(b)
|
|
|
|
|
|
|
|
b = wxButton(self, -1, "non-default")
|
1999-12-11 07:59:23 +00:00
|
|
|
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
2002-06-06 17:37:38 +00:00
|
|
|
sizer.Add(b)
|
2003-11-21 07:36:53 +00:00
|
|
|
sizer.Add((10,10))
|
1999-12-11 07:59:23 +00:00
|
|
|
|
2002-06-06 17:37:38 +00:00
|
|
|
b = wxGenButton(self, -1, 'Hello')
|
1999-12-11 07:59:23 +00:00
|
|
|
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
2002-06-06 17:37:38 +00:00
|
|
|
sizer.Add(b)
|
|
|
|
|
|
|
|
b = wxGenButton(self, -1, 'disabled')
|
1999-12-11 07:59:23 +00:00
|
|
|
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
2003-03-25 06:35:27 +00:00
|
|
|
b.Enable(False)
|
2002-06-06 17:37:38 +00:00
|
|
|
sizer.Add(b)
|
1999-12-11 07:59:23 +00:00
|
|
|
|
2002-06-06 17:37:38 +00:00
|
|
|
b = wxGenButton(self, -1, 'bigger')
|
|
|
|
EVT_BUTTON(self, b.GetId(), self.OnBiggerButton)
|
2003-03-25 06:35:27 +00:00
|
|
|
b.SetFont(wxFont(20, wxSWISS, wxNORMAL, wxBOLD, False))
|
1999-12-11 07:59:23 +00:00
|
|
|
b.SetBezelWidth(5)
|
2002-06-06 17:37:38 +00:00
|
|
|
###b.SetBestSize()
|
|
|
|
b.SetBackgroundColour("Navy")
|
1999-12-11 07:59:23 +00:00
|
|
|
b.SetForegroundColour(wxWHITE)
|
2000-11-21 03:44:14 +00:00
|
|
|
b.SetToolTipString("This is a BIG button...")
|
2002-06-06 17:37:38 +00:00
|
|
|
sizer.Add(b, flag=wxADJUST_MINSIZE) # let the sizer set best size
|
1999-12-11 07:59:23 +00:00
|
|
|
|
2001-04-09 19:36:36 +00:00
|
|
|
bmp = images.getTest2Bitmap()
|
2002-06-06 17:37:38 +00:00
|
|
|
b = wxGenBitmapButton(self, -1, bmp)
|
1999-12-11 07:59:23 +00:00
|
|
|
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
2002-06-06 17:37:38 +00:00
|
|
|
sizer.Add(b)
|
1999-12-11 07:59:23 +00:00
|
|
|
|
2003-03-25 06:35:27 +00:00
|
|
|
bmp = images.getTest2Bitmap()
|
|
|
|
b = wxGenBitmapButton(self, -1, bmp)
|
|
|
|
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
|
|
|
sizer.Add(b)
|
|
|
|
b.Enable(False)
|
|
|
|
|
2002-06-06 17:37:38 +00:00
|
|
|
b = wxGenBitmapButton(self, -1, None)
|
1999-12-11 07:59:23 +00:00
|
|
|
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
2001-04-09 19:36:36 +00:00
|
|
|
bmp = images.getBulb1Bitmap()
|
1999-12-29 22:10:32 +00:00
|
|
|
mask = wxMaskColour(bmp, wxBLUE)
|
|
|
|
bmp.SetMask(mask)
|
1999-12-11 07:59:23 +00:00
|
|
|
b.SetBitmapLabel(bmp)
|
2001-04-09 19:36:36 +00:00
|
|
|
bmp = images.getBulb2Bitmap()
|
1999-12-29 22:10:32 +00:00
|
|
|
mask = wxMaskColour(bmp, wxBLUE)
|
|
|
|
bmp.SetMask(mask)
|
1999-12-11 07:59:23 +00:00
|
|
|
b.SetBitmapSelected(bmp)
|
1999-12-14 06:38:17 +00:00
|
|
|
b.SetBestSize()
|
2002-06-06 17:37:38 +00:00
|
|
|
sizer.Add(b)
|
1999-12-11 07:59:23 +00:00
|
|
|
|
2002-06-06 17:37:38 +00:00
|
|
|
b = wxGenToggleButton(self, -1, "Toggle Button")
|
1999-12-11 07:59:23 +00:00
|
|
|
EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
|
2002-06-06 17:37:38 +00:00
|
|
|
sizer.Add(b)
|
1999-12-11 07:59:23 +00:00
|
|
|
|
2002-06-06 17:37:38 +00:00
|
|
|
b = wxGenBitmapToggleButton(self, -1, None)
|
1999-12-11 07:59:23 +00:00
|
|
|
EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
|
2001-04-09 19:36:36 +00:00
|
|
|
bmp = images.getBulb1Bitmap()
|
1999-12-29 22:10:32 +00:00
|
|
|
mask = wxMaskColour(bmp, wxBLUE)
|
|
|
|
bmp.SetMask(mask)
|
1999-12-11 07:59:23 +00:00
|
|
|
b.SetBitmapLabel(bmp)
|
2001-04-09 19:36:36 +00:00
|
|
|
bmp = images.getBulb2Bitmap()
|
1999-12-29 22:10:32 +00:00
|
|
|
mask = wxMaskColour(bmp, wxBLUE)
|
|
|
|
bmp.SetMask(mask)
|
1999-12-11 07:59:23 +00:00
|
|
|
b.SetBitmapSelected(bmp)
|
2003-03-25 06:35:27 +00:00
|
|
|
b.SetToggle(True)
|
1999-12-14 06:38:17 +00:00
|
|
|
b.SetBestSize()
|
2002-06-06 17:37:38 +00:00
|
|
|
sizer.Add(b)
|
1999-12-11 07:59:23 +00:00
|
|
|
|
2002-06-06 17:37:38 +00:00
|
|
|
b = wxGenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45))
|
2001-09-03 23:23:47 +00:00
|
|
|
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
|
|
|
bmp = images.getBulb1Bitmap()
|
|
|
|
mask = wxMaskColour(bmp, wxBLUE)
|
|
|
|
bmp.SetMask(mask)
|
|
|
|
b.SetBitmapLabel(bmp)
|
|
|
|
bmp = images.getBulb2Bitmap()
|
|
|
|
mask = wxMaskColour(bmp, wxBLUE)
|
|
|
|
bmp.SetMask(mask)
|
|
|
|
b.SetBitmapSelected(bmp)
|
2003-03-25 06:35:27 +00:00
|
|
|
b.SetUseFocusIndicator(False)
|
2001-09-03 23:23:47 +00:00
|
|
|
b.SetBestSize()
|
2002-06-06 17:37:38 +00:00
|
|
|
sizer.Add(b)
|
|
|
|
|
|
|
|
border = wxBoxSizer(wxVERTICAL)
|
|
|
|
border.Add(sizer, 0, wxALL, 25)
|
|
|
|
self.SetSizer(border)
|
2001-09-03 23:23:47 +00:00
|
|
|
|
1999-12-11 07:59:23 +00:00
|
|
|
|
|
|
|
def OnButton(self, event):
|
|
|
|
self.log.WriteText("Button Clicked: %d\n" % event.GetId())
|
|
|
|
|
2002-06-06 17:37:38 +00: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 07:59:23 +00: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
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
import wxPython.lib.buttons
|
|
|
|
overview = wxPython.lib.buttons.__doc__
|
2003-03-25 06:35:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])])
|
|
|
|
|