wxpython evt text

Solutions on MaxInterview for wxpython evt text by the best coders in the world

showing results for - "wxpython evt text"
Simon
23 Jul 2017
1   1 import wx
2   2  
3   3 class PromptingComboBox(wx.ComboBox) :
4   4     def __init__(self, parent, value, choices=[], style=0, **par):
5   5         wx.ComboBox.__init__(self, parent, wx.ID_ANY, value, style=style|wx.CB_DROPDOWN, choices=choices, **par)
6   6         self.choices = choices
7   7         self.Bind(wx.EVT_TEXT, self.EvtText)
8   8         self.Bind(wx.EVT_CHAR, self.EvtChar)
9   9         self.Bind(wx.EVT_COMBOBOX, self.EvtCombobox) 
10  10         self.ignoreEvtText = False
11  11         
12  12     def EvtCombobox(self, event):
13  13         self.ignoreEvtText = True
14  14         event.Skip()
15  15         
16  16     def EvtChar(self, event):
17  17         if event.GetKeyCode() == 8:
18  18             self.ignoreEvtText = True
19  19         event.Skip()
20  20         
21  21     def EvtText(self, event):
22  22         if self.ignoreEvtText:
23  23             self.ignoreEvtText = False
24  24             return
25  25         currentText = event.GetString()
26  26         found = False
27  27         for choice in self.choices :
28  28             if choice.startswith(currentText):
29  29                 self.ignoreEvtText = True
30  30                 self.SetValue(choice)
31  31                 self.SetInsertionPoint(len(currentText))
32  32                 self.SetMark(len(currentText), len(choice))
33  33                 found = True
34  34                 break
35  35         if not found:
36  36             event.Skip()
37  37 
38  38 class TrialPanel(wx.Panel):
39  39     def __init__(self, parent):
40  40         wx.Panel.__init__(self, parent, wx.ID_ANY)
41  41         
42  42         choices = ['grandmother', 'grandfather', 'cousin', 'aunt', 'uncle', 'grandson', 'granddaughter']
43  43         for relative in ['mother', 'father', 'sister', 'brother', 'daughter', 'son']:
44  44             choices.extend(self.derivedRelatives(relative))
45  45 
46  46         cb = PromptingComboBox(self, "default value", choices, style=wx.CB_SORT) 
47  47 
48  48     def derivedRelatives(self, relative):
49  49         return [relative, 'step' + relative, relative + '-in-law']
50  50 
51  51 
52  52 if __name__ == '__main__':
53  53     app = wx.App()
54  54     frame = wx.Frame (None, -1, 'Demo PromptingComboBox Control', size=(400, 50))
55  55     TrialPanel(frame)
56  56     frame.Show()
57  57     app.MainLoop()
58
similar questions
queries leading to this page
wxpython evt text