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