wx.ComboBox magically autocompletes

Hello,

I am using a Combobox and I realized a strange behaviour.
When I press the first key of a string in the choices,
the control autocompletes, but only when I refresh the
windows (either programmatically or when the window is resized).
When I don't use a sizer for the ComboBoxes, I do not have
this phenomenon.

When the input autocompletes this way, I do not receive a EVT_TEXT
or a EVT_COMBOBOX event (normally these events are generated
when the input is autocompleted for example by pressing
key-down)
I am using wx-2.8.10.1, python-2.6.4, windows vista sp2

Here is the sample code:

import wx

class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Test")
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)
        self.combo = wx.ComboBox(self, -1, style=wx.CB_DROPDOWN,
                                 choices=["one", "two", "three"])
        sizer.Add(self.combo, 1, wx.EXPAND)
        self.combo.Bind(wx.EVT_TEXT, self.OnTextChanged)
        self.combo.Bind(wx.EVT_COMBOBOX, self.OnCombobox)
        self.Fit()

    def OnTextChanged(self, event):
        print "OnTextChanged", event.String, self.combo.GetValue()
        def refresh():
            wnd = self.combo
            while wnd:
                wnd.Layout()
                wnd = wnd.GetParent()
            self.combo.Refresh()
        refresh()
        event.Skip()

    def OnCombobox(self, event):
        print "OnCombobox"
        event.Skip()

app = wx.PySimpleApp()
TestFrame().Show()
app.MainLoop()

It looks to me like this may be some built-in feature/bug of the native widget. wx isn't doing anything that I can see for auto-completion.

···

On 12/14/11 12:09 PM, ErwinP wrote:

Hello,

I am using a Combobox and I realized a strange behaviour.
When I press the first key of a string in the choices,
the control autocompletes, but only when I refresh the
windows (either programmatically or when the window is resized).
When I don't use a sizer for the ComboBoxes, I do not have
this phenomenon.

When the input autocompletes this way, I do not receive a EVT_TEXT
or a EVT_COMBOBOX event (normally these events are generated
when the input is autocompleted for example by pressing
key-down)
I am using wx-2.8.10.1, python-2.6.4, windows vista sp2

Here is the sample code:

--
Robin Dunn
Software Craftsman

What is your goal? do you need it to auto complete?

···

On Dec 14, 10:09 pm, ErwinP <hombr...@gmx.at> wrote:

Hello,

I am using a Combobox and I realized a strange behaviour.
When I press the first key of a string in the choices,
the control autocompletes, but only when I refresh the
windows (either programmatically or when the window is resized).
When I don't use a sizer for the ComboBoxes, I do not have
this phenomenon.

When the input autocompletes this way, I do not receive a EVT_TEXT
or a EVT_COMBOBOX event (normally these events are generated
when the input is autocompleted for example by pressing
key-down)
I am using wx-2.8.10.1, python-2.6.4, windows vista sp2

Here is the sample code:

import wx

class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Test")
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(sizer)
self.combo = wx.ComboBox(self, -1, style=wx.CB_DROPDOWN,
choices=["one", "two", "three"])
sizer.Add(self.combo, 1, wx.EXPAND)
self.combo.Bind(wx.EVT_TEXT, self.OnTextChanged)
self.combo.Bind(wx.EVT_COMBOBOX, self.OnCombobox)
self.Fit()

def OnTextChanged\(self, event\):
    print &quot;OnTextChanged&quot;, event\.String, self\.combo\.GetValue\(\)
    def refresh\(\):
        wnd = self\.combo
        while wnd:
            wnd\.Layout\(\)
            wnd = wnd\.GetParent\(\)
        self\.combo\.Refresh\(\)
    refresh\(\)
    event\.Skip\(\)

def OnCombobox\(self, event\):
    print &quot;OnCombobox&quot;
    event\.Skip\(\)

app = wx.PySimpleApp()
TestFrame().Show()
app.MainLoop()

Hello, I’m sorry for waking the dead guy, but having the same issue :frowning:

The problem is not only in autocomplete, but when for example “one” is selected, you can’t use backspace correctly, it autocompletes to “one” if text in input field is a prefix to any of possible selections.

Any sugestions on how to avoid this?? Because I need to programmically update combobox after user changes it, but this feature/bug messes everything up :frowning:

–JJ

···

On Saturday, December 17, 2011 10:18:26 AM UTC+2, Michael Gorelik wrote:

What is your goal? do you need it to auto complete?
On Dec 14, 10:09 pm, ErwinP hombr...@gmx.at wrote:

Hello,

I am using a Combobox and I realized a strange behaviour.
When I press the first key of a string in the choices,
the control autocompletes, but only when I refresh the
windows (either programmatically or when the window is resized).
When I don’t use a sizer for the ComboBoxes, I do not have
this phenomenon.

When the input autocompletes this way, I do not receive a EVT_TEXT
or a EVT_COMBOBOX event (normally these events are generated
when the input is autocompleted for example by pressing
key-down)
I am using wx-2.8.10.1, python-2.6.4, windows vista sp2

Here is the sample code:

import wx

class TestFrame(wx.Frame):
def init(self):
wx.Frame.init(self, None, -1, “Test”)
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(sizer)
self.combo = wx.ComboBox(self, -1, style=wx.CB_DROPDOWN,
choices=[“one”, “two”, “three”])
sizer.Add(self.combo, 1, wx.EXPAND)
self.combo.Bind(wx.EVT_TEXT, self.OnTextChanged)
self.combo.Bind(wx.EVT_COMBOBOX, self.OnCombobox)
self.Fit()

def OnTextChanged(self, event):
    print "OnTextChanged", event.String, self.combo.GetValue()
    def refresh():
        wnd = self.combo
        while wnd:
            wnd.Layout()
            wnd = wnd.GetParent()
        self.combo.Refresh()
    refresh()
    event.Skip()

def OnCombobox(self, event):
    print "OnCombobox"
    event.Skip()

app = wx.PySimpleApp()
TestFrame().Show()
app.MainLoop()

I’ve located the problem, if wnd.Layout() is replaced with wnd.Refresh() this tends to happen really really rare, but sometimes weird things do happen.