]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/CheckListBox.py
Changes needed for new RTL methods, and also various other updates to
[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
35c15a4d
RD
23 lb.Bind(wx.EVT_RIGHT_DOWN, self.OnDoHitTest)
24
1e4a197e 25 pos = lb.GetPosition().x + lb.GetSize().width + 25
8fa876ca 26 btn = wx.Button(self, -1, "Test SetString", (pos, 50))
95bfd958 27 self.Bind(wx.EVT_BUTTON, self.OnTestButton, btn)
cf694132
RD
28
29 def EvtListBox(self, event):
30 self.log.WriteText('EvtListBox: %s\n' % event.GetString())
31
982d1607
RD
32 def EvtCheckListBox(self, event):
33 index = event.GetSelection()
34 label = self.lb.GetString(index)
35 status = 'un'
36 if self.lb.IsChecked(index):
37 status = ''
38 self.log.WriteText('Box %s is %schecked \n' % (label, status))
39 self.lb.SetSelection(index) # so that (un)checking also selects (moves the highlight)
40
cf694132 41
be43cc44
RD
42 def OnTestButton(self, evt):
43 self.lb.SetString(4, "FUBAR")
44
35c15a4d
RD
45 def OnDoHitTest(self, evt):
46 item = self.lb.HitTest(evt.GetPosition())
47 self.log.write("HitTest: %d\n" % item)
48
cf694132
RD
49#----------------------------------------------------------------------
50
51def runTest(frame, nb, log):
52 win = TestPanel(nb, log)
53 return win
54
55#----------------------------------------------------------------------
56
57
1fded56b 58overview = """\
8fa876ca
RD
59A checklistbox is like a Listbox, but allows items to be checked or unchecked rather
60than relying on extended selection (e.g. shift-select) to select multiple items in
61the list.
cf694132 62
8fa876ca 63This class is currently implemented under Windows and GTK.
cf694132 64
8fa876ca
RD
65This demo shows the basic CheckListBox and how to use the SetString method to change
66labels dynamically.
67"""
cf694132
RD
68
69
1fded56b
RD
70if __name__ == '__main__':
71 import sys,os
72 import run
8eca4fef 73 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
cf694132 74