]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/CheckListBox.py
Typo
[wxWidgets.git] / wxPython / demo / CheckListBox.py
1
2 import wx
3
4 #----------------------------------------------------------------------
5
6 class TestPanel(wx.Panel):
7 def __init__(self, parent, log):
8 wx.Panel.__init__(self, parent, -1)
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
15 wx.StaticText(self, -1, "This example uses the wxCheckListBox control.", (45, 15))
16
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)
20 lb.SetSelection(0)
21 self.lb = lb
22
23 pos = lb.GetPosition().x + lb.GetSize().width + 25
24 btn = wx.Button(self, -1, "Test SetString", (pos, 50))
25 self.Bind(wx.EVT_BUTTON, self.OnTestButton, btn)
26 self.Bind(wx.EVT_RIGHT_UP, self.OnDoPopup)
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
34 def OnTestButton(self, evt):
35 self.lb.SetString(4, "FUBAR")
36
37
38 def OnDoPopup(self, evt):
39 menu = wx.Menu()
40 # Make this first item bold
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
49 item.SetFont(nf)
50 menu.AppendItem(item)
51
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"))
56
57 self.PopupMenu(menu, evt.GetPosition())
58 menu.Destroy()
59 evt.Skip()
60
61
62 #----------------------------------------------------------------------
63
64 def runTest(frame, nb, log):
65 win = TestPanel(nb, log)
66 return win
67
68 #----------------------------------------------------------------------
69
70
71 overview = """\
72 A checklistbox is like a Listbox, but allows items to be checked or unchecked rather
73 than relying on extended selection (e.g. shift-select) to select multiple items in
74 the list.
75
76 This class is currently implemented under Windows and GTK.
77
78 This demo shows the basic CheckListBox and how to use the SetString method to change
79 labels dynamically.
80 """
81
82
83 if __name__ == '__main__':
84 import sys,os
85 import run
86 run.main(['', os.path.basename(sys.argv[0])])
87