Reputation: 1368
I'm using wxPython (Phoenix). I wrote a small app with a custom autocompleter, according to these guidelines, but it fails with the following error:
Traceback (most recent call last):
File "try2.py", line 33, in <module>
frame = TextFrame()
File "try2.py", line 26, in __init__
basicText.AutoComplete(MyTextCompleter)
TypeError: TextEntry.AutoComplete(): arguments did not match any overloaded call:
overload 1: argument 1 has unexpected type 'sip.wrappertype'
overload 2: argument 1 has unexpected type 'sip.wrappertype'
This is the code:
import wx
class MyTextCompleter(wx.TextCompleterSimple):
def __init__(self):
wx.TextCompleterSimple.__init__(self)
def GetCompletions(self, prefix, res):
if prefix == "a":
res.append("This order is")
res.append("very important")
elif firstWord == "b":
res.append("z - It's not in")
res.append("a - lexicographic order")
else:
res.append("bye")
class TextFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Text Entry Example', size=(300, 100))
panel = wx.Panel(self, -1)
basicLabel = wx.StaticText(panel, -1, "Basic Control:")
basicText = wx.TextCtrl(panel, -1, "I've entered some text!", size=(175, -1))
basicText.SetInsertionPoint(0)
basicText.AutoComplete(MyTextCompleter)
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
sizer.AddMany([basicLabel, basicText])
panel.SetSizer(sizer)
app = wx.PySimpleApp()
frame = TextFrame()
frame.Show()
app.MainLoop()
When commenting out the basicText.AutoComplete(MyTextCompleter)
it runs successfully (without the autocompletion)
Upvotes: 2
Views: 1573
Reputation: 168
You need to pass an instance of MyTextCompleter, not the class itself, to wx.TextCtrl.AutoComplete(). Change this:
basicText.AutoComplete(MyTextCompleter)
to
basicText.AutoComplete(MyTextCompleter())
Upvotes: 2
Reputation: 3177
I should have warned you more thouroghly: wxPython Phoenix is the future of wxPython (because, in contrast to classic it supports Python 3, too). That said, this does not mean everything is nice and shiny. My personal advice is to keep on going with classic (or in other words: what works now in classic, will most probably also work in Phoenix). In Phoenix, you will stumble into bugs like this more often.
Luckily, in this special case, there has already been something else done:
<wx.TextCtrl>.AutoComplete(…)
does accept a list of strings. This already works in 2.9.0/classic. See documentation for wx.TextEntry
/AutoComplete.
Upvotes: 2