]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GenericButtons.py
style sheet for the api docs
[wxWidgets.git] / wxPython / demo / GenericButtons.py
1
2 import wx
3 import wx.lib.buttons as buttons
4
5 import images
6
7 #----------------------------------------------------------------------
8
9 class TestPanel(wx.Panel):
10 def __init__(self, parent, log):
11 wx.Panel.__init__(self, parent, -1)
12 self.log = log
13
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")
18 b.SetDefault()
19 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
20 sizer.Add(b)
21
22 # Same thing, but NOT set as the default button
23 b = wx.Button(self, -1, "non-default")
24 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
25 sizer.Add(b)
26 sizer.Add((10,10))
27
28 # Plain old text button based off GenButton()
29 b = buttons.GenButton(self, -1, 'Hello')
30 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
31 sizer.Add(b)
32
33 # Plain old text button, disabled.
34 b = buttons.GenButton(self, -1, 'disabled')
35 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
36 b.Enable(False)
37 sizer.Add(b)
38
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')
42 self.Bind(wx.EVT_BUTTON, self.OnBiggerButton, b)
43 b.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.BOLD, False))
44 b.SetBezelWidth(5)
45 ###b.SetBestSize()
46 b.SetBackgroundColour("Navy")
47 b.SetForegroundColour(wx.WHITE)
48 b.SetToolTipString("This is a BIG button...")
49 # let the sizer set best size
50 sizer.Add(b, flag=wx.ADJUST_MINSIZE)
51
52 # An image button
53 bmp = images.getTest2Bitmap()
54 b = buttons.GenBitmapButton(self, -1, bmp)
55 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
56 sizer.Add(b)
57
58 # An image button, disabled.
59 bmp = images.getTest2Bitmap()
60 b = buttons.GenBitmapButton(self, -1, bmp)
61 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
62 sizer.Add(b)
63 b.Enable(False)
64
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)
68 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
69 bmp = images.getBulb1Bitmap()
70 mask = wx.MaskColour(bmp, wx.BLUE)
71 bmp.SetMask(mask)
72 b.SetBitmapLabel(bmp)
73 bmp = images.getBulb2Bitmap()
74 mask = wx.MaskColour(bmp, wx.BLUE)
75 bmp.SetMask(mask)
76 b.SetBitmapSelected(bmp)
77 b.SetBestSize()
78 sizer.Add(b)
79
80 # A toggle button
81 b = buttons.GenToggleButton(self, -1, "Toggle Button")
82 self.Bind(wx.EVT_BUTTON, self.OnToggleButton, b)
83 sizer.Add(b)
84
85 # An image toggle button
86 b = buttons.GenBitmapToggleButton(self, -1, None)
87 self.Bind(wx.EVT_BUTTON, self.OnToggleButton, b)
88 bmp = images.getBulb1Bitmap()
89 mask = wx.MaskColour(bmp, wx.BLUE)
90 bmp.SetMask(mask)
91 b.SetBitmapLabel(bmp)
92 bmp = images.getBulb2Bitmap()
93 mask = wx.MaskColour(bmp, wx.BLUE)
94 bmp.SetMask(mask)
95 b.SetBitmapSelected(bmp)
96 b.SetToggle(True)
97 b.SetBestSize()
98 sizer.Add(b)
99
100 # A bitmap button with text.
101 b = buttons.GenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45))
102 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
103 bmp = images.getBulb1Bitmap()
104 mask = wx.MaskColour(bmp, wx.BLUE)
105 bmp.SetMask(mask)
106 b.SetBitmapLabel(bmp)
107 bmp = images.getBulb2Bitmap()
108 mask = wx.MaskColour(bmp, wx.BLUE)
109 bmp.SetMask(mask)
110 b.SetBitmapSelected(bmp)
111 b.SetUseFocusIndicator(False)
112 b.SetBestSize()
113 sizer.Add(b)
114
115 border = wx.BoxSizer(wx.VERTICAL)
116 border.Add(sizer, 0, wx.ALL, 25)
117 self.SetSizer(border)
118
119
120 def OnButton(self, event):
121 self.log.WriteText("Button Clicked: %d\n" % event.GetId())
122
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
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
141 def runTest(frame, nb, log):
142 win = TestPanel(nb, log)
143 return win
144
145
146 #----------------------------------------------------------------------
147
148
149 overview = buttons.__doc__
150
151 if __name__ == '__main__':
152 import sys,os
153 import run
154 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
155