+#---------------------------------------------------------------------------
+
+class wxFindPrefixListBox(wxListBox):
+ def __init__(self, parent, id, pos=wxDefaultPosition, size=wxDefaultSize,
+ choices=[], style=0, validator=wxDefaultValidator):
+ wxListBox.__init__(self, parent, id, pos, size, choices, style, validator)
+ self.typedText = ''
+ self.log = parent.log
+ EVT_KEY_DOWN(self, self.OnKey)
+
+
+ def FindPrefix(self, prefix):
+ self.log.WriteText('Looking for prefix: %s\n' % prefix)
+ if prefix:
+ prefix = prefix.lower()
+ length = len(prefix)
+ for x in range(self.Number()):
+ text = self.GetString(x)
+ text = text.lower()
+ if text[:length] == prefix:
+ self.log.WriteText('Prefix %s is found.\n' % prefix)
+ return x
+ self.log.WriteText('Prefix %s is not found.\n' % prefix)
+ return -1
+
+
+ def OnKey(self, evt):
+ key = evt.GetKeyCode()
+ if key >= 32 and key <= 127:
+ self.typedText = self.typedText + chr(key)
+ item = self.FindPrefix(self.typedText)
+ if item != -1:
+ self.SetSelection(item)
+
+ elif key == WXK_BACK: # backspace removes one character and backs up
+ self.typedText = self.typedText[:-1]
+ if not self.typedText:
+ self.SetSelection(0)
+ else:
+ item = self.FindPrefix(self.typedText)
+ if item != -1:
+ self.SetSelection(item)
+
+ else:
+ self.typedText = ''
+ evt.Skip()
+
+ def OnKeyDown(self, evt):
+ pass
+
+