]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/GenericButtons.py
doc tweaks, typo fixed, etc.
[wxWidgets.git] / wxPython / demo / GenericButtons.py
CommitLineData
8fa876ca
RD
1# 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4#
6999b0d8 5
8fa876ca
RD
6import wx
7import wx.lib.buttons as buttons
6999b0d8 8
96bfd053 9import images
6999b0d8 10
8fa876ca 11#----------------------------------------------------------------------
6999b0d8 12
8fa876ca 13class TestPanel(wx.Panel):
6999b0d8 14 def __init__(self, parent, log):
8fa876ca 15 wx.Panel.__init__(self, parent, -1)
6999b0d8
RD
16 self.log = log
17
8fa876ca
RD
18 sizer = wx.FlexGridSizer(1, 3, 20, 20)
19
20 # A regular button, selected as the default button
21 b = wx.Button(self, -1, "A real button")
6999b0d8 22 b.SetDefault()
8fa876ca 23 self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
b0e5c039
RD
24 sizer.Add(b)
25
8fa876ca
RD
26 # Same thing, but NOT set as the default button
27 b = wx.Button(self, -1, "non-default")
28 self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
b0e5c039 29 sizer.Add(b)
fbd5dd1d 30 sizer.Add((10,10))
6999b0d8 31
8fa876ca
RD
32 # Plain old text button based off GenButton()
33 b = buttons.GenButton(self, -1, 'Hello')
34 self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
b0e5c039
RD
35 sizer.Add(b)
36
8fa876ca
RD
37 # Plain old text button, disabled.
38 b = buttons.GenButton(self, -1, 'disabled')
39 self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
1e4a197e 40 b.Enable(False)
b0e5c039 41 sizer.Add(b)
6999b0d8 42
8fa876ca
RD
43 # This time, we let the botton be as big as it can be.
44 # Also, this one is fancier, with custom colors and bezel size.
45 b = buttons.GenButton(self, -1, 'bigger')
46 self.Bind(wx.EVT_BUTTON, self.OnBiggerButton, id=b.GetId())
47 b.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.BOLD, False))
6999b0d8 48 b.SetBezelWidth(5)
b0e5c039
RD
49 ###b.SetBestSize()
50 b.SetBackgroundColour("Navy")
8fa876ca 51 b.SetForegroundColour(wx.WHITE)
185d7c3e 52 b.SetToolTipString("This is a BIG button...")
8fa876ca
RD
53 # let the sizer set best size
54 sizer.Add(b, flag=wx.ADJUST_MINSIZE)
6999b0d8 55
8fa876ca 56 # An image button
96bfd053 57 bmp = images.getTest2Bitmap()
8fa876ca
RD
58 b = buttons.GenBitmapButton(self, -1, bmp)
59 self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
b0e5c039 60 sizer.Add(b)
6999b0d8 61
8fa876ca 62 # An image button, disabled.
1e4a197e 63 bmp = images.getTest2Bitmap()
8fa876ca
RD
64 b = buttons.GenBitmapButton(self, -1, bmp)
65 self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
1e4a197e
RD
66 sizer.Add(b)
67 b.Enable(False)
68
8fa876ca
RD
69 # An image button, using a mask to get rid of the
70 # undesireable part of the image
71 b = buttons.GenBitmapButton(self, -1, None)
72 self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
96bfd053 73 bmp = images.getBulb1Bitmap()
8fa876ca 74 mask = wx.MaskColour(bmp, wx.BLUE)
54b96882 75 bmp.SetMask(mask)
6999b0d8 76 b.SetBitmapLabel(bmp)
96bfd053 77 bmp = images.getBulb2Bitmap()
8fa876ca 78 mask = wx.MaskColour(bmp, wx.BLUE)
54b96882 79 bmp.SetMask(mask)
6999b0d8 80 b.SetBitmapSelected(bmp)
78385733 81 b.SetBestSize()
b0e5c039 82 sizer.Add(b)
6999b0d8 83
8fa876ca
RD
84 # A toggle button
85 b = buttons.GenToggleButton(self, -1, "Toggle Button")
86 self.Bind(wx.EVT_BUTTON, self.OnToggleButton, id=b.GetId())
b0e5c039 87 sizer.Add(b)
6999b0d8 88
8fa876ca
RD
89 # An image toggle button
90 b = buttons.GenBitmapToggleButton(self, -1, None)
91 self.Bind(wx.EVT_BUTTON, self.OnToggleButton, id=b.GetId())
96bfd053 92 bmp = images.getBulb1Bitmap()
8fa876ca 93 mask = wx.MaskColour(bmp, wx.BLUE)
54b96882 94 bmp.SetMask(mask)
6999b0d8 95 b.SetBitmapLabel(bmp)
96bfd053 96 bmp = images.getBulb2Bitmap()
8fa876ca 97 mask = wx.MaskColour(bmp, wx.BLUE)
54b96882 98 bmp.SetMask(mask)
6999b0d8 99 b.SetBitmapSelected(bmp)
1e4a197e 100 b.SetToggle(True)
78385733 101 b.SetBestSize()
b0e5c039 102 sizer.Add(b)
6999b0d8 103
8fa876ca
RD
104 # A bitmap button with text.
105 b = buttons.GenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45))
106 self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
ddcb3d83 107 bmp = images.getBulb1Bitmap()
8fa876ca 108 mask = wx.MaskColour(bmp, wx.BLUE)
ddcb3d83
RD
109 bmp.SetMask(mask)
110 b.SetBitmapLabel(bmp)
111 bmp = images.getBulb2Bitmap()
8fa876ca 112 mask = wx.MaskColour(bmp, wx.BLUE)
ddcb3d83
RD
113 bmp.SetMask(mask)
114 b.SetBitmapSelected(bmp)
1e4a197e 115 b.SetUseFocusIndicator(False)
ddcb3d83 116 b.SetBestSize()
b0e5c039
RD
117 sizer.Add(b)
118
8fa876ca
RD
119 border = wx.BoxSizer(wx.VERTICAL)
120 border.Add(sizer, 0, wx.ALL, 25)
b0e5c039 121 self.SetSizer(border)
ddcb3d83 122
6999b0d8
RD
123
124 def OnButton(self, event):
125 self.log.WriteText("Button Clicked: %d\n" % event.GetId())
126
b0e5c039
RD
127
128 def OnBiggerButton(self, event):
129 self.log.WriteText("Bigger Button Clicked: %d\n" % event.GetId())
130 b = event.GetEventObject()
131 txt = "big " + b.GetLabel()
132 b.SetLabel(txt)
133 self.GetSizer().Layout()
134
135
6999b0d8
RD
136 def OnToggleButton(self, event):
137 msg = (event.GetIsDown() and "on") or "off"
138 self.log.WriteText("Button %d Toggled: %s\n" % (event.GetId(), msg))
139
140
141
142#----------------------------------------------------------------------
143
144
145def runTest(frame, nb, log):
146 win = TestPanel(nb, log)
147 return win
148
149
150#----------------------------------------------------------------------
151
152
8fa876ca 153overview = buttons.__doc__
1e4a197e
RD
154
155if __name__ == '__main__':
156 import sys,os
157 import run
158 run.main(['', os.path.basename(sys.argv[0])])
159