]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/CheckListBox.py
Fixed preprocessor warnings
[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
95bfd958
RD
17 lb = wx.CheckListBox(self, -1, (80, 50), (80, 120), sampleList)
18 self.Bind(wx.EVT_LISTBOX, self.EvtListBox, lb)
19 self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, 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)
8fa876ca 26 self.Bind(wx.EVT_RIGHT_UP, self.OnDoPopup)
cf694132
RD
27
28 def EvtListBox(self, event):
29 self.log.WriteText('EvtListBox: %s\n' % event.GetString())
30
31 def EvtListBoxDClick(self, event):
32 self.log.WriteText('EvtListBoxDClick:\n')
33
be43cc44
RD
34 def OnTestButton(self, evt):
35 self.lb.SetString(4, "FUBAR")
36
37
25832b3f 38 def OnDoPopup(self, evt):
8fa876ca 39 menu = wx.Menu()
25832b3f 40 # Make this first item bold
8fa876ca
RD
41 item = wx.MenuItem(menu, wx.NewId(), "If supported, this is bold")
42 df = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
43
44 nf = wx.Font(
45 df.GetPointSize(), df.GetFamily(), df.GetStyle(),
46 wx.BOLD, False, df.GetFaceName()
47 )
48
25832b3f
RD
49 item.SetFont(nf)
50 menu.AppendItem(item)
51
8fa876ca
RD
52 menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &1"))
53 menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &2"))
54 menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &3"))
55 menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &4"))
25832b3f
RD
56
57 self.PopupMenu(menu, evt.GetPosition())
58 menu.Destroy()
59 evt.Skip()
cf694132
RD
60
61
62#----------------------------------------------------------------------
63
64def runTest(frame, nb, log):
65 win = TestPanel(nb, log)
66 return win
67
68#----------------------------------------------------------------------
69
70
1fded56b 71overview = """\
8fa876ca
RD
72A checklistbox is like a Listbox, but allows items to be checked or unchecked rather
73than relying on extended selection (e.g. shift-select) to select multiple items in
74the list.
cf694132 75
8fa876ca 76This class is currently implemented under Windows and GTK.
cf694132 77
8fa876ca
RD
78This demo shows the basic CheckListBox and how to use the SetString method to change
79labels dynamically.
80"""
cf694132
RD
81
82
1fded56b
RD
83if __name__ == '__main__':
84 import sys,os
85 import run
86 run.main(['', os.path.basename(sys.argv[0])])
cf694132 87