Sub-classing wx.TextCompleter

147 views
Skip to first unread message

Xaviou

unread,
Apr 24, 2018, 11:26:47 AM4/24/18
to wxPython-users
Hi.

I am trying to play with auto completion.

I have created a class derived from wx.TextCompleter witch contains the following :

import wx

from ClassList import szClasses

class ClassCompleter(wx.TextCompleter):
def __init__(self):
wx.TextCompleter.__init__(self)
self._iLastReturned = wx.NOT_FOUND
self._sPrefix = ''

def Start(self, prefix):
self._sPrefix = prefix.lower()
self._iLastReturned = wx.NOT_FOUND
for item in szClasses:
if item.lower().startswith(self._sPrefix):
return True
# Nothing found
return False

def GetNext(self):
for i in range(self._iLastReturned+1, len(szClasses)):
if szClasses[i].lower().startswith(self._sPrefix):
return szClasses[i]
# No more corresponding item
return ''


Then, in the main application, I've created a simple textbox and enabled auto complete using the following line :

self._txtEntry.AutoComplete(ClassCompleter())

But this line gives an error at execution time :
TypeError: wx._core.TextCompleter cannot be instantiated or sub-classed
OnInit returned false, exiting...

Can one tell me what I've done wrong ?
I'm using wxPython 4.0.2a1 dev3717 64bits on a Windows 10 system, installed from the "snapshots builds" wheels (https://wxpython.org/Phoenix/snapshot-builds/).

Thanks in advance.

Regards
Xav'

Xaviou

unread,
Apr 24, 2018, 11:46:19 AM4/24/18
to wxPython-users
Hi again...

For people who prefer having a small test app : here it is.

The line witch causes the error has been commented : see MainFrame.py line 28

Regards
Xav'
AutoComplete.zip

Robin Dunn

unread,
Apr 24, 2018, 3:24:58 PM4/24/18
to wxPython-users
Thanks for the sample. I'll take a look when I can. It will probably need some extra tweaks for that class to convince sip that it's not an abstract class.

I've added an issue to track this, and so it won't be forgotten. https://github.com/wxWidgets/Phoenix/issues/827

--
Robin

Xaviou

unread,
Apr 25, 2018, 11:01:53 AM4/25/18
to wxPython-users
Hi.

I think there is also a problem with wx.TextCompleterSimple : I've tried the sample code provided on the doc (https://wxpython.org/Phoenix/docs/html/wx.TextCompleterSimple.html) and I obtain an error when auto completion starts :
NotImplementedError: TextCompleterSimple.Start() is abstract and must be overridden

If I add a basic "Start" method witch returns a boolean, it also requires the "GetNext" one:
NotImplementedError: TextCompleterSimple.GetNext() is abstract and must be overridden

Regards
Xav'

Scott Talbert

unread,
Apr 25, 2018, 12:05:09 PM4/25/18
to wxPython-users
Yes, looks like another bug. TextCompleterSimple should only require
GetCompletions() to be overridden.
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to wxpython-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>

Scott Talbert

unread,
Apr 27, 2018, 8:44:57 PM4/27/18
to wxPython-users
I submitted this to fix the TextCompleter issues:
https://github.com/wxWidgets/Phoenix/pull/829

Xaviou

unread,
Apr 30, 2018, 2:52:41 AM4/30/18
to wxPython-users
Hi.


On Saturday, April 28, 2018 at 2:44:57 AM UTC+2, Scott Talbert wrote:
I submitted this to fix the TextCompleter issues:
https://github.com/wxWidgets/Phoenix/pull/829

Thank you.
It works fine for TextCompleter.
But TextCompleterSimple still requires the "Start" and "GetNext" method to be overriden.

Regards
Xav'

Xaviou

unread,
Apr 30, 2018, 2:58:36 AM4/30/18
to wxPython-users
I think there is a problem with the last snapshot build filenames :
  • wheels names are like "wxPython-4.0.2a1.dev3730+6e8d62e-cp36-cp36m-win_amd64.whl"
  • sources tarball name is "wxPython-4.0.2a1.dev3730+6e8d62e0.tar.gz" (1 more char in the commit ref)
So pip don't install the wheel : it tries to install from the sources.

Regards
Xav'

Robin Dunn

unread,
Apr 30, 2018, 11:20:37 AM4/30/18
to wxPython-users
Thanks. That will be an easy fix, I'll probably be able to get it taken care of this evening.

--
Robin

Robin Dunn

unread,
Apr 30, 2018, 11:23:54 AM4/30/18
to wxPython-users
On Sunday, April 29, 2018 at 11:58:36 PM UTC-7, Xaviou wrote:
I think there is a problem with the last snapshot build filenames :
  • wheels names are like "wxPython-4.0.2a1.dev3730+6e8d62e-cp36-cp36m-win_amd64.whl"
  • sources tarball name is "wxPython-4.0.2a1.dev3730+6e8d62e0.tar.gz" (1 more char in the commit ref)
So pip don't install the wheel : it tries to install from the sources.


Xaviou

unread,
May 2, 2018, 8:10:40 AM5/2/18
to wxPython-users
Hi.

Thank you for all fixes on this point.

I also noticed that GetCompletions for the TextCompleterSimple class has changed (in a more logical way than it was before).

Regards
Xav'

Scott Talbert

unread,
May 2, 2018, 9:22:02 AM5/2/18
to wxPython-users
Good point - Robin, we should also update the example code to reflect
'res' being returned now instead of a parameter.

Scott

Robin Dunn

unread,
May 2, 2018, 2:16:30 PM5/2/18
to wxPython-users
Yep, I changed it but apparently it didn't get checked in to the PR's branch. It will be there in the next build.


--
Robin

Reply all
Reply to author
Forward
0 new messages