]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ToggleButton.py
Fixed preprocessor warnings
[wxWidgets.git] / wxPython / demo / ToggleButton.py
CommitLineData
d1679124 1
8fa876ca 2import wx
d1679124 3
eb0f373c 4haveToggleBtn = 1
8fa876ca 5
eb0f373c 6try:
8fa876ca 7 wx.ToggleButton
eb0f373c
RD
8except NameError:
9 haveToggleBtn = 0
10
d1679124
RD
11#----------------------------------------------------------------------
12
8fa876ca 13class TestPanel(wx.Panel):
d1679124 14 def __init__(self, parent, log):
8fa876ca 15 wx.Panel.__init__(self, parent, -1)
d1679124 16 self.log = log
8fa876ca
RD
17 panel = wx.Panel(self, -1)
18 buttons = wx.BoxSizer(wx.HORIZONTAL)
19
1e4a197e 20 for word in "These are toggle buttons".split():
8fa876ca
RD
21 b = wx.ToggleButton(panel, -1, word)
22 self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, b)
23 buttons.Add(b, flag=wx.ALL, border=5)
d1679124 24
1e4a197e 25 panel.SetAutoLayout(True)
d1679124
RD
26 panel.SetSizer(buttons)
27 buttons.Fit(panel)
28 panel.Move((50,50))
29
30 def OnToggle(self, evt):
31 self.log.write("Button %d toggled\n" % evt.GetId())
32
33#----------------------------------------------------------------------
34
35def runTest(frame, nb, log):
eb0f373c
RD
36 if haveToggleBtn:
37 win = TestPanel(nb, log)
38 return win
39 else:
95bfd958 40 dlg = wx.MessageDialog(frame, 'wx.ToggleButton is not available on this platform.',
8fa876ca 41 'Sorry', wx.OK | wx.ICON_INFORMATION)
eb0f373c
RD
42 dlg.ShowModal()
43 dlg.Destroy()
44
45
d1679124
RD
46#----------------------------------------------------------------------
47
48
49overview = """\
95bfd958 50wx.ToggleButton is a button that stays pressed when clicked by the user.
8fa876ca
RD
51In other words, it is similar to wxCheckBox in functionality but looks like a
52wxButton.
1fded56b 53
8fa876ca 54This class is only available under wxMSW and wxGTK currently.
1fded56b 55
8fa876ca 56"""
1fded56b
RD
57
58
59
60if __name__ == '__main__':
61 import sys,os
62 import run
63 run.main(['', os.path.basename(sys.argv[0])])