]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GenericButtons.py
doc tweaks, typo fixed, etc.
[wxWidgets.git] / wxPython / demo / GenericButtons.py
1 # 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2 #
3 # o Updated for wx namespace
4 #
5
6 import wx
7 import wx.lib.buttons as buttons
8
9 import images
10
11 #----------------------------------------------------------------------
12
13 class TestPanel(wx.Panel):
14 def __init__(self, parent, log):
15 wx.Panel.__init__(self, parent, -1)
16 self.log = log
17
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")
22 b.SetDefault()
23 self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
24 sizer.Add(b)
25
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())
29 sizer.Add(b)
30 sizer.Add((10,10))
31
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())
35 sizer.Add(b)
36
37 # Plain old text button, disabled.
38 b = buttons.GenButton(self, -1, 'disabled')
39 self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
40 b.Enable(False)
41 sizer.Add(b)
42
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))
48 b.SetBezelWidth(5)
49 ###b.SetBestSize()
50 b.SetBackgroundColour("Navy")
51 b.SetForegroundColour(wx.WHITE)
52 b.SetToolTipString("This is a BIG button...")
53 # let the sizer set best size
54 sizer.Add(b, flag=wx.ADJUST_MINSIZE)
55
56 # An image button
57 bmp = images.getTest2Bitmap()
58 b = buttons.GenBitmapButton(self, -1, bmp)
59 self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
60 sizer.Add(b)
61
62 # An image button, disabled.
63 bmp = images.getTest2Bitmap()
64 b = buttons.GenBitmapButton(self, -1, bmp)
65 self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
66 sizer.Add(b)
67 b.Enable(False)
68
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())
73 bmp = images.getBulb1Bitmap()
74 mask = wx.MaskColour(bmp, wx.BLUE)
75 bmp.SetMask(mask)
76 b.SetBitmapLabel(bmp)
77 bmp = images.getBulb2Bitmap()
78 mask = wx.MaskColour(bmp, wx.BLUE)
79 bmp.SetMask(mask)
80 b.SetBitmapSelected(bmp)
81 b.SetBestSize()
82 sizer.Add(b)
83
84 # A toggle button
85 b = buttons.GenToggleButton(self, -1, "Toggle Button")
86 self.Bind(wx.EVT_BUTTON, self.OnToggleButton, id=b.GetId())
87 sizer.Add(b)
88
89 # An image toggle button
90 b = buttons.GenBitmapToggleButton(self, -1, None)
91 self.Bind(wx.EVT_BUTTON, self.OnToggleButton, id=b.GetId())
92 bmp = images.getBulb1Bitmap()
93 mask = wx.MaskColour(bmp, wx.BLUE)
94 bmp.SetMask(mask)
95 b.SetBitmapLabel(bmp)
96 bmp = images.getBulb2Bitmap()
97 mask = wx.MaskColour(bmp, wx.BLUE)
98 bmp.SetMask(mask)
99 b.SetBitmapSelected(bmp)
100 b.SetToggle(True)
101 b.SetBestSize()
102 sizer.Add(b)
103
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())
107 bmp = images.getBulb1Bitmap()
108 mask = wx.MaskColour(bmp, wx.BLUE)
109 bmp.SetMask(mask)
110 b.SetBitmapLabel(bmp)
111 bmp = images.getBulb2Bitmap()
112 mask = wx.MaskColour(bmp, wx.BLUE)
113 bmp.SetMask(mask)
114 b.SetBitmapSelected(bmp)
115 b.SetUseFocusIndicator(False)
116 b.SetBestSize()
117 sizer.Add(b)
118
119 border = wx.BoxSizer(wx.VERTICAL)
120 border.Add(sizer, 0, wx.ALL, 25)
121 self.SetSizer(border)
122
123
124 def OnButton(self, event):
125 self.log.WriteText("Button Clicked: %d\n" % event.GetId())
126
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
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
145 def runTest(frame, nb, log):
146 win = TestPanel(nb, log)
147 return win
148
149
150 #----------------------------------------------------------------------
151
152
153 overview = buttons.__doc__
154
155 if __name__ == '__main__':
156 import sys,os
157 import run
158 run.main(['', os.path.basename(sys.argv[0])])
159