1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
import wx
class PromptingTextCtrl(wx.TextCtrl) :
def __init__(self, parent, value, choices):
wx.TextCtrl.__init__(self, parent, wx.ID_ANY, value, size=(400, -1))
self.choices = choices
self.Bind(wx.EVT_TEXT, self.EvtText)
self.Bind(wx.EVT_CHAR, self.EvtChar)
self.ignoreEvtText = False
def EvtChar(self, event):
if event.GetKeyCode() == 8:
self.ignoreEvtText = True
event.Skip()
def EvtText(self, event):
if self.ignoreEvtText:
self.ignoreEvtText = False
return
currentText = event.GetString()
found = False
for choice in self.choices :
if choice.startswith(currentText):
self.ignoreEvtText = True
self.SetValue(choice)
self.SetInsertionPoint(len(currentText))
# HERE HIGHLIGHT SELECTION DOESNT APPEAR !!!!!!!
self.SetSelection(len(currentText), len(choice))
found = True
break
if not found:
event.Skip()
class TrialPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, wx.ID_ANY)
choices = ['grandmother', 'grandfather', 'cousin', 'aunt', 'uncle', 'grandson', 'granddaughter']
for relative in ['mother', 'father', 'sister', 'brother', 'daughter', 'son']:
choices.extend(self.derivedRelatives(relative))
cb = PromptingTextCtrl(self, "default value", choices)
def derivedRelatives(self, relative):
return [relative, 'step' + relative, relative + '-in-law']
if __name__ == '__main__':
app = wx.App()
frame = wx.Frame (None, -1, 'Demo PromptingTextCtrl Control', size=(500, 50))
TrialPanel(frame)
frame.Show()
app.MainLoop() |
Partager