]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxListBox.py
2 from wxPython
. wx
import *
4 #---------------------------------------------------------------------------
6 class TestListBox ( wxPanel
):
7 def __init__ ( self
, parent
, log
):
9 wxPanel
.__ init
__ ( self
, parent
, - 1 )
11 sampleList
= [ 'zero' , 'one' , 'two' , 'three' , 'four' , 'five' ,
12 'six' , 'seven' , 'eight' , 'nine' , 'ten' , 'eleven' ,
13 'twelve' , 'thirteen' , 'fourteen' ]
15 wxStaticText ( self
, - 1 , "This example uses the wxListBox control." ,
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 )
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 )
35 def EvtListBox ( self
, event
):
36 self
. log
. WriteText ( 'EvtListBox: %s \n ' % event
. GetString ())
38 def EvtListBoxDClick ( self
, event
):
39 self
. log
. WriteText ( 'EvtListBoxDClick: %s \n ' % self
. lb1
. GetSelection ())
41 def EvtMultiListBox ( self
, event
):
42 self
. log
. WriteText ( 'EvtMultiListBox: %s \n ' % str ( self
. lb2
. GetSelections ()))
44 def EvtRightButton ( self
, event
):
45 self
. log
. WriteText ( 'EvtRightButton: %s \n ' % event
. GetPosition ())
47 #---------------------------------------------------------------------------
49 def runTest ( frame
, nb
, log
):
50 win
= TestListBox ( nb
, log
)
53 #---------------------------------------------------------------------------
69 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 List box elements are numbered from zero.
78 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 Constructor, creating and showing a list box.
85 parent = Parent window. Must not be NULL.
87 id = Window identifier. A value of -1 indicates a default value.
89 pos = Window position.
91 size = Window size. If the default size (-1, -1) is specified then the window is sized appropriately.
93 n = Number of strings with which to initialise the control.
95 choices = An array of strings with which to initialise the control.
97 style = Window style. See wxListBox.
99 validator = Window validator.