]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/GenericButtons.py
Move comment to where it can be a true statement ;-)
[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)
b0e5c039 46 ###b.SetBestSize()
5193b348 47 b.SetMinSize(wx.DefaultSize)
b0e5c039 48 b.SetBackgroundColour("Navy")
8fa876ca 49 b.SetForegroundColour(wx.WHITE)
185d7c3e 50 b.SetToolTipString("This is a BIG button...")
8fa876ca
RD
51 # let the sizer set best size
52 sizer.Add(b, flag=wx.ADJUST_MINSIZE)
6999b0d8 53
8fa876ca 54 # An image button
96bfd053 55 bmp = images.getTest2Bitmap()
8fa876ca 56 b = buttons.GenBitmapButton(self, -1, bmp)
95bfd958 57 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
b0e5c039 58 sizer.Add(b)
6999b0d8 59
8fa876ca 60 # An image button, disabled.
1e4a197e 61 bmp = images.getTest2Bitmap()
8fa876ca 62 b = buttons.GenBitmapButton(self, -1, bmp)
95bfd958 63 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
1e4a197e
RD
64 sizer.Add(b)
65 b.Enable(False)
66
8fa876ca
RD
67 # An image button, using a mask to get rid of the
68 # undesireable part of the image
69 b = buttons.GenBitmapButton(self, -1, None)
95bfd958 70 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
96bfd053 71 bmp = images.getBulb1Bitmap()
d7403ad2 72 mask = wx.Mask(bmp, wx.BLUE)
54b96882 73 bmp.SetMask(mask)
6999b0d8 74 b.SetBitmapLabel(bmp)
96bfd053 75 bmp = images.getBulb2Bitmap()
d7403ad2 76 mask = wx.Mask(bmp, wx.BLUE)
54b96882 77 bmp.SetMask(mask)
6999b0d8 78 b.SetBitmapSelected(bmp)
78385733 79 b.SetBestSize()
b0e5c039 80 sizer.Add(b)
6999b0d8 81
8fa876ca
RD
82 # A toggle button
83 b = buttons.GenToggleButton(self, -1, "Toggle Button")
95bfd958 84 self.Bind(wx.EVT_BUTTON, self.OnToggleButton, b)
b0e5c039 85 sizer.Add(b)
6999b0d8 86
8fa876ca
RD
87 # An image toggle button
88 b = buttons.GenBitmapToggleButton(self, -1, None)
95bfd958 89 self.Bind(wx.EVT_BUTTON, self.OnToggleButton, b)
96bfd053 90 bmp = images.getBulb1Bitmap()
d7403ad2 91 mask = wx.Mask(bmp, wx.BLUE)
54b96882 92 bmp.SetMask(mask)
6999b0d8 93 b.SetBitmapLabel(bmp)
96bfd053 94 bmp = images.getBulb2Bitmap()
d7403ad2 95 mask = wx.Mask(bmp, wx.BLUE)
54b96882 96 bmp.SetMask(mask)
6999b0d8 97 b.SetBitmapSelected(bmp)
1e4a197e 98 b.SetToggle(True)
78385733 99 b.SetBestSize()
b0e5c039 100 sizer.Add(b)
6999b0d8 101
8fa876ca
RD
102 # A bitmap button with text.
103 b = buttons.GenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45))
95bfd958 104 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
ddcb3d83 105 bmp = images.getBulb1Bitmap()
d7403ad2 106 mask = wx.Mask(bmp, wx.BLUE)
ddcb3d83
RD
107 bmp.SetMask(mask)
108 b.SetBitmapLabel(bmp)
109 bmp = images.getBulb2Bitmap()
d7403ad2 110 mask = wx.Mask(bmp, wx.BLUE)
ddcb3d83
RD
111 bmp.SetMask(mask)
112 b.SetBitmapSelected(bmp)
1e4a197e 113 b.SetUseFocusIndicator(False)
ddcb3d83 114 b.SetBestSize()
b0e5c039
RD
115 sizer.Add(b)
116
8fa876ca
RD
117 border = wx.BoxSizer(wx.VERTICAL)
118 border.Add(sizer, 0, wx.ALL, 25)
b0e5c039 119 self.SetSizer(border)
ddcb3d83 120
6999b0d8
RD
121
122 def OnButton(self, event):
123 self.log.WriteText("Button Clicked: %d\n" % event.GetId())
124
b0e5c039
RD
125
126 def OnBiggerButton(self, event):
127 self.log.WriteText("Bigger Button Clicked: %d\n" % event.GetId())
128 b = event.GetEventObject()
129 txt = "big " + b.GetLabel()
130 b.SetLabel(txt)
131 self.GetSizer().Layout()
132
133
6999b0d8
RD
134 def OnToggleButton(self, event):
135 msg = (event.GetIsDown() and "on") or "off"
136 self.log.WriteText("Button %d Toggled: %s\n" % (event.GetId(), msg))
137
138
139
140#----------------------------------------------------------------------
141
142
143def runTest(frame, nb, log):
144 win = TestPanel(nb, log)
145 return win
146
147
148#----------------------------------------------------------------------
149
150
8fa876ca 151overview = buttons.__doc__
1e4a197e
RD
152
153if __name__ == '__main__':
154 import sys,os
155 import run
8eca4fef 156 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1e4a197e 157