]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxCheckListBox.py
reSWIGged
[wxWidgets.git] / wxPython / demo / wxCheckListBox.py
CommitLineData
8fa876ca
RD
1# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4# o Why is there a popup menu in this demo?
5#
cf694132 6
8fa876ca 7import wx
cf694132
RD
8
9#----------------------------------------------------------------------
10
8fa876ca 11class TestPanel(wx.Panel):
cf694132 12 def __init__(self, parent, log):
8fa876ca 13 wx.Panel.__init__(self, parent, -1)
cf694132
RD
14 self.log = log
15
16 sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
17 'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
18 'twelve', 'thirteen', 'fourteen']
19
8fa876ca 20 wx.StaticText(self, -1, "This example uses the wxCheckListBox control.", (45, 15))
cf694132 21
8fa876ca
RD
22 lb = wx.CheckListBox(self, 60, (80, 50), (80, 120), sampleList)
23 self.Bind(wx.EVT_LISTBOX, self.EvtListBox, id=60)
24 self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, id=60)
cf694132 25 lb.SetSelection(0)
be43cc44
RD
26 self.lb = lb
27
1e4a197e 28 pos = lb.GetPosition().x + lb.GetSize().width + 25
8fa876ca
RD
29 btn = wx.Button(self, -1, "Test SetString", (pos, 50))
30 self.Bind(wx.EVT_BUTTON, self.OnTestButton, id=btn.GetId())
31 self.Bind(wx.EVT_RIGHT_UP, self.OnDoPopup)
cf694132
RD
32
33 def EvtListBox(self, event):
34 self.log.WriteText('EvtListBox: %s\n' % event.GetString())
35
36 def EvtListBoxDClick(self, event):
37 self.log.WriteText('EvtListBoxDClick:\n')
38
be43cc44
RD
39 def OnTestButton(self, evt):
40 self.lb.SetString(4, "FUBAR")
41
42
25832b3f 43 def OnDoPopup(self, evt):
8fa876ca 44 menu = wx.Menu()
25832b3f 45 # Make this first item bold
8fa876ca
RD
46 item = wx.MenuItem(menu, wx.NewId(), "If supported, this is bold")
47 df = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
48
49 nf = wx.Font(
50 df.GetPointSize(), df.GetFamily(), df.GetStyle(),
51 wx.BOLD, False, df.GetFaceName()
52 )
53
25832b3f
RD
54 item.SetFont(nf)
55 menu.AppendItem(item)
56
8fa876ca
RD
57 menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &1"))
58 menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &2"))
59 menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &3"))
60 menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &4"))
25832b3f
RD
61
62 self.PopupMenu(menu, evt.GetPosition())
63 menu.Destroy()
64 evt.Skip()
cf694132
RD
65
66
67#----------------------------------------------------------------------
68
69def runTest(frame, nb, log):
70 win = TestPanel(nb, log)
71 return win
72
73#----------------------------------------------------------------------
74
75
1fded56b 76overview = """\
8fa876ca
RD
77A checklistbox is like a Listbox, but allows items to be checked or unchecked rather
78than relying on extended selection (e.g. shift-select) to select multiple items in
79the list.
cf694132 80
8fa876ca 81This class is currently implemented under Windows and GTK.
cf694132 82
8fa876ca
RD
83This demo shows the basic CheckListBox and how to use the SetString method to change
84labels dynamically.
85"""
cf694132
RD
86
87
1fded56b
RD
88if __name__ == '__main__':
89 import sys,os
90 import run
91 run.main(['', os.path.basename(sys.argv[0])])
cf694132 92