]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ToggleButton.py
Fixed the docstring, default module is now wx, not wxPython.wx
[wxWidgets.git] / wxPython / demo / ToggleButton.py
1
2 import wx
3
4 haveToggleBtn = 1
5
6 try:
7 wx.ToggleButton
8 except NameError:
9 haveToggleBtn = 0
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 panel = wx.Panel(self, -1)
18 buttons = wx.BoxSizer(wx.HORIZONTAL)
19
20 for word in "These are toggle buttons".split():
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)
24
25 panel.SetAutoLayout(True)
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
35 def runTest(frame, nb, log):
36 if haveToggleBtn:
37 win = TestPanel(nb, log)
38 return win
39 else:
40 dlg = wx.MessageDialog(frame, 'wx.ToggleButton is not available on this platform.',
41 'Sorry', wx.OK | wx.ICON_INFORMATION)
42 dlg.ShowModal()
43 dlg.Destroy()
44
45
46 #----------------------------------------------------------------------
47
48
49 overview = """\
50 wx.ToggleButton is a button that stays pressed when clicked by the user.
51 In other words, it is similar to wxCheckBox in functionality but looks like a
52 wxButton.
53
54 This class is only available under wxMSW and wxGTK currently.
55
56 """
57
58
59
60 if __name__ == '__main__':
61 import sys,os
62 import run
63 run.main(['', os.path.basename(sys.argv[0])])