Sub-classing wx.TextCompleter

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’

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 (6.38 KB)

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. Subclassing wx.TextCompleter · Issue #827 · wxWidgets/Phoenix · GitHub

···

On Tuesday, April 24, 2018 at 8:46:19 AM UTC-7, Xaviou wrote:

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

Robin

Hi.

I think there is also a problem with wx.TextCompleterSimple : I’ve tried the sample code provided on the doc (wx.TextCompleterSimple — wxPython Phoenix 4.2.3a1 documentation) 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’

···

On Tuesday, April 24, 2018 at 9:24:58 PM UTC+2, Robin Dunn wrote:

On Tuesday, April 24, 2018 at 8:46:19 AM UTC-7, Xaviou wrote:

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

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

Yes, looks like another bug. TextCompleterSimple should only require GetCompletions() to be overridden.

···

On Wed, 25 Apr 2018, Xaviou wrote:

Hi.
I think there is also a problem with wx.TextCompleterSimple : I've tried the
sample code provided on the doc
(wx.TextCompleterSimple — wxPython Phoenix 4.2.3a1 documentation) 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'

On Tuesday, April 24, 2018 at 9:24:58 PM UTC+2, Robin Dunn wrote:
      On Tuesday, April 24, 2018 at 8:46:19 AM UTC-7, Xaviou wrote:
            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

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. Subclassing wx.TextCompleter · Issue #827 · wxWidgets/Phoenix · GitHub

--
Robin

--
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-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I submitted this to fix the TextCompleter issues:

···

On Wed, 25 Apr 2018, Scott Talbert wrote:

Yes, looks like another bug. TextCompleterSimple should only require GetCompletions() to be overridden.

On Wed, 25 Apr 2018, Xaviou wrote:

Hi.
I think there is also a problem with wx.TextCompleterSimple : I've tried the
sample code provided on the doc
(wx.TextCompleterSimple — wxPython Phoenix 4.2.3a1 documentation) 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'

On Tuesday, April 24, 2018 at 9:24:58 PM UTC+2, Robin Dunn wrote:
      On Tuesday, April 24, 2018 at 8:46:19 AM UTC-7, Xaviou wrote:
            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

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. Subclassing wx.TextCompleter · Issue #827 · wxWidgets/Phoenix · GitHub

--
Robin

--
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-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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’

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’

···

On Monday, April 30, 2018 at 8:52:41 AM UTC+2, Xaviou wrote:

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’

Thanks. That will be an easy fix, I’ll probably be able to get it taken care of this evening.

···

On Sunday, April 29, 2018 at 11:52:41 PM UTC-7, Xaviou wrote:

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.

Robin

Thanks. Check snapshot revision names · Issue #837 · wxWidgets/Phoenix · GitHub

–Robin

···

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.

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’

Good point - Robin, we should also update the example code to reflect 'res' being returned now instead of a parameter.

Scott

···

On Wed, 2 May 2018, Xaviou wrote:

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).

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.

···

On Wednesday, May 2, 2018 at 6:22:02 AM UTC-7, Scott Talbert wrote:

On Wed, 2 May 2018, Xaviou wrote:

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).

Good point - Robin, we should also update the example code to reflect
‘res’ being returned now instead of a parameter.

Robin