]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/wxCheckListBox.py
reSWIGged
[wxWidgets.git] / wxPython / demo / wxCheckListBox.py
... / ...
CommitLineData
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#
6
7import wx
8
9#----------------------------------------------------------------------
10
11class TestPanel(wx.Panel):
12 def __init__(self, parent, log):
13 wx.Panel.__init__(self, parent, -1)
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
20 wx.StaticText(self, -1, "This example uses the wxCheckListBox control.", (45, 15))
21
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)
25 lb.SetSelection(0)
26 self.lb = lb
27
28 pos = lb.GetPosition().x + lb.GetSize().width + 25
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)
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
39 def OnTestButton(self, evt):
40 self.lb.SetString(4, "FUBAR")
41
42
43 def OnDoPopup(self, evt):
44 menu = wx.Menu()
45 # Make this first item bold
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
54 item.SetFont(nf)
55 menu.AppendItem(item)
56
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"))
61
62 self.PopupMenu(menu, evt.GetPosition())
63 menu.Destroy()
64 evt.Skip()
65
66
67#----------------------------------------------------------------------
68
69def runTest(frame, nb, log):
70 win = TestPanel(nb, log)
71 return win
72
73#----------------------------------------------------------------------
74
75
76overview = """\
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.
80
81This class is currently implemented under Windows and GTK.
82
83This demo shows the basic CheckListBox and how to use the SetString method to change
84labels dynamically.
85"""
86
87
88if __name__ == '__main__':
89 import sys,os
90 import run
91 run.main(['', os.path.basename(sys.argv[0])])
92