]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/CheckListBox.py
Fix "warning: operation on 'y' may be undefined".
[wxWidgets.git] / wxPython / demo / CheckListBox.py
CommitLineData
cf694132 1
8fa876ca 2import wx
cf694132
RD
3
4#----------------------------------------------------------------------
5
8fa876ca 6class TestPanel(wx.Panel):
cf694132 7 def __init__(self, parent, log):
8fa876ca 8 wx.Panel.__init__(self, parent, -1)
cf694132
RD
9 self.log = log
10
11 sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
12 'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
13 'twelve', 'thirteen', 'fourteen']
14
8fa876ca 15 wx.StaticText(self, -1, "This example uses the wxCheckListBox control.", (45, 15))
cf694132 16
6ab5d488 17 lb = wx.CheckListBox(self, -1, (80, 50), wx.DefaultSize, sampleList)
95bfd958 18 self.Bind(wx.EVT_LISTBOX, self.EvtListBox, lb)
982d1607 19 self.Bind(wx.EVT_CHECKLISTBOX, self.EvtCheckListBox, lb)
cf694132 20 lb.SetSelection(0)
be43cc44
RD
21 self.lb = lb
22
1e4a197e 23 pos = lb.GetPosition().x + lb.GetSize().width + 25
8fa876ca 24 btn = wx.Button(self, -1, "Test SetString", (pos, 50))
95bfd958 25 self.Bind(wx.EVT_BUTTON, self.OnTestButton, btn)
cf694132
RD
26
27 def EvtListBox(self, event):
28 self.log.WriteText('EvtListBox: %s\n' % event.GetString())
29
982d1607
RD
30 def EvtCheckListBox(self, event):
31 index = event.GetSelection()
32 label = self.lb.GetString(index)
33 status = 'un'
34 if self.lb.IsChecked(index):
35 status = ''
36 self.log.WriteText('Box %s is %schecked \n' % (label, status))
37 self.lb.SetSelection(index) # so that (un)checking also selects (moves the highlight)
38
cf694132 39
be43cc44
RD
40 def OnTestButton(self, evt):
41 self.lb.SetString(4, "FUBAR")
42
cf694132
RD
43#----------------------------------------------------------------------
44
45def runTest(frame, nb, log):
46 win = TestPanel(nb, log)
47 return win
48
49#----------------------------------------------------------------------
50
51
1fded56b 52overview = """\
8fa876ca
RD
53A checklistbox is like a Listbox, but allows items to be checked or unchecked rather
54than relying on extended selection (e.g. shift-select) to select multiple items in
55the list.
cf694132 56
8fa876ca 57This class is currently implemented under Windows and GTK.
cf694132 58
8fa876ca
RD
59This demo shows the basic CheckListBox and how to use the SetString method to change
60labels dynamically.
61"""
cf694132
RD
62
63
1fded56b
RD
64if __name__ == '__main__':
65 import sys,os
66 import run
8eca4fef 67 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
cf694132 68