1 from wxPython
.wx
import *
3 #---------------------------------------------------------------------------
5 class TestComboBox(wxPanel
):
6 def OnSetFocus(self
, evt
):
9 def OnKillFocus(self
, evt
):
13 def __init__(self
, parent
, log
):
15 wxPanel
.__init
__(self
, parent
, -1)
17 sampleList
= ['zero', 'one', 'two', 'three', 'four', 'five',
18 'six', 'seven', 'eight']
20 wxStaticText(self
, -1, "This example uses the wxComboBox control.",
23 wxStaticText(self
, -1, "Select one:", wxPoint(15, 50), wxSize(75, 18))
24 cb
= wxComboBox(self
, 500, "default value", wxPoint(90, 50), wxSize(95, -1),
25 sampleList
, wxCB_DROPDOWN
)#|wxTE_PROCESS_ENTER)
26 EVT_COMBOBOX(self
, 500, self
.EvtComboBox
)
27 EVT_TEXT(self
, 500, self
.EvtText
)
28 EVT_TEXT_ENTER(self
, 500, self
.EvtTextEnter
)
29 EVT_SET_FOCUS(cb
, self
.OnSetFocus
)
30 EVT_KILL_FOCUS(cb
, self
.OnKillFocus
)
32 cb
.Append("foo", "This is some client data for this item")
34 cb
= wxComboBox(self
, 501, "default value", wxPoint(90, 80), wxSize(95, -1),
36 for item
in sampleList
:
37 cb
.Append(item
, item
.upper())
38 EVT_COMBOBOX(self
, 501, self
.EvtComboBox
)
39 EVT_TEXT(self
, 501, self
.EvtText
)
42 def EvtComboBox(self
, evt
):
43 cb
= evt
.GetEventObject()
44 data
= cb
.GetClientData(cb
.GetSelection())
45 self
.log
.WriteText('EvtComboBox: %s\nClientData: %s\n' % (evt
.GetString(), data
))
47 def EvtText(self
, evt
):
48 self
.log
.WriteText('EvtText: %s\n' % evt
.GetString())
50 def EvtTextEnter(self
, evt
):
51 self
.log
.WriteText('EvtTextEnter: does this work?')
53 #---------------------------------------------------------------------------
55 def runTest(frame
, nb
, log
):
56 win
= TestComboBox(nb
, log
)
59 #---------------------------------------------------------------------------
68 A combobox is like a combination of an edit control and a listbox. It can be displayed as static list with editable or read-only text field; or a drop-down list with text field; or a drop-down list without a text field.
74 if __name__
== '__main__':
77 run
.main(['', os
.path
.basename(sys
.argv
[0])])