| 1 | from wxPython.wx import * |
| 2 | |
| 3 | #--------------------------------------------------------------------------- |
| 4 | |
| 5 | class TestComboBox(wxPanel): |
| 6 | def OnSetFocus(self, evt): |
| 7 | print "OnSetFocus" |
| 8 | evt.Skip() |
| 9 | def OnKillFocus(self, evt): |
| 10 | print "OnKillFocus" |
| 11 | evt.Skip() |
| 12 | |
| 13 | def __init__(self, parent, log): |
| 14 | self.log = log |
| 15 | wxPanel.__init__(self, parent, -1) |
| 16 | |
| 17 | sampleList = ['zero', 'one', 'two', 'three', 'four', 'five', |
| 18 | ##'this is a long item that needs a scrollbar...', |
| 19 | 'six', 'seven', 'eight'] |
| 20 | |
| 21 | wxStaticText(self, -1, "This example uses the wxComboBox control.", |
| 22 | wxPoint(8, 10)) |
| 23 | |
| 24 | wxStaticText(self, -1, "Select one:", wxPoint(15, 50), wxSize(75, 18)) |
| 25 | cb = wxComboBox(self, 500, "default value", wxPoint(90, 50), wxSize(95, -1), |
| 26 | sampleList, wxCB_DROPDOWN)#|wxTE_PROCESS_ENTER) |
| 27 | ##import win32api, win32con |
| 28 | ##win32api.SendMessage(cb.GetHandle(), |
| 29 | ## win32con.CB_SETHORIZONTALEXTENT, |
| 30 | ## 200, 0) |
| 31 | |
| 32 | EVT_COMBOBOX(self, 500, self.EvtComboBox) |
| 33 | EVT_TEXT(self, 500, self.EvtText) |
| 34 | EVT_TEXT_ENTER(self, 500, self.EvtTextEnter) |
| 35 | EVT_SET_FOCUS(cb, self.OnSetFocus) |
| 36 | EVT_KILL_FOCUS(cb, self.OnKillFocus) |
| 37 | |
| 38 | cb.Append("foo", "This is some client data for this item") |
| 39 | |
| 40 | cb = wxComboBox(self, 501, "default value", wxPoint(90, 80), wxSize(95, -1), |
| 41 | [], wxCB_SIMPLE) |
| 42 | for item in sampleList: |
| 43 | cb.Append(item, item.upper()) |
| 44 | EVT_COMBOBOX(self, 501, self.EvtComboBox) |
| 45 | EVT_TEXT(self, 501, self.EvtText) |
| 46 | |
| 47 | |
| 48 | def EvtComboBox(self, evt): |
| 49 | cb = evt.GetEventObject() |
| 50 | data = cb.GetClientData(cb.GetSelection()) |
| 51 | self.log.WriteText('EvtComboBox: %s\nClientData: %s\n' % (evt.GetString(), data)) |
| 52 | |
| 53 | def EvtText(self, evt): |
| 54 | self.log.WriteText('EvtText: %s\n' % evt.GetString()) |
| 55 | |
| 56 | def EvtTextEnter(self, evt): |
| 57 | self.log.WriteText('EvtTextEnter: does this work?') |
| 58 | |
| 59 | #--------------------------------------------------------------------------- |
| 60 | |
| 61 | def runTest(frame, nb, log): |
| 62 | win = TestComboBox(nb, log) |
| 63 | return win |
| 64 | |
| 65 | #--------------------------------------------------------------------------- |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | overview = """\ |
| 74 | 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. |
| 75 | |
| 76 | """ |
| 77 | |
| 78 | |
| 79 | |
| 80 | if __name__ == '__main__': |
| 81 | import sys,os |
| 82 | import run |
| 83 | run.main(['', os.path.basename(sys.argv[0])]) |
| 84 | |