]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxListBox.py
First draft of a cygwin script to create wxMSW distributions
[wxWidgets.git] / wxPython / demo / wxListBox.py
1
2 from wxPython.wx import *
3
4 #---------------------------------------------------------------------------
5
6 class TestListBox(wxPanel):
7 def __init__(self, parent, log):
8 self.log = log
9 wxPanel.__init__(self, parent, -1)
10
11 sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
12 'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
13 'twelve', 'thirteen', 'fourteen']
14
15 wxStaticText(self, -1, "This example uses the wxListBox control.",
16 wxPoint(45, 10))
17
18 wxStaticText(self, -1, "Select one:", wxPoint(15, 50), wxSize(65, 18))
19 self.lb1 = wxListBox(self, 60, wxPoint(80, 50), wxSize(80, 120),
20 sampleList, wxLB_SINGLE)
21 EVT_LISTBOX(self, 60, self.EvtListBox)
22 EVT_LISTBOX_DCLICK(self, 60, self.EvtListBoxDClick)
23 EVT_RIGHT_UP(self.lb1, self.EvtRightButton)
24 self.lb1.SetSelection(0)
25
26
27 wxStaticText(self, -1, "Select many:", wxPoint(200, 50), wxSize(65, 18))
28 self.lb2 = wxListBox(self, 70, wxPoint(280, 50), wxSize(80, 120),
29 sampleList, wxLB_EXTENDED)
30 EVT_LISTBOX(self, 70, self.EvtMultiListBox)
31 EVT_LISTBOX_DCLICK(self, 70, self.EvtListBoxDClick)
32 self.lb2.SetSelection(0)
33
34
35 def EvtListBox(self, event):
36 self.log.WriteText('EvtListBox: %s\n' % event.GetString())
37
38 def EvtListBoxDClick(self, event):
39 self.log.WriteText('EvtListBoxDClick: %s\n' % self.lb1.GetSelection())
40 self.lb1.Delete(self.lb1.GetSelection())
41
42 def EvtMultiListBox(self, event):
43 self.log.WriteText('EvtMultiListBox: %s\n' % str(self.lb2.GetSelections()))
44
45 def EvtRightButton(self, event):
46 self.log.WriteText('EvtRightButton: %s\n' % event.GetPosition())
47
48 #---------------------------------------------------------------------------
49
50 def runTest(frame, nb, log):
51 win = TestListBox(nb, log)
52 return win
53
54 #---------------------------------------------------------------------------
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 overview = """\
70 A listbox is used to select one or more of a list of strings. The strings are displayed in a scrolling box, with the selected string(s) marked in reverse video. A listbox can be single selection (if an item is selected, the previous selection is removed) or multiple selection (clicking an item toggles the item on or off independently of other selections).
71
72 List box elements are numbered from zero.
73
74 wxListBox()
75 ---------------------
76
77 Default constructor.
78
79 wxListBox(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, int n, const wxString choices[] = NULL, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = "listBox")
80
81 Constructor, creating and showing a list box.
82
83 Parameters
84 -------------------
85
86 parent = Parent window. Must not be NULL.
87
88 id = Window identifier. A value of -1 indicates a default value.
89
90 pos = Window position.
91
92 size = Window size. If the default size (-1, -1) is specified then the window is sized appropriately.
93
94 n = Number of strings with which to initialise the control.
95
96 choices = An array of strings with which to initialise the control.
97
98 style = Window style. See wxListBox.
99
100 validator = Window validator.
101
102 name = Window name.
103 """