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