Hi all
(Sorry for my english, im french)
I've an amazing problem with a wx.textCtrl (!)
I've taken this code on wiki.wxPython ("combobox that suggets
options") and adapts it on a textCtrl. Easy...
But wx.TextCtrl.SetSelection(...) works on Windows but NOT ON LINUX
(Ubuntu). I use last version of wxPython.
You can try yourself this little code on Linux to reproduce the bug (i
hope) :
#!/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()
I really hope you'll be able to help me !!
Thx for your answer.