]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/CheckListBox.py
4 #----------------------------------------------------------------------
6 class TestPanel(wx
.Panel
):
7 def __init__(self
, parent
, log
):
8 wx
.Panel
.__init
__(self
, parent
, -1)
11 sampleList
= ['zero', 'one', 'two', 'three', 'four', 'five',
12 'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
13 'twelve', 'thirteen', 'fourteen']
15 wx
.StaticText(self
, -1, "This example uses the wxCheckListBox control.", (45, 15))
17 lb
= wx
.CheckListBox(self
, -1, (80, 50), wx
.DefaultSize
, sampleList
)
18 self
.Bind(wx
.EVT_LISTBOX
, self
.EvtListBox
, lb
)
19 self
.Bind(wx
.EVT_CHECKLISTBOX
, self
.EvtCheckListBox
, lb
)
23 lb
.Bind(wx
.EVT_RIGHT_DOWN
, self
.OnDoHitTest
)
25 pos
= lb
.GetPosition().x
+ lb
.GetSize().width
+ 25
26 btn
= wx
.Button(self
, -1, "Test SetString", (pos
, 50))
27 self
.Bind(wx
.EVT_BUTTON
, self
.OnTestButton
, btn
)
29 def EvtListBox(self
, event
):
30 self
.log
.WriteText('EvtListBox: %s\n' % event
.GetString())
32 def EvtCheckListBox(self
, event
):
33 index
= event
.GetSelection()
34 label
= self
.lb
.GetString(index
)
36 if self
.lb
.IsChecked(index
):
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)
42 def OnTestButton(self
, evt
):
43 self
.lb
.SetString(4, "FUBAR")
45 def OnDoHitTest(self
, evt
):
46 item
= self
.lb
.HitTest(evt
.GetPosition())
47 self
.log
.write("HitTest: %d\n" % item
)
49 #----------------------------------------------------------------------
51 def runTest(frame
, nb
, log
):
52 win
= TestPanel(nb
, log
)
55 #----------------------------------------------------------------------
59 A checklistbox is like a Listbox, but allows items to be checked or unchecked rather
60 than relying on extended selection (e.g. shift-select) to select multiple items in
63 This class is currently implemented under Windows and GTK.
65 This demo shows the basic CheckListBox and how to use the SetString method to change
70 if __name__
== '__main__':
73 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])