]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GenericButtons.py
1 # 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
7 import wx
.lib
.buttons
as buttons
11 #----------------------------------------------------------------------
13 class TestPanel(wx
.Panel
):
14 def __init__(self
, parent
, log
):
15 wx
.Panel
.__init
__(self
, parent
, -1)
18 sizer
= wx
.FlexGridSizer(1, 3, 20, 20)
20 # A regular button, selected as the default button
21 b
= wx
.Button(self
, -1, "A real button")
23 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, id=b
.GetId())
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())
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())
37 # Plain old text button, disabled.
38 b
= buttons
.GenButton(self
, -1, 'disabled')
39 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, id=b
.GetId())
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))
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
)
57 bmp
= images
.getTest2Bitmap()
58 b
= buttons
.GenBitmapButton(self
, -1, bmp
)
59 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, id=b
.GetId())
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())
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
)
77 bmp
= images
.getBulb2Bitmap()
78 mask
= wx
.MaskColour(bmp
, wx
.BLUE
)
80 b
.SetBitmapSelected(bmp
)
85 b
= buttons
.GenToggleButton(self
, -1, "Toggle Button")
86 self
.Bind(wx
.EVT_BUTTON
, self
.OnToggleButton
, id=b
.GetId())
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
)
96 bmp
= images
.getBulb2Bitmap()
97 mask
= wx
.MaskColour(bmp
, wx
.BLUE
)
99 b
.SetBitmapSelected(bmp
)
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
)
110 b
.SetBitmapLabel(bmp
)
111 bmp
= images
.getBulb2Bitmap()
112 mask
= wx
.MaskColour(bmp
, wx
.BLUE
)
114 b
.SetBitmapSelected(bmp
)
115 b
.SetUseFocusIndicator(False)
119 border
= wx
.BoxSizer(wx
.VERTICAL
)
120 border
.Add(sizer
, 0, wx
.ALL
, 25)
121 self
.SetSizer(border
)
124 def OnButton(self
, event
):
125 self
.log
.WriteText("Button Clicked: %d\n" % event
.GetId())
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()
133 self
.GetSizer().Layout()
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
))
142 #----------------------------------------------------------------------
145 def runTest(frame
, nb
, log
):
146 win
= TestPanel(nb
, log
)
150 #----------------------------------------------------------------------
153 overview
= buttons
.__doc
__
155 if __name__
== '__main__':
158 run
.main(['', os
.path
.basename(sys
.argv
[0])])