2003-12-09 01:23:28 +00:00
|
|
|
|
|
|
|
import wx
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
class TestComboBox(wx.Panel):
|
2001-09-17 21:47:20 +00:00
|
|
|
def OnSetFocus(self, evt):
|
|
|
|
print "OnSetFocus"
|
|
|
|
evt.Skip()
|
2003-12-09 01:23:28 +00:00
|
|
|
|
2001-09-17 21:47:20 +00:00
|
|
|
def OnKillFocus(self, evt):
|
|
|
|
print "OnKillFocus"
|
|
|
|
evt.Skip()
|
|
|
|
|
1999-04-30 03:29:54 +00:00
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
|
2003-12-09 01:23:28 +00:00
|
|
|
#'this is a long item that needs a scrollbar...',
|
1999-04-30 03:29:54 +00:00
|
|
|
'six', 'seven', 'eight']
|
|
|
|
|
2004-01-13 03:17:17 +00:00
|
|
|
wx.StaticText(self, -1, "This example uses the wx.ComboBox control.", (8, 10))
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.StaticText(self, -1, "Select one:", (15, 50), (75, 18))
|
|
|
|
|
|
|
|
# This combobox is created with a preset list of values.
|
|
|
|
cb = wx.ComboBox(
|
|
|
|
self, 500, "default value", (90, 50),
|
|
|
|
(95, -1), sampleList, wx.CB_DROPDOWN #|wxTE_PROCESS_ENTER
|
|
|
|
)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, cb)
|
|
|
|
self.Bind(wx.EVT_TEXT, self.EvtText, cb)
|
|
|
|
self.Bind(wx.EVT_TEXT_ENTER, self.EvtTextEnter, cb)
|
|
|
|
cb.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
|
|
|
|
cb.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
|
2001-09-17 21:47:20 +00:00
|
|
|
|
2004-01-31 01:19:44 +00:00
|
|
|
# Once the combobox is set up, we can append some more data to it.
|
2002-01-07 19:15:47 +00:00
|
|
|
cb.Append("foo", "This is some client data for this item")
|
2001-09-17 21:47:20 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# This combobox is created with no values initially.
|
|
|
|
cb = wx.ComboBox(
|
2004-03-10 04:04:52 +00:00
|
|
|
self, 501, "default value", (90, 80), (95, -1), [], wx.CB_DROPDOWN)
|
2003-12-09 01:23:28 +00:00
|
|
|
|
|
|
|
# Here we dynamically add our values to the second combobox.
|
2002-04-03 18:15:21 +00:00
|
|
|
for item in sampleList:
|
2003-03-25 06:35:27 +00:00
|
|
|
cb.Append(item, item.upper())
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, cb)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2004-01-31 01:19:44 +00:00
|
|
|
# When the user selects something, we go here.
|
2002-01-07 19:15:47 +00:00
|
|
|
def EvtComboBox(self, evt):
|
|
|
|
cb = evt.GetEventObject()
|
2006-02-24 01:13:55 +00:00
|
|
|
data = cb.GetClientData(evt.GetSelection())
|
2002-01-07 19:15:47 +00:00
|
|
|
self.log.WriteText('EvtComboBox: %s\nClientData: %s\n' % (evt.GetString(), data))
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
if evt.GetString() == 'one':
|
|
|
|
self.log.WriteText("You follow directions well!\n\n")
|
|
|
|
|
|
|
|
# Capture events every time a user hits a key in the text entry field.
|
2002-01-07 19:15:47 +00:00
|
|
|
def EvtText(self, evt):
|
|
|
|
self.log.WriteText('EvtText: %s\n' % evt.GetString())
|
2006-04-04 23:29:14 +00:00
|
|
|
evt.Skip()
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# Capture events when the user types something into the control then
|
|
|
|
# hits ENTER.
|
2002-04-01 20:27:19 +00:00
|
|
|
def EvtTextEnter(self, evt):
|
2003-12-09 01:23:28 +00:00
|
|
|
self.log.WriteText('EvtTextEnter: %s' % evt.GetString())
|
2006-04-04 23:29:14 +00:00
|
|
|
evt.Skip()
|
2002-04-01 20:27:19 +00:00
|
|
|
|
1999-04-30 03:29:54 +00:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestComboBox(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
overview = """\
|
|
|
|
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.
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
This example shows both a preset ComboBox and one that is dynamically created
|
|
|
|
(that is, it is initially empty but then we 'grow' it out of program-supplied
|
|
|
|
data). The former is common for read-only controls.
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
This example also shows the two form factors for the ComboBox. The first is more
|
|
|
|
common, and resembles a Choice control. The latter, although less common, shows
|
|
|
|
how all the values in the ComboBox can be visible, yet the functionality is the
|
|
|
|
same for both.
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
Finally, this demo shows how event handling can differ. The first ComboBox is set
|
|
|
|
up to handle EVT_TEXT_ENTER events, in which text is typed in and then ENTER is
|
|
|
|
hit by the user. This allows the user to enter a line of text which can then be
|
|
|
|
processed by the program. EVT_TEXT can also be processed, but in that case the
|
|
|
|
event is generated every time that the user hits a key in the ComboBox entry field.
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2002-09-07 23:17:14 +00:00
|
|
|
"""
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2004-01-13 03:17:17 +00:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2002-09-07 23:17:14 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-05 00:06:33 +00:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
1999-04-30 03:29:54 +00:00
|
|
|
|