]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxListBox.py
2 from wxPython
. wx
import *
6 #---------------------------------------------------------------------------
8 class wxFindPrefixListBox ( wxListBox
):
9 def __init__ ( self
, parent
, id , pos
= wxDefaultPosition
, size
= wxDefaultSize
,
10 choices
=[], style
= 0 , validator
= wxDefaultValidator
):
11 wxListBox
.__ init
__ ( self
, parent
, id , pos
, size
, choices
, style
, validator
)
13 EVT_KEY_UP ( self
, self
. OnKey
)
16 def FindPrefix ( self
, prefix
):
18 prefix
= string
. lower ( prefix
)
20 for x
in range ( self
. Number ()):
21 text
= self
. GetString ( x
)
22 text
= string
. lower ( text
)
23 if text
[: length
] == prefix
:
29 key
= evt
. GetKeyCode ()
30 if key
>= 32 and key
<= 127 :
31 self
. typedText
= self
. typedText
+ chr ( key
)
32 item
= self
. FindPrefix ( self
. typedText
)
34 self
. SetSelection ( item
)
36 elif key
== WXK_BACK
: # backspace removes one character and backs up
37 self
. typedText
= self
. typedText
[:- 1 ]
38 if not self
. typedText
:
41 item
= self
. FindPrefix ( self
. typedText
)
43 self
. SetSelection ( item
)
49 #---------------------------------------------------------------------------
51 class TestListBox ( wxPanel
):
52 def __init__ ( self
, parent
, log
):
54 wxPanel
.__ init
__ ( self
, parent
, - 1 )
56 sampleList
= [ 'zero' , 'one' , 'two' , 'three' , 'four' , 'five' ,
57 'six' , 'seven' , 'eight' , 'nine' , 'ten' , 'eleven' ,
58 'twelve' , 'thirteen' , 'fourteen' ]
60 wxStaticText ( self
, - 1 , "This example uses the wxListBox control." ,
63 wxStaticText ( self
, - 1 , "Select one:" , wxPoint ( 15 , 50 ), wxSize ( 65 , 18 ))
64 self
. lb1
= wxListBox ( self
, 60 , wxPoint ( 80 , 50 ), wxSize ( 80 , 120 ),
65 sampleList
, wxLB_SINGLE
)
66 EVT_LISTBOX ( self
, 60 , self
. EvtListBox
)
67 EVT_LISTBOX_DCLICK ( self
, 60 , self
. EvtListBoxDClick
)
68 EVT_RIGHT_UP ( self
. lb1
, self
. EvtRightButton
)
69 self
. lb1
. SetSelection ( 3 )
72 wxStaticText ( self
, - 1 , "Select many:" , wxPoint ( 200 , 50 ), wxSize ( 65 , 18 ))
73 self
. lb2
= wxListBox ( self
, 70 , wxPoint ( 280 , 50 ), wxSize ( 80 , 120 ),
74 sampleList
, wxLB_EXTENDED
)
75 EVT_LISTBOX ( self
, 70 , self
. EvtMultiListBox
)
76 EVT_LISTBOX_DCLICK ( self
, 70 , self
. EvtListBoxDClick
)
77 self
. lb2
. SetSelection ( 0 )
80 sampleList
= sampleList
+ [ 'test a' , 'test aa' , 'test aab' ,
81 'test ab' , 'test abc' , 'test abcc' ,
84 wxStaticText ( self
, - 1 , "Find Prefix:" , wxPoint ( 15 , 250 ))
85 fp
= wxFindPrefixListBox ( self
, - 1 , wxPoint ( 80 , 250 ), wxSize ( 80 , 120 ),
86 sampleList
, wxLB_SINGLE
)
90 def EvtListBox ( self
, event
):
91 self
. log
. WriteText ( 'EvtListBox: %s \n ' % event
. GetString ())
93 def EvtListBoxDClick ( self
, event
):
94 self
. log
. WriteText ( 'EvtListBoxDClick: %s \n ' % self
. lb1
. GetSelection ())
95 self
. lb1
. Delete ( self
. lb1
. GetSelection ())
97 def EvtMultiListBox ( self
, event
):
98 self
. log
. WriteText ( 'EvtMultiListBox: %s \n ' % str ( self
. lb2
. GetSelections ()))
100 def EvtRightButton ( self
, event
):
101 self
. log
. WriteText ( 'EvtRightButton: %s \n ' % event
. GetPosition ())
103 #---------------------------------------------------------------------------
105 def runTest ( frame
, nb
, log
):
106 win
= TestListBox ( nb
, log
)
109 #---------------------------------------------------------------------------
125 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).