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