Hi All -
I'm running into a problem with wx.ComboBox that I hope someone may have a
workaround for.
I'm driving the rest of a screen based on what gets selected in the combobox
by the user, but I'm noticing that EVT_COMBOBOX doesn't get triggered under
some circumstances.
If I use the mouse to actually click on an entry in the expanded combobox, I
trigger an event and everything works just fine. If, however, I expand the
combobox with the mouse but then use the keyboard to select different
entries (either by hitting the arrow keys or by typing characters that match
the strings) and then hit the enter key, the combobox shows the value I've
selected, but no event is triggered. I can then select something else in
the combobox (just with the mouse this time), and I get both events (in the
correct order). One additional note is that once I get into the
delayed-event state, if I open the combobox with the mouse, the first time I
press a key also triggers that previous event.
This can be easily tested with the demo code. In my case I've changed the
style to wxCB_READONLY and have added an extra print in the EvtComboBox
method.
Thanks for any suggestions!
-David Seelig
import wx
···
#---------------------------------------------------------------------------
class TestComboBox(wx.Panel):
def OnSetFocus(self, evt):
print "OnSetFocus"
evt.Skip()
def OnKillFocus(self, evt):
print "OnKillFocus"
evt.Skip()
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
#'this is a long item that needs a scrollbar...',
'six', 'seven', 'eight']
wx.StaticText(self, -1, "This example uses the wx.ComboBox
control.", (8, 10))
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_READONLY #|wxTE_PROCESS_ENTER
)
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)
# Once the combobox is set up, we can append some more data to it.
cb.Append("foo", "This is some client data for this item")
# This combobox is created with no values initially.
cb = wx.ComboBox(
self, 501, "default value", (90, 80), (95, -1), [],
wx.CB_READONLY)
# Here we dynamically add our values to the second combobox.
for item in sampleList:
cb.Append(item, item.upper())
self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, cb)
self.Bind(wx.EVT_COMBOBOX, self.EvtText, cb)
# When the user selects something, we go here.
def EvtComboBox(self, evt):
cb = evt.GetEventObject()
data = cb.GetClientData(cb.GetSelection())
self.log.WriteText('EvtComboBox: evt.GetString:%s' %
(evt.GetString()))
self.log.WriteText('EvtComboBox: SelectedSomething: %s\n' %
(cb.GetSelection()))
# Capture events every time a user hits a key in the text entry field.
def EvtText(self, evt):
self.log.WriteText('EvtText: %s\n' % evt.GetString())
# Capture events when the user types something into the control then
# hits ENTER.
def EvtTextEnter(self, evt):
self.log.WriteText('EvtTextEnter: %s' % evt.GetString())
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestComboBox(nb, log)
return win
#---------------------------------------------------------------------------
overview = """\
"""
#---------------------------------------------------------------------------
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])